예제 #1
0
파일: ModelTest.php 프로젝트: rapzo/lithium
 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);
 }
예제 #2
0
 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());
 }
예제 #3
0
 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));
 }
예제 #4
0
 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);
 }