* @license PHP License * @package WB * @subpackage unittest */ require_once dirname(__FILE__) . '/../rule.php'; /** * Unit Test * * * * @version 0.1.0 * @package WB * @subpackage unittest */ class TestCasePat_Forms_Rule_vfsisdir extends TestCasePat_Forms_Rule { protected $formDef = array( 'dir' => array( 'type' => 'String', 'attributes' => array( 'title' => 'folder', 'required' => 'no', 'minlenght' => 1, 'maxlength' => 250 ) ) ); /** * constructor * * - start objects * - source SQL * */ public function __construct() { parent::__construct(); WBClass::load('WBUnitTest_SQLUte'); WBUnitTest_SQLUte::source(__FILE__, 'construct'); } /** * destruct * * Remove testing tables */ public function __destruct() { // WBUnitTest_SQLUte::source( __FILE__, 'destruct' ); parent::__destruct(); } public function testLoad() { WBClass::load('patForms'); $rule = patForms::createRule('VFSIsDir'); /** @var $rule WBPAT_Forms_Rule */ $this->assertIsA($rule, 'WBPAT_Forms_Rule'); $this->assertIsA($rule, 'patForms_Rule'); $this->assertIsA($rule, 'patForms_Rule_VFSIsDir'); $config = array( 'user' => '42', ); $rule->setConfig($config); $this->getForm(); } public function testRootFolder() { return $this->checkFolder('NULL'); } public function testValidFolder() { //$this->checkFolder(1); //$this->checkFolder(3); //$this->checkFolder(32); } public function testInvalidFolder() { $this->checkFolder(1231233, false); } protected function checkFolder($dir, $valid = true) { $values = array( 'dir' => $dir ); $_POST = $values; $form = $this->getForm(); $form->setSubmitted(true); $isValid = $form->validateForm(true); if ($valid) { // if form is valid, there sould be no errors $this->assertTrue($isValid); $errors = $form->getValidationErrors(); $this->assertFalse($errors); return; } // shoulw not be valid $this->assertFalse($isValid); $errors = $form->getValidationErrors(); $this->assertTrue(is_array($errors)); // count number of faild form elements $this->assertEqual(count($errors), 1); // count errors of specific form element $this->assertTrue(isset($errors['dir'])); $this->assertEqual(count($errors['dir']), 1); } /** * create form object * * Create form itself and add rule * * @return patForms $form */ protected function getForm() { $params = array(); $params['elements'] = $this->formDef; $form = WBClass::create('patForms', $params); $this->assertIsA($form, 'patForms'); $rule = patForms::createRule('VFSIsDir'); /** @var $rule WBPAT_Forms_Rule */ $this->assertIsA($rule, 'patForms_Rule_VFSIsDir'); $config = array( 'user' => '42', ); $rule->setConfig($config); $el = $form->getElementByname('dir'); $el->addRule($rule); return $form; } } ?>