public function testSaveFailedWithValidationByModelDefinitionAndTriggeredCustomEvents() { $post = MockPostForValidates::create(); $events = array('customEvent', 'anotherCustomEvent'); $result = $post->save(null, compact('events')); $this->assertFalse($result); $result = $post->errors(); $this->assertNotEmpty($result); $expected = array('title' => array('please enter a title'), 'email' => array('email is empty', 'email is not valid', 'email is not in 1st list', 'email is not in 2nd list')); $result = $post->errors(); $this->assertEqual($expected, $result); }
public function testCustomValidationCriteria() { $validates = array('title' => 'A custom message here for empty titles.', 'email' => array(array('notEmpty', 'message' => 'email is empty.'))); $post = MockPostForValidates::create(array('title' => 'custom validation', 'email' => 'asdf')); $result = $post->validates(array('rules' => $validates)); $this->assertTrue($result === true); $this->assertIdentical(array(), $post->errors()); }
public function testValidatesEmailIsValid() { $post = MockPostForValidates::create(array('title' => 'new post', 'email' => '*****@*****.**')); $result = $post->validates(); $this->assertTrue($result === true); $result = $post->errors(); $this->assertTrue(empty($result)); }
public function testSaveWithValidationAndWhitelist() { $post = MockPostForValidates::create(); $whitelist = array('title'); $post->title = 'title'; $result = $post->save(null, compact('whitelist')); $this->assertTrue($result); $post->title = ''; $result = $post->save(null, compact('whitelist')); $this->assertFalse($result); $result = $post->errors(); $this->assertNotEmpty($result); $expected = array('title' => array('please enter a title')); $result = $post->errors(); $this->assertEqual($expected, $result); }