/**
  * tests that passing custom validation methods work
  *
  * @return void
  */
 public function testCustomMethods()
 {
     $def = array('rule' => 'myTestRule');
     $data = array('fieldName' => 'some data');
     $methods = array('mytestrule' => array($this, 'myTestRule'));
     $Rule = new CakeValidationRule($def);
     $Rule->process('fieldName', $data, $methods);
     $this->assertFalse($Rule->isValid());
     $methods = array('mytestrule' => array($this, 'myTestRule2'));
     $Rule->process('fieldName', $data, $methods);
     $this->assertTrue($Rule->isValid());
     $methods = array('mytestrule' => array($this, 'myTestRule3'));
     $Rule->process('fieldName', $data, $methods);
     $this->assertFalse($Rule->isValid());
 }
コード例 #2
0
 /**
  * Make sure errors are triggered when validation is missing.
  *
  * @expectedException PHPUnit_Framework_Error_Warning
  * @expectedExceptionMessage Could not find validation handler totallyMissing for fieldName
  * @return void
  */
 public function testCustomMethodMissingError()
 {
     $def = array('rule' => array('totallyMissing'));
     $data = array('fieldName' => 'some data');
     $methods = array('mytestrule' => array($this, 'myTestRule'));
     $Rule = new CakeValidationRule($def);
     $Rule->process('fieldName', $data, $methods);
 }