* @license PHP License * @package FIT * @subpackage fixture */ Testing_FIT_Loader::loadClass( 'Testing_FIT_Fixture' , 'Testing_FIT_Fixture_Column' ); /** * FIT Test * * Form_Rule_Email * * @version 0.1.0 * @package WB * @subpackage FIT */ class Form_Rule_Email extends Testing_FIT_Fixture_Column { /** * column fixture data: email * @var string */ public $email; /** * validateion errors * @var array */ protected $errors; /** * current row index * @var int */ protected $pos = 0; protected $elements = array(); protected $rules = array(); protected $skel = array( 'name' => 'email_%s', 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'title' => 'title', 'label' => 'Email %s', 'description' => 'Email %s', 'maxlength' => 1000, ) ); public function __construct() { // create a patForms object to initialize required classes $param = array(); $param['elements'] = array( 'test' => $this->skel ); $form = WBClass::create('patForms', $param); // chuck form object in the bin, we do it all manually // call the constuctor form base class to create an instance of type filter parent::__construct(); } /** * delete the users */ public function __destruct() { } /** * Validate * * read the inputdata and validate the data * * @return boolean true on succes, false otherwise */ public function validate() { $def = $this->skel; $def['name'] = sprintf($def['name'], $this->pos); foreach ($def['attributes'] as &$a) { $a = sprintf($a, $this->pos); } $this->elements[$this->pos] = patForms::createElement($def['name'], $def['type'], $def['attributes']); /** @var $this->elements[$this->pos] patForms_Element */ $this->rules[$this->pos] = patForms::createRule('Email'); /** @var $this->rules[$this->pos] patForms_Element */ $this->elements[$this->pos]->addRule($this->rules[$this->pos]); $this->elements[$this->pos]->setValue($this->email); $valid = $this->elements[$this->pos]->validate(); $this->errors = $this->elements[$this->pos]->getValidationErrors(); ++$this->pos; return $valid; } /** * Fetch actual error message * * Compare real error message with expected error message * * @return string */ public function errorMessage() { if (!isset($this->errors[0])) { return ''; } return $this->errors[0]['message']; } }