* @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_vfsisfile extends TestCasePat_Forms_Rule { protected $formDef = array( 'file' => array( 'type' => 'String', 'attributes' => array( 'title' => 'file', '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('VFSIsFile'); /** @var $rule WBPAT_Forms_Rule */ $this->assertIsA($rule, 'WBPAT_Forms_Rule'); $this->assertIsA($rule, 'patForms_Rule'); $this->assertIsA($rule, 'patForms_Rule_VFSIsFile'); $config = array( 'user' => '42', ); $rule->setConfig($config); $this->getForm(); } public function testFileValid() { $this->checkFile('ml1'); $this->checkFile('fg2'); $this->checkFile('Ze3'); $this->checkFile('k74'); $this->checkFile('Lc5'); $this->checkFile('Dm6'); $this->checkFile('ys9'); } public function testFileInvalid() { $this->checkFile('xx123', false); $this->checkFile('uI10', false); $this->checkFile('0V11', false); $this->checkFile('Sn12', false); $this->checkFile('mx13', false); $this->checkFile('Ww14', false); $this->checkFile('Fs15', false); } protected function checkFile($obscure, $valid = true) { $form = $this->getForm(); $values = array( 'file' => $obscure ); $_POST = $values; $form->setSubmitted(true); $isValid = $form->validateForm(true); if ($valid !== $isValid) { $this->assertTrue(false); return; } $this->assertTrue(true); } /** * 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('VFSIsFile'); /** @var $rule WBPAT_Forms_Rule */ $this->assertIsA($rule, 'patForms_Rule_VFSIsFile'); $config = array( 'user' => '42', ); $rule->setConfig($config); $el = $form->getElementByname('file'); $el->addRule($rule); return $form; } } ?>