* @license PHP License * @package WB * @subpackage unittest */ /** * Unit Test * * * * @version 0.1.1 * @package WB * @subpackage unittest */ class TestCasePatFormsElementDate extends UnitTestCase { /** * keep error reporting level */ protected $oldErrorReportingLevel; protected $formDef = array( 'datelegacy' => array( 'type' => 'Date', 'attributes' => array( ) ) ); /** * 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() { $form = $this->mkForm(); $el = $form->getElementByName('datelegacy'); /** @var $el patForms_Element */ $this->assertIsA($el, 'patForms_Element'); $this->assertIsA($el, 'patForms_Element_Date'); $this->assertFalse($el->validate('anything'), 'Element should not be valid'); $errors = $el->getValidationErrors(); $this->assertEqual(count($errors), 1, 'There should be 1 error'); } /** * create form object * * create and configure form with elements * * @return patForms */ protected function mkForm() { $params = array(); $params['elements'] = $this->formDef; $form = WBClass::create('patForms', $params); $this->assertIsA($form, 'patForms'); return $form; } }