当前位置: 首页>>代码示例>>PHP>>正文


PHP Book::addReview方法代码示例

本文整理汇总了PHP中Book::addReview方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::addReview方法的具体用法?PHP Book::addReview怎么用?PHP Book::addReview使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Book的用法示例。


在下文中一共展示了Book::addReview方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testScenarioUsingQuery


//.........这里部分代码省略.........
     $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
     // ---------------
     require_once 'tools/helpers/bookstore/validator/ISBNValidator.php';
     $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();
     $auth2->setLastName("Blah");
     //passes
     $auth2->setEmail("some@body.com");
     //passes
     $auth2->setAge(50);
     //passes
     $bk2->setAuthor($auth2);
     $rev2 = new Review();
     $rev2->setReviewedBy("Me!");
     // passes
     $rev2->setStatus("new");
     // passes
     $bk2->addReview($rev2);
     $ret3 = $bk2->validate();
     $this->assertTrue($ret3, 'complex validation can pass');
     // Testing doCount() functionality
     // -------------------------------
     // old way
     $c = new Criteria();
     $records = BookPeer::doSelect($c);
     $count = BookPeer::doCount($c);
     $this->assertEquals($count, count($records), 'correct number of results');
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:BookstoreTest.php

示例2: testCountRefFk

 public function testCountRefFk()
 {
     $book = new Book();
     $book->setTitle("Test Book");
     $book->setISBN("TT-EE-SS-TT");
     $num = 5;
     for ($i = 2; $i < $num + 2; $i++) {
         $r = new Review();
         $r->setReviewedBy('Hans ' . $num);
         $dt = new DateTime("now");
         $dt->modify("-" . $i . " weeks");
         $r->setReviewDate($dt);
         $r->setRecommended($i % 2 == 0);
         $book->addReview($r);
     }
     $this->assertEquals($num, $book->countReviews(), "Expected countReviews to return {$num}");
     $this->assertEquals($num, count($book->getReviews()), "Expected getReviews to return {$num} reviews");
     $book->save();
     BookPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $book = BookPeer::retrieveByPK($book->getId());
     $this->assertEquals($num, $book->countReviews(), "Expected countReviews() to return {$num} (after save)");
     $this->assertEquals($num, count($book->getReviews()), "Expected getReviews() to return {$num} (after save)");
     // Now set different criteria and expect different results
     $c = new Criteria();
     $c->add(ReviewPeer::RECOMMENDED, false);
     $this->assertEquals(floor($num / 2), $book->countReviews($c), "Expected " . floor($num / 2) . " results from countReviews(recomm=false)");
     // Change Criteria, run again -- expect different.
     $c = new Criteria();
     $c->add(ReviewPeer::RECOMMENDED, true);
     $this->assertEquals(ceil($num / 2), count($book->getReviews($c)), "Expected " . ceil($num / 2) . " results from getReviews(recomm=true)");
     $this->assertEquals($num, $book->countReviews(), "Expected countReviews to return {$num} with new empty Criteria");
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:33,代码来源:GeneratedObjectTest.php

示例3: Author

    $bk2->setTitle("12345678901");
    // passes
    $auth2 = new Author();
    $auth2->setLastName("Blah");
    //passes
    $auth2->setEmail("some@body.com");
    //passes
    $auth2->setAge(50);
    //passes
    $bk2->setAuthor($auth2);
    $rev2 = new Review();
    $rev2->setReviewedBy("Me!");
    // passes
    $rev2->setStatus("new");
    // passes
    $bk2->addReview($rev2);
    $ret3 = $bk2->validate();
    print "Making sure complex validation can pass: ";
    print boolTest($ret3 === true);
} catch (Exception $e) {
    die("Error doing validation tests: " . $e->__toString());
}
// Test doCount()
//
try {
    print "\nTesting doCount() functionality\n";
    print "-------------------------------\n\n";
    $c = new Criteria();
    $records = BookPeer::doSelect($c);
    $count = BookPeer::doCount($c);
    print "Making sure correct number of results: ";
开发者ID:yasirgit,项目名称:afids,代码行数:31,代码来源:bookstore-test.php

示例4: testDoValidate_ComplexSpecifiedCols

 /**
  * Test recursive validaton with specified columns.
  */
 public function testDoValidate_ComplexSpecifiedCols()
 {
     $book = new Book();
     $book->setTitle("12345");
     // min length is 10
     $author = new Author();
     $author->setFirstName("Hans");
     // last name required, valid email format, age > 0
     $review = new Review();
     $review->setReviewDate("08/09/2001");
     // reviewed_by column required, invalid status (new, reviewed, archived)
     $book->setAuthor($author);
     $book->addReview($review);
     $cols = array(AuthorPeer::LAST_NAME, ReviewPeer::REVIEWED_BY);
     $res = $book->validate($cols);
     $this->assertFalse($res, "Expected validation to fail.");
     $failures = $book->getValidationFailures();
     /* Make sure 3 validation messages were returned; NOT 6, because the others were NULL */
     $this->assertEquals(2, count($failures), "");
     /* Make sure correct columns failed */
     $expectedCols = array(AuthorPeer::LAST_NAME, ReviewPeer::REVIEWED_BY);
     $returnedCols = array_keys($failures);
     /* implode for readability */
     $this->assertEquals(implode(',', $expectedCols), implode(',', $returnedCols));
 }
开发者ID:nhemsley,项目名称:propel,代码行数:28,代码来源:ValidatorTest.php

示例5: testClearRefFk

 /**
  * Test the clearing of related object collection.
  * @link       http://www.propelorm.org/ticket/529
  */
 public function testClearRefFk()
 {
     BookstoreDataPopulator::populate();
     $book = new Book();
     $book->setISBN("Foo-bar-baz");
     $book->setTitle("The book title");
     // No save ...
     $r = new Review();
     $r->setReviewedBy('Me');
     $r->setReviewDate(new DateTime("now"));
     $book->addReview($r);
     // No save (yet) ...
     $this->assertEquals(1, count($book->getReviews()));
     $book->clearReviews();
     $this->assertEquals(0, count($book->getReviews()));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:20,代码来源:GeneratedObjectRelTest.php

示例6: testSpeed


//.........这里部分代码省略.........
     $r = ReviewPeer::doSelectOne(new Criteria());
     $r_id = $r->getId();
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewPeer::retrieveByPk($r_id);
     // Testing the DATE/TIME columns
     // -----------------------------
     // that's the control timestamp.
     $control = strtotime('2004-02-29 00:00:00');
     // should be two in the db
     $r = ReviewPeer::doSelectOne(new Criteria());
     $r_id = $r->getId();
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewPeer::retrieveByPk($r_id);
     // Testing the column validators
     // -----------------------------
     $bk1 = new Book();
     $bk1->setTitle("12345");
     // min length is 10
     $ret = $bk1->validate();
     // Unique validator
     $bk2 = new Book();
     $bk2->setTitle("Don Juan");
     $ret = $bk2->validate();
     // 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();
     $bk2 = new Book();
     $bk2->setTitle("12345678901");
     // passes
     $auth2 = new Author();
     $auth2->setLastName("Blah");
     //passes
     $auth2->setEmail("some@body.com");
     //passes
     $auth2->setAge(50);
     //passes
     $bk2->setAuthor($auth2);
     $rev2 = new Review();
     $rev2->setReviewedBy("Me!");
     // passes
     $rev2->setStatus("new");
     // passes
     $bk2->addReview($rev2);
     $ret3 = $bk2->validate();
     // Testing doCount() functionality
     // -------------------------------
     $c = new Criteria();
     $count = BookPeer::doCount($c);
     // Testing many-to-many relationships
     // ----------------------------------
     // init book club list 1 with 2 books
     $blc1 = new BookClubList();
     $blc1->setGroupLeader("Crazyleggs");
     $blc1->setTheme("Happiness");
     $brel1 = new BookListRel();
     $brel1->setBook($phoenix);
     $brel2 = new BookListRel();
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:speed.php


注:本文中的Book::addReview方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。