/** * @param $request A Request object * @return bool True if successful, false otherwise */ public function isValid($request = null) { if ($this->isSubmitted($request)) { parent::isValid($request); } else { $this->error = true; } return !$this->error; }
function testModelCheckRules() { $model = new A_Model(); $datasource = new A_Collection(); $datasource->set('foo', 'barBAR'); $datasource->set('bar', 'baz'); $rule = new A_Rule_Regexp('/^[a-z]*$/', '', 'not all lowercase letters. '); // add rule to check both fields $model->addRule($rule, array('foo', 'bar')); # $model->excludeRules(array('foo', 'bar')); $this->assertFalse($model->isValid($datasource)); // only check bar $model->excludeRules(array('foo')); $this->assertTrue($model->isValid($datasource)); // only check foo $model->excludeRules(array()); $model->includeRules(array('foo')); $this->assertFalse($model->isValid($datasource)); #dump($model, 'Model: ', 1); #echo '<pre>' . print_r($model->getErrorMsg(), 1) . '</pre>'; #echo '<pre>' . print_r($model->isValid($datasource), 1) . '</pre>'; }