/**
  * Tests validation parameter order in custom validation methods
  *
  * @return void
  */
 public function testAllowSimulatedFields()
 {
     $TestModel = new ValidationTest1();
     $TestModel->create(array('title' => 'foo', 'bar' => 'baz'));
     $expected = array('ValidationTest1' => array('title' => 'foo', 'bar' => 'baz'));
     $this->assertEquals($expected, $TestModel->data);
 }
 /**
  * Tests validation parameter order in custom validation methods
  *
  * @return void
  */
 public function testInvalidAssociation()
 {
     $TestModel = new ValidationTest1();
     $this->assertNull($TestModel->getAssociated('Foo'));
 }
 /**
  * Test placeholder replacement when validation message is an array
  *
  * @return void
  */
 public function testValidationMessageAsArray()
 {
     $TestModel = new ValidationTest1();
     $TestModel->validate = array('title' => array('minLength' => array('rule' => array('minLength', 6), 'required' => true, 'message' => 'Minimum length allowed is %d chars', 'last' => false), 'between' => array('rule' => array('between', 5, 15), 'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6))));
     $TestModel->create();
     $TestModel->invalidFields();
     $expected = array('title' => array('Minimum length allowed is 6 chars'));
     $this->assertEquals($TestModel->validationErrors, $expected);
     $TestModel->create(array('title' => 'foo'));
     $TestModel->invalidFields();
     $expected = array('title' => array('Minimum length allowed is 6 chars', 'You may enter up to 14 chars (minimum is 6 chars)'));
     $this->assertEquals($TestModel->validationErrors, $expected);
 }
 /**
  * Test validation message translation
  *
  * @return void
  */
 public function testValidationMessageTranslation()
 {
     $lang = Configure::read('Config.language');
     Configure::write('Config.language', 'en');
     App::build(array('Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS)), App::RESET);
     $TestModel = new ValidationTest1();
     $TestModel->validationDomain = 'validation_messages';
     $TestModel->validate = array('title' => array(array('rule' => array('customValidationMethod', 'arg1'), 'required' => true, 'message' => 'Validation failed: %s')));
     $TestModel->create();
     $expected = array('title' => array('Translated validation failed: Translated arg1'));
     $TestModel->invalidFields();
     $this->assertEquals($expected, $TestModel->validationErrors);
     $TestModel->validationDomain = 'default';
     Configure::write('Config.language', $lang);
     App::build();
 }
Example #5
0
 /**
  * Test that missing validation methods does not trigger errors in production mode.
  *
  * @return void
  */
 public function testMissingValidationErrorNoTriggering()
 {
     Configure::write('debug', 0);
     $TestModel = new ValidationTest1();
     $TestModel->create(array('title' => 'foo'));
     $TestModel->validate = array('title' => array('rule' => array('thisOneBringsThePain'), 'required' => true));
     $TestModel->invalidFields(array('fieldList' => array('title')));
     $this->assertEquals($TestModel->validationErrors, array());
 }