Exemplo n.º 1
0
 public function testUniqueValidatorAlwaysPassIfNull()
 {
     $book = new Book();
     $book->setTitle("The return of Sherlock Holmes");
     $book->save();
     $book1 = new Book();
     $book1->setTitle('Dracula');
     $this->assertTrue($book1->validate());
     $book->delete();
 }
 public function testComplexValidationMultipleFailures()
 {
     //Array of expected failures. key: property failed, value: Class in wich the property has failed
     $failedProperties = array('first_name' => 'Propel\\Tests\\Bookstore\\Behavior\\ValidateAuthor', 'website' => 'Propel\\Tests\\Bookstore\\Behavior\\ValidatePublisher', 'title' => 'Propel\\Tests\\Bookstore\\Behavior\\ValidateBook', 'email' => 'Propel\\Tests\\Bookstore\\Behavior\\ValidateReader', 'last_name' => 'Propel\\Tests\\Bookstore\\Behavior\\ValidateReader');
     $author = new ValidateAuthor();
     $author->setId(1);
     $author->setFirstName(null);
     //failed
     $author->setLastName('Friesen');
     $author->setEmail('*****@*****.**');
     $author->setBirthday('1954-10-16');
     $publisher = new ValidatePublisher();
     $publisher->setId(5);
     $publisher->setName('Huel Ltd');
     $publisher->setWebsite('huel.com');
     //failed
     $book = new ValidateBook();
     $book->setId(1);
     $book->setValidateAuthor($author);
     $book->setValidatePublisher($publisher);
     $book->setTitle(null);
     //failed
     $book->setPrice(12, 90);
     $reader1 = new ValidateReader();
     $reader1->setId(1);
     $reader1->setFirstName('Sigurd');
     $reader1->setLastName('Dare');
     $reader1->setEmail('sig.dare@');
     //failed
     $reader1->setBirthday('1974-11-19');
     $book->addValidateReader($reader1);
     $reader2 = new ValidateReader();
     $reader2->setId(2);
     $reader2->setFirstName('Hans');
     $reader2->setLastName(null);
     //failed
     $reader2->setEmail('*****@*****.**');
     $reader2->setBirthday('1974-11-19');
     $book->addValidateReader($reader2);
     $res = $book->validate();
     $this->assertFalse($res, 'This validation expected to fail');
     $failures = $book->getValidationFailures();
     $this->assertInstanceOf('Symfony\\Component\\Validator\\ConstraintViolationList', $failures);
     $this->assertEquals(5, count($failures), 'Five constraint violation objects expected.');
     foreach ($failures as $failure) {
         $this->assertInstanceOf('Symfony\\Component\\Validator\\ConstraintViolation', $failure);
         $failObject = new \ReflectionObject($failure->getRoot());
         $this->assertTrue(in_array($failure->getPropertyPath(), array_keys($failedProperties)));
         $this->assertEquals($failedProperties[$failure->getPropertyPath()], $failObject->getName());
     }
 }