예제 #1
0
 /**
  * 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()));
 }
예제 #2
0
 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();
     BookTableMap::clearInstancePool();
     ReviewTableMap::clearInstancePool();
     $book = BookQuery::create()->findPk($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(ReviewTableMap::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(ReviewTableMap::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");
 }