* @license PHP License * @package WB * @subpackage unittest */ /** * Unit Test * * * * @version 0.1.1 * @package WB * @subpackage unittest */ class TestCasePatFormsElementVfsFile extends UnitTestCase { /** * keep error reporting level */ protected $oldErrorReportingLevel; /** * set up error reporting level */ public function __construct() { $this->req = WBClass::create('WBRequest'); $this->oldErrorReportingLevel = error_reporting(E_ALL); } /** * reset error reporting level */ public function __destruct() { $this->req->import(array('save' => null)); error_reporting($this->oldErrorReportingLevel); } /** * load class and start */ public function testInit() { $formDef = array(); $formDef['file01'] = array( 'type' => 'Vfsfile', 'attributes' => array( 'user' => 1 ) ); $formDef['file02'] = array( 'type' => 'Vfsfile', 'attributes' => array( 'user' => 1, 'required' => 'no' ) ); $params = array(); $params['elements'] = $formDef; $form = WBClass::create('patForms', $params); $this->assertIsA($form, 'patForms'); $el = $form->getElementByName('file01'); /** @var $el patForms_Element */ $this->assertIsA($el, 'patForms_Element'); $this->assertIsA($el, 'patForms_Element_Vfsfile'); $this->assertFalse($el->validate('anything'), 'Element should not be valid'); $errors = $el->getValidationErrors(); $this->assertEqual(count($errors), 1, 'There should be 1 error'); $el = $form->getElementByName('file02'); /** @var $el patForms_Element */ $this->assertIsA($el, 'patForms_Element'); $this->assertIsA($el, 'patForms_Element_Vfsfile'); $this->assertTrue($el->validate('anything'), 'Element should be valid'); $errors = $el->getValidationErrors(); $this->assertEqual(count($errors), 0, 'There should be 0 errors'); // validate form $values = array( 'save' => 'save me', 'name' => 'Joe Doe', 'age' => '18' ); $this->req->import($values); } } ?>