本文整理汇总了PHP中Propel\Tests\Bookstore\Book::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::validate方法的具体用法?PHP Book::validate怎么用?PHP Book::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Tests\Bookstore\Book
的用法示例。
在下文中一共展示了Book::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testScenarioUsingQuery
//.........这里部分代码省略.........
$r_id = $r->getId();
$r->setReviewDate($control);
$r->save();
$r2 = ReviewQuery::create()->findPk($r_id);
$this->assertEquals(new DateTime('2004-02-29 00:00:00'), $r2->getReviewDate(null), 'ability to fetch DateTime');
$this->assertEquals($control, $r2->getReviewDate('U'), 'ability to fetch native unix timestamp');
$this->assertEquals('2-29-2004', $r2->getReviewDate('n-j-Y'), 'ability to use date() formatter');
// Handle BLOB/CLOB Columns
// ------------------------
$blob_path = __DIR__ . '/../../Fixtures/etc/lob/tin_drum.gif';
$blob2_path = __DIR__ . '/../../Fixtures/etc/lob/propel.gif';
$clob_path = __DIR__ . '/../../Fixtures/etc/lob/tin_drum.txt';
$m1 = new Media();
$m1->setBook($phoenix);
$m1->setCoverImage(file_get_contents($blob_path));
$m1->setExcerpt(file_get_contents($clob_path));
$m1->save();
$m1_id = $m1->getId();
$m1_lookup = MediaQuery::create()->findPk($m1_id);
$this->assertNotNull($m1_lookup, 'Can find just-created media item');
$this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m1_lookup->getCoverImage())), 'BLOB was correctly updated');
$this->assertEquals(file_get_contents($clob_path), (string) $m1_lookup->getExcerpt(), 'CLOB was correctly updated');
// now update the BLOB column and save it & check the results
$m1_lookup->setCoverImage(file_get_contents($blob2_path));
$m1_lookup->save();
$m2_lookup = MediaQuery::create()->findPk($m1_id);
$this->assertNotNull($m2_lookup, 'Can find just-created media item');
$this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2_lookup->getCoverImage())), 'BLOB was correctly overwritten');
// Test Validators
// ---------------
$bk1 = new Book();
$bk1->setTitle("12345");
// min length is 10
$ret = $bk1->validate();
$this->assertFalse($ret, 'validation failed');
$failures = $bk1->getValidationFailures();
$this->assertEquals(1, count($failures), '1 validation message was returned');
$el = array_shift($failures);
$this->assertContains("must be more than", $el->getMessage(), 'Expected validation message was returned');
$bk2 = new Book();
$bk2->setTitle("Don Juan");
$ret = $bk2->validate();
$this->assertFalse($ret, 'validation failed');
$failures = $bk2->getValidationFailures();
$this->assertEquals(1, count($failures), '1 validation message was returned');
$el = array_shift($failures);
$this->assertContains("Book title already in database.", $el->getMessage(), 'Expected validation message was returned');
//Now trying some more complex validation.
$auth1 = new Author();
$auth1->setFirstName("Hans");
// last name required; will fail
$bk1->setAuthor($auth1);
$rev1 = new Review();
$rev1->setReviewDate("08/09/2001");
// will fail: reviewed_by column required
$bk1->addReview($rev1);
$ret2 = $bk1->validate();
$this->assertFalse($ret2, 'validation failed');
$failures2 = $bk1->getValidationFailures();
$this->assertEquals(3, count($failures2), '3 validation messages were returned');
$expectedKeys = array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY);
$this->assertEquals($expectedKeys, array_keys($failures2), 'correct columns failed');
$bk2 = new Book();
$bk2->setTitle("12345678901");
// passes
$auth2 = new Author();
示例2: testDoValidate_CustomValidator
public function testDoValidate_CustomValidator()
{
$book = new Book();
$book->setTitle("testDoValidate_CustomValidator");
// (valid)
$book->setISBN("Foo.Bar.Baz");
// (invalid)
$res = $book->validate();
$this->assertFalse($res, "Expected validation to fail.");
$failures = $book->getValidationFailures();
$this->assertEquals(1, count($failures), "Expected 1 column to fail validation.");
$this->assertEquals(array(BookPeer::ISBN), array_keys($failures), "Expected EMAIL to fail validation.");
$validator = $failures[BookPeer::ISBN]->getValidator();
$this->assertInstanceOf('Propel\\Tests\\Helpers\\Bookstore\\Validator\\ISBNValidator', $validator, "Expected validator that failed to be ISBNValidator");
}