| 110 | | $obj = MediaPeer::retrieveByPK($mediaId); |
|---|
| 111 | | $this->assertNull($obj, "Expect NULL when retrieving on no matching Media."); |
|---|
| | 111 | $obj = MediaPeer::retrieveByPK($mediaId); |
|---|
| | 112 | $this->assertNull($obj, "Expect NULL when retrieving on no matching Media."); |
|---|
| | 113 | |
|---|
| | 114 | } |
|---|
| | 115 | |
|---|
| | 116 | /** |
|---|
| | 117 | * Test that cascading deletes are happening correctly for composite pk. |
|---|
| | 118 | * @link http://propel.phpdb.org/trac/ticket/544 |
|---|
| | 119 | */ |
|---|
| | 120 | public function testDoDelete_Cascade_CompositePK() |
|---|
| | 121 | { |
|---|
| | 122 | |
|---|
| | 123 | $origBceCount = BookstoreContestEntryPeer::doCount(new Criteria()); |
|---|
| | 124 | |
|---|
| | 125 | $cust1 = new Customer(); |
|---|
| | 126 | $cust1->setName("Cust1"); |
|---|
| | 127 | $cust1->save(); |
|---|
| | 128 | |
|---|
| | 129 | $cust2 = new Customer(); |
|---|
| | 130 | $cust2->setName("Cust2"); |
|---|
| | 131 | $cust2->save(); |
|---|
| | 132 | |
|---|
| | 133 | $c1 = new Contest(); |
|---|
| | 134 | $c1->setName("Contest1"); |
|---|
| | 135 | $c1->save(); |
|---|
| | 136 | |
|---|
| | 137 | $c2 = new Contest(); |
|---|
| | 138 | $c2->setName("Contest2"); |
|---|
| | 139 | $c2->save(); |
|---|
| | 140 | |
|---|
| | 141 | $store1 = new Bookstore(); |
|---|
| | 142 | $store1->setStoreName("Store1"); |
|---|
| | 143 | $store1->save(); |
|---|
| | 144 | |
|---|
| | 145 | $bc1 = new BookstoreContest(); |
|---|
| | 146 | $bc1->setBookstore($store1); |
|---|
| | 147 | $bc1->setContest($c1); |
|---|
| | 148 | $bc1->save(); |
|---|
| | 149 | |
|---|
| | 150 | $bc2 = new BookstoreContest(); |
|---|
| | 151 | $bc2->setBookstore($store1); |
|---|
| | 152 | $bc2->setContest($c2); |
|---|
| | 153 | $bc2->save(); |
|---|
| | 154 | |
|---|
| | 155 | $bce1 = new BookstoreContestEntry(); |
|---|
| | 156 | $bce1->setEntryDate("now"); |
|---|
| | 157 | $bce1->setCustomer($cust1); |
|---|
| | 158 | $bce1->setBookstoreContest($bc1); |
|---|
| | 159 | $bce1->save(); |
|---|
| | 160 | |
|---|
| | 161 | $bce2 = new BookstoreContestEntry(); |
|---|
| | 162 | $bce2->setEntryDate("now"); |
|---|
| | 163 | $bce2->setCustomer($cust1); |
|---|
| | 164 | $bce2->setBookstoreContest($bc2); |
|---|
| | 165 | $bce2->save(); |
|---|
| | 166 | |
|---|
| | 167 | // Now, if we remove $bc1, we expect *only* bce1 to be no longer valid. |
|---|
| | 168 | |
|---|
| | 169 | BookstoreContestPeer::doDelete($bc1); |
|---|
| | 170 | |
|---|
| | 171 | $newCount = BookstoreContestEntryPeer::doCount(new Criteria()); |
|---|
| | 172 | |
|---|
| | 173 | $this->assertEquals($origBceCount + 1, $newCount, "Expected new number of rows in BCE to be orig + 1"); |
|---|
| | 174 | |
|---|
| | 175 | $bcetest = BookstoreContestEntryPeer::retrieveByPK($store1->getId(), $c1->getId(), $cust1->getId()); |
|---|
| | 176 | $this->assertNull($bcetest, "Expected BCE for store1 to be cascade deleted."); |
|---|
| | 177 | |
|---|
| | 178 | $bcetest2 = BookstoreContestEntryPeer::retrieveByPK($store1->getId(), $c2->getId(), $cust1->getId()); |
|---|
| | 179 | $this->assertNotNull($bcetest2, "Expected BCE for store2 to NOT be cascade deleted."); |
|---|
| | 524 | * Tests the doCount() method with limit/offset. |
|---|
| | 525 | */ |
|---|
| | 526 | public function testDoCountLimitOffset() |
|---|
| | 527 | { |
|---|
| | 528 | BookPeer::doDeleteAll(); |
|---|
| | 529 | |
|---|
| | 530 | for ($i=0; $i < 25; $i++) { |
|---|
| | 531 | $b = new Book(); |
|---|
| | 532 | $b->setTitle("Book $i"); |
|---|
| | 533 | $b->setISBN("ISBN $i"); |
|---|
| | 534 | $b->save(); |
|---|
| | 535 | } |
|---|
| | 536 | |
|---|
| | 537 | $c = new Criteria(); |
|---|
| | 538 | $totalCount = BookPeer::doCount($c); |
|---|
| | 539 | |
|---|
| | 540 | $this->assertEquals(25, $totalCount); |
|---|
| | 541 | |
|---|
| | 542 | $c2 = new Criteria(); |
|---|
| | 543 | $c2->setLimit(10); |
|---|
| | 544 | $this->assertEquals(10, BookPeer::doCount($c2)); |
|---|
| | 545 | |
|---|
| | 546 | $c3 = new Criteria(); |
|---|
| | 547 | $c3->setOffset(10); |
|---|
| | 548 | $this->assertEquals(15, BookPeer::doCount($c3)); |
|---|
| | 549 | |
|---|
| | 550 | $c4 = new Criteria(); |
|---|
| | 551 | $c4->setOffset(5); |
|---|
| | 552 | $c4->setLimit(5); |
|---|
| | 553 | $this->assertEquals(5, BookPeer::doCount($c4)); |
|---|
| | 554 | |
|---|
| | 555 | $c5 = new Criteria(); |
|---|
| | 556 | $c5->setOffset(20); |
|---|
| | 557 | $c5->setLimit(10); |
|---|
| | 558 | $this->assertEquals(5, BookPeer::doCount($c5)); |
|---|
| | 559 | } |
|---|
| | 560 | |
|---|
| | 561 | /** |
|---|
| | 562 | * Test doCountJoin*() methods. |
|---|
| | 563 | */ |
|---|
| | 564 | public function testDoCountJoin() |
|---|
| | 565 | { |
|---|
| | 566 | BookPeer::doDeleteAll(); |
|---|
| | 567 | |
|---|
| | 568 | for ($i=0; $i < 25; $i++) { |
|---|
| | 569 | $b = new Book(); |
|---|
| | 570 | $b->setTitle("Book $i"); |
|---|
| | 571 | $b->setISBN("ISBN $i"); |
|---|
| | 572 | $b->save(); |
|---|
| | 573 | } |
|---|
| | 574 | |
|---|
| | 575 | $c = new Criteria(); |
|---|
| | 576 | $totalCount = BookPeer::doCount($c); |
|---|
| | 577 | |
|---|
| | 578 | $this->assertEquals($totalCount, BookPeer::doCountJoinAuthor($c)); |
|---|
| | 579 | $this->assertEquals($totalCount, BookPeer::doCountJoinPublisher($c)); |
|---|
| | 580 | } |
|---|
| | 581 | |
|---|
| | 582 | /** |
|---|
| | 709 | /** |
|---|
| | 710 | * Testing foreign keys with multiple referrer columns. |
|---|
| | 711 | * @link http://propel.phpdb.org/trac/ticket/606 |
|---|
| | 712 | */ |
|---|
| | 713 | public function testMultiColFk() |
|---|
| | 714 | { |
|---|
| | 715 | $con = Propel::getConnection(BookPeer::DATABASE_NAME); |
|---|
| | 716 | |
|---|
| | 717 | ReaderFavoritePeer::doDeleteAll(); |
|---|
| | 718 | |
|---|
| | 719 | $b1 = new Book(); |
|---|
| | 720 | $b1->setTitle("Book1"); |
|---|
| | 721 | $b1->setISBN("ISBN-1"); |
|---|
| | 722 | $b1->save(); |
|---|
| | 723 | |
|---|
| | 724 | $r1 = new BookReader(); |
|---|
| | 725 | $r1-> setName("Me"); |
|---|
| | 726 | $r1->save(); |
|---|
| | 727 | |
|---|
| | 728 | $bo1 = new BookOpinion(); |
|---|
| | 729 | $bo1->setBookId($b1->getId()); |
|---|
| | 730 | $bo1->setReaderId($r1->getId()); |
|---|
| | 731 | $bo1->setRating(9); |
|---|
| | 732 | $bo1->setRecommendToFriend(true); |
|---|
| | 733 | $bo1->save(); |
|---|
| | 734 | |
|---|
| | 735 | $rf1 = new ReaderFavorite(); |
|---|
| | 736 | $rf1->setReaderId($r1->getId()); |
|---|
| | 737 | $rf1->setBookId($b1->getId()); |
|---|
| | 738 | $rf1->save(); |
|---|
| | 739 | |
|---|
| | 740 | $c = new Criteria(ReaderFavoritePeer::DATABASE_NAME); |
|---|
| | 741 | $c->add(ReaderFavoritePeer::BOOK_ID, $b1->getId()); |
|---|
| | 742 | $c->add(ReaderFavoritePeer::READER_ID, $r1->getId()); |
|---|
| | 743 | |
|---|
| | 744 | // This will produce an error! |
|---|
| | 745 | $results = ReaderFavoritePeer::doSelectJoinBookOpinion($c); |
|---|
| | 746 | $this->assertEquals(1, count($results), "Expected 1 result"); |
|---|
| | 747 | } |
|---|
| | 748 | /** |
|---|
| | 749 | * Testing foreign keys with multiple referrer columns. |
|---|
| | 750 | * @link http://propel.phpdb.org/trac/ticket/606 |
|---|
| | 751 | */ |
|---|
| | 752 | public function testMultiColJoin() |
|---|
| | 753 | { |
|---|
| | 754 | BookstoreContestPeer::doDeleteAll(); |
|---|
| | 755 | BookstoreContestEntryPeer::doDeleteAll(); |
|---|
| | 756 | |
|---|
| | 757 | $bs = new Bookstore(); |
|---|
| | 758 | $bs->setStoreName("Test1"); |
|---|
| | 759 | $bs->setPopulationServed(5); |
|---|
| | 760 | $bs->save(); |
|---|
| | 761 | $bs1Id = $bs->getId(); |
|---|
| | 762 | |
|---|
| | 763 | $bs2 = new Bookstore(); |
|---|
| | 764 | $bs2->setStoreName("Test2"); |
|---|
| | 765 | $bs2->setPopulationServed(5); |
|---|
| | 766 | $bs2->save(); |
|---|
| | 767 | $bs2Id = $bs2->getId(); |
|---|
| | 768 | |
|---|
| | 769 | $ct1 = new Contest(); |
|---|
| | 770 | $ct1->setName("Contest1!"); |
|---|
| | 771 | $ct1->save(); |
|---|
| | 772 | $ct1Id = $ct1->getId(); |
|---|
| | 773 | |
|---|
| | 774 | $ct2 = new Contest(); |
|---|
| | 775 | $ct2->setName("Contest2!"); |
|---|
| | 776 | $ct2->save(); |
|---|
| | 777 | $ct2Id = $ct2->getId(); |
|---|
| | 778 | |
|---|
| | 779 | $cmr = new Customer(); |
|---|
| | 780 | $cmr->setName("Customer1"); |
|---|
| | 781 | $cmr->save(); |
|---|
| | 782 | $cmr1Id = $cmr->getId(); |
|---|
| | 783 | |
|---|
| | 784 | $cmr2 = new Customer(); |
|---|
| | 785 | $cmr2->setName("Customer2"); |
|---|
| | 786 | $cmr2->save(); |
|---|
| | 787 | $cmr2Id = $cmr2->getId(); |
|---|
| | 788 | |
|---|
| | 789 | $contest = new BookstoreContest(); |
|---|
| | 790 | $contest->setBookstoreId($bs1Id); |
|---|
| | 791 | $contest->setContestId($ct1Id); |
|---|
| | 792 | $contest->save(); |
|---|
| | 793 | |
|---|
| | 794 | $contest = new BookstoreContest(); |
|---|
| | 795 | $contest->setBookstoreId($bs2Id); |
|---|
| | 796 | $contest->setContestId($ct1Id); |
|---|
| | 797 | $contest->save(); |
|---|
| | 798 | |
|---|
| | 799 | $entry = new BookstoreContestEntry(); |
|---|
| | 800 | $entry->setBookstoreId($bs1Id); |
|---|
| | 801 | $entry->setContestId($ct1Id); |
|---|
| | 802 | $entry->setCustomerId($cmr1Id); |
|---|
| | 803 | $entry->save(); |
|---|
| | 804 | |
|---|
| | 805 | $entry = new BookstoreContestEntry(); |
|---|
| | 806 | $entry->setBookstoreId($bs1Id); |
|---|
| | 807 | $entry->setContestId($ct1Id); |
|---|
| | 808 | $entry->setCustomerId($cmr2Id); |
|---|
| | 809 | $entry->save(); |
|---|
| | 810 | |
|---|
| | 811 | // Note: this test isn't really working very well. We setup fkeys that |
|---|
| | 812 | // require that the BookstoreContest rows exist and then try to violate |
|---|
| | 813 | // the rules ... :-/ This may work in some lenient databases, but an error |
|---|
| | 814 | // is expected here. |
|---|
| | 815 | |
|---|
| | 816 | /* |
|---|
| | 817 | * Commented out for now ... though without it, this test may not really be testing anything |
|---|
| | 818 | $entry = new BookstoreContestEntry(); |
|---|
| | 819 | $entry->setBookstoreId($bs1Id); |
|---|
| | 820 | $entry->setContestId($ct2Id); |
|---|
| | 821 | $entry->setCustomerId($cmr2Id); |
|---|
| | 822 | $entry->save(); |
|---|
| | 823 | */ |
|---|
| | 824 | |
|---|
| | 825 | |
|---|
| | 826 | $c = new Criteria(); |
|---|
| | 827 | $c->addJoin(array(BookstoreContestEntryPeer::BOOKSTORE_ID, BookstoreContestEntryPeer::CONTEST_ID), array(BookstoreContestPeer::BOOKSTORE_ID, BookstoreContestPeer::CONTEST_ID) ); |
|---|
| | 828 | |
|---|
| | 829 | $results = BookstoreContestEntryPeer::doSelect($c); |
|---|
| | 830 | $this->assertEquals(2, count($results) ); |
|---|
| | 831 | foreach ($results as $result) { |
|---|
| | 832 | $this->assertEquals($bs1Id, $result->getBookstoreId() ); |
|---|
| | 833 | $this->assertEquals($ct1Id, $result->getContestId() ); |
|---|
| | 834 | } |
|---|
| | 835 | } |
|---|
| | 836 | |
|---|
| | 837 | |
|---|
| | 838 | /** |
|---|
| | 839 | * Test doCountJoin*() methods with ORDER BY columns in Criteria. |
|---|
| | 840 | * @link http://propel.phpdb.org/trac/ticket/627 |
|---|
| | 841 | */ |
|---|
| | 842 | public function testDoCountJoinWithOrderBy() |
|---|
| | 843 | { |
|---|
| | 844 | $c = new Criteria(BookPeer::DATABASE_NAME); |
|---|
| | 845 | $c->addAscendingOrderByColumn(BookPeer::ID); |
|---|
| | 846 | |
|---|
| | 847 | // None of these should not throw an exception! |
|---|
| | 848 | BookPeer::doCountJoinAll($c); |
|---|
| | 849 | BookPeer::doCountJoinAllExceptAuthor($c); |
|---|
| | 850 | BookPeer::doCountJoinAuthor($c); |
|---|
| | 851 | } |
|---|