Esempio n. 1
0
 public function testBasic()
 {
     $simpleData = array('login' => '   login with space   ');
     $dp = DataProcessor::createInstance();
     $dp->addProcessRule('login', 'trim');
     $dp->process($simpleData);
     $this->assertEquals('login with space', $dp->getData('login'), 'trim process loaded and worked');
     $dp->addValidationRule('login', 'email');
     $dp->process($simpleData);
     $this->assertArrayHasKey('login', $dp->getErrors(), 'Has validation error on email');
     $data = array('login' => '  a@viniychuk.com ', 'name' => '  Alexandr');
     $dp->process($data);
     $this->assertTrue($dp->isValid(), 'Valid email');
     $dp->clearProcessRules();
     $dp->clearValidationRules();
     $allRules = array('name' => array(array('email'), array('trim')));
     $result = DataProcessor::createInstance($allRules)->process(array('name' => 'data  '));
     $this->assertNotEmpty($result->getErrors(), 'Errors on grouped rules');
     $this->assertEquals('data', $result->getData('name'), 'Processing on grouped rules');
     $dp = new DataProcessor();
     $dp->addValidationRule('name', 'mandatory');
     $this->assertNotEmpty($dp->process(array('login' => 'asdf'))->getErrors(), 'Mandatory rule');
 }
Esempio n. 2
0
 public function addValidationRule($columnName, $ruleName, $params = array())
 {
     $this->_dataProcessor->addValidationRule($columnName, $ruleName, $params);
     return $this;
 }