Show
Ignore:
Timestamp:
08/06/08 07:55:11 (2 months ago)
Author:
ron
Message:

Merge in changes from 1.3 branch: merge -r 832:1067

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/generator

    • Property svn:ignore set to
      build.properties
  • trunk/generator/test/classes/propel/GeneratedPeerTest.php

    r1024 r1068  
    4141         * Test ability to delete multiple rows via single Criteria object. 
    4242         */ 
    43         public function t3estDoDelete_MultiTable() { 
     43        public function testDoDelete_MultiTable() { 
    4444 
    4545                $selc = new Criteria(); 
     
    9090         * Test that cascading deletes are happening correctly (whether emulated or native). 
    9191         */ 
    92         public function testDoDelete_Cascade() { 
     92        public function testDoDelete_Cascade_Simple() 
     93        { 
    9394 
    9495                // The 'media' table will cascade from book deletes 
     
    9697                // 1) Assert the row exists right now 
    9798 
    98                        $medias = MediaPeer::doSelect(new Criteria()); 
    99                        $this->assertTrue(count($medias) > 0, "Expected to find at least one row in 'media' table."); 
    100                        $media = $medias[0]; 
    101                        $mediaId = $media->getId(); 
     99                $medias = MediaPeer::doSelect(new Criteria()); 
     100                $this->assertTrue(count($medias) > 0, "Expected to find at least one row in 'media' table."); 
     101                $media = $medias[0]; 
     102                $mediaId = $media->getId(); 
    102103 
    103104                // 2) Delete the owning book 
    104105 
    105                        $owningBookId = $media->getBookId(); 
    106                        BookPeer::doDelete($owningBookId); 
     106                $owningBookId = $media->getBookId(); 
     107                BookPeer::doDelete($owningBookId); 
    107108 
    108109                // 3) Assert that the media row is now also gone 
    109110 
    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."); 
    112180 
    113181        } 
     
    121189 
    122190                // 1) Get an arbitrary book 
    123  
    124                         $c = new Criteria(); 
    125                         $book = BookPeer::doSelectOne($c); 
    126                         $bookId = $book->getId(); 
    127                         $authorId = $book->getAuthorId(); 
    128                         unset($book); 
     191                $c = new Criteria(); 
     192                $book = BookPeer::doSelectOne($c); 
     193                $bookId = $book->getId(); 
     194                $authorId = $book->getAuthorId(); 
     195                unset($book); 
    129196 
    130197                // 2) Delete the author for that book 
    131                        AuthorPeer::doDelete($authorId); 
     198                AuthorPeer::doDelete($authorId); 
    132199 
    133200                // 3) Assert that the book.author_id column is now NULL 
    134201 
    135                        $book = BookPeer::retrieveByPK($bookId); 
    136                        $this->assertNull($book->getAuthorId(), "Expect the book.author_id to be NULL after the author was removed."); 
     202                $book = BookPeer::retrieveByPK($bookId); 
     203                $this->assertNull($book->getAuthorId(), "Expect the book.author_id to be NULL after the author was removed."); 
    137204 
    138205        } 
     
    144211 
    145212                // 1) get an arbitrary book 
    146                        $book = BookPeer::doSelectOne(new Criteria()); 
    147                        $bookId = $book->getId(); 
     213                $book = BookPeer::doSelectOne(new Criteria()); 
     214                $bookId = $book->getId(); 
    148215 
    149216                // 2) now delete that book 
    150                        BookPeer::doDelete($bookId); 
     217                BookPeer::doDelete($bookId); 
    151218 
    152219                // 3) now make sure it's gone 
    153                        $obj = BookPeer::retrieveByPK($bookId); 
    154                        $this->assertNull($obj, "Expect NULL when retrieving on no matching Book."); 
     220                $obj = BookPeer::retrieveByPK($bookId); 
     221                $this->assertNull($obj, "Expect NULL when retrieving on no matching Book."); 
    155222 
    156223        } 
     
    162229 
    163230                // 1) get an arbitrary book 
    164                        $book = BookPeer::doSelectOne(new Criteria()); 
    165                        $bookId = $book->getId(); 
     231                $book = BookPeer::doSelectOne(new Criteria()); 
     232                $bookId = $book->getId(); 
    166233 
    167234                // 2) now delete that book 
    168                        BookPeer::doDelete($book); 
     235                BookPeer::doDelete($book); 
    169236 
    170237                // 3) now make sure it's gone 
    171                        $obj = BookPeer::retrieveByPK($bookId); 
    172                        $this->assertNull($obj, "Expect NULL when retrieving on no matching Book."); 
    173  
    174                
     238                $obj = BookPeer::retrieveByPK($bookId); 
     239                $this->assertNull($obj, "Expect NULL when retrieving on no matching Book."); 
     240 
     241       
    175242 
    176243 
     
    220287 
    221288                $values = new Criteria(); 
    222                 $values->add(PublisherPeer::ID, 1); 
    223289                $values->add(PublisherPeer::NAME, $name); 
    224290                PublisherPeer::doInsert($values); 
     
    456522 
    457523        /** 
     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        /** 
    458583         * Test passing null values to removeInstanceFromPool(). 
    459584         */ 
     
    467592                } 
    468593        } 
    469          
     594 
    470595        /** 
    471596         * @see        testDoDeleteCompositePK() 
     
    486611                } 
    487612        } 
    488          
     613 
    489614        /** 
    490615         * @see        testDoDeleteCompositePK() 
     
    505630                } 
    506631        } 
    507          
     632 
    508633        /** 
    509634         * @link       http://propel.phpdb.org/trac/ticket/519 
     
    512637        { 
    513638                $con = Propel::getConnection(BookPeer::DATABASE_NAME); 
    514                  
     639 
    515640                ReaderFavoritePeer::doDeleteAll(); 
    516641                // Create book and reader with ID 1 
    517642                // Create book and reader with ID 2 
    518                  
     643 
    519644                $this->createBookWithId(1); 
    520645                $this->createBookWithId(2); 
    521646                $this->createReaderWithId(1); 
    522647                $this->createReaderWithId(2); 
    523                  
    524                 for($i=1; $i <= 2; $i++) { 
    525                         for($j=1; $j <= 2; $j++) { 
     648 
     649                for ($i=1; $i <= 2; $i++) { 
     650                        for ($j=1; $j <= 2; $j++) { 
     651                                $bo = new BookOpinion(); 
     652                                $bo->setBookId($i); 
     653                                $bo->setReaderId($j); 
     654                                $bo->save(); 
     655                                 
    526656                                $rf = new ReaderFavorite(); 
    527657                                $rf->setBookId($i); 
     
    532662 
    533663                $this->assertEquals(4, ReaderFavoritePeer::doCount(new Criteria())); 
    534                  
    535                 // Now delete 2 of those rows  
     664 
     665                // Now delete 2 of those rows 
    536666                ReaderFavoritePeer::doDelete(array(array(1,1), array(2,2))); 
    537                  
     667 
    538668                $this->assertEquals(2, ReaderFavoritePeer::doCount(new Criteria())); 
    539                  
     669 
    540670                $this->assertNotNull(ReaderFavoritePeer::retrieveByPK(2,1)); 
    541671                $this->assertNotNull(ReaderFavoritePeer::retrieveByPK(1,2)); 
     
    543673                $this->assertNull(ReaderFavoritePeer::retrieveByPK(2,2)); 
    544674        } 
    545          
    546          
     675 
     676 
    547677        /** 
    548678         * Test hydration of joined rows that contain lazy load columns. 
     
    559689                $bemp2->setJobTitle("Clerk"); 
    560690                $bemp2->save(); 
    561                  
     691 
    562692                $role = new AcctAccessRole(); 
    563693                $role->setName("Admin"); 
    564                  
     694 
    565695                $bempacct = new BookstoreEmployeeAccount(); 
    566696                $bempacct->setBookstoreEmployee($bemp2); 
     
    569699                $bempacct->setPassword("johnp4ss"); 
    570700                $bempacct->save(); 
    571                  
     701 
    572702                $c = new Criteria(); 
    573703                $results = BookstoreEmployeeAccountPeer::doSelectJoinAll($c); 
    574704                $o = $results[0]; 
    575                  
     705 
    576706                $this->assertEquals('Admin', $o->getAcctAccessRole()->getName()); 
    577707        } 
    578708 
     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        } 
    579852}