示例#1
0
 /**
  *
  */
 public function testBigIntIgnoreCaseOrderBy()
 {
     // Some sample data
     $b = new Bookstore();
     $b->setStoreName("SortTest1")->setPopulationServed(2000)->save();
     $b = new Bookstore();
     $b->setStoreName("SortTest2")->setPopulationServed(201)->save();
     $b = new Bookstore();
     $b->setStoreName("SortTest3")->setPopulationServed(302)->save();
     $b = new Bookstore();
     $b->setStoreName("SortTest4")->setPopulationServed(10000000)->save();
     $c = new Criteria();
     $c->setIgnoreCase(true);
     $c->add(BookstorePeer::STORE_NAME, 'SortTest%', Criteria::LIKE);
     $c->addAscendingOrderByColumn(BookstorePeer::POPULATION_SERVED);
     $rows = BookstorePeer::doSelect($c);
     $this->assertEquals('SortTest2', $rows[0]->getStoreName());
     $this->assertEquals('SortTest3', $rows[1]->getStoreName());
     $this->assertEquals('SortTest1', $rows[2]->getStoreName());
     $this->assertEquals('SortTest4', $rows[3]->getStoreName());
 }
 /**
  * Test that setting the auto-increment primary key will result in exception.
  */
 public function testSettingAutoIncrementPK()
 {
     // The whole test is in a transaction, but this test needs real transactions
     $this->con->commit();
     $b = new Bookstore();
     $b->setId(1);
     $b->setStoreName("Test");
     try {
         $b->save();
         $this->fail("Expected setting auto-increment primary key to result in Exception");
     } catch (Exception $x) {
         $this->assertInstanceOf('PropelException', $x);
     }
     // ... but we should silently ignore NULL values, since these are really
     // the same as "not set" in PHP world.
     $b = new Bookstore();
     $b->setId(null);
     $b->setStoreName("Test2");
     try {
         $b->save();
     } catch (Exception $x) {
         $this->fail("Expected no exception when setting auto-increment primary key to NULL");
     }
     // success ...
     $this->con->beginTransaction();
 }
 /**
  * Test that setting the auto-increment primary key will result in exception.
  */
 public function testSettingAutoIncrementPK()
 {
     $b = new Bookstore();
     $b->setId(1);
     $b->setStoreName("Test");
     try {
         $b->save();
         $this->fail("Expected setting auto-increment primary key to result in Exception");
     } catch (Exception $x) {
         $this->assertType('PropelException', $x);
     }
     // ... but we should silently ignore NULL values, since these are really
     // the same as "not set" in PHP world.
     $b = new Bookstore();
     $b->setId(null);
     $b->setStoreName("Test2");
     try {
         $b->save();
     } catch (Exception $x) {
         $this->fail("Expected no exception when setting auto-increment primary key to NULL");
     }
     // success ...
 }
 /**
  * Testing foreign keys with multiple referrer columns.
  * @link       http://propel.phpdb.org/trac/ticket/606
  */
 public function testMultiColJoin()
 {
     BookstoreContestPeer::doDeleteAll();
     BookstoreContestEntryPeer::doDeleteAll();
     $bs = new Bookstore();
     $bs->setStoreName("Test1");
     $bs->setPopulationServed(5);
     $bs->save();
     $bs1Id = $bs->getId();
     $bs2 = new Bookstore();
     $bs2->setStoreName("Test2");
     $bs2->setPopulationServed(5);
     $bs2->save();
     $bs2Id = $bs2->getId();
     $ct1 = new Contest();
     $ct1->setName("Contest1!");
     $ct1->save();
     $ct1Id = $ct1->getId();
     $ct2 = new Contest();
     $ct2->setName("Contest2!");
     $ct2->save();
     $ct2Id = $ct2->getId();
     $cmr = new Customer();
     $cmr->setName("Customer1");
     $cmr->save();
     $cmr1Id = $cmr->getId();
     $cmr2 = new Customer();
     $cmr2->setName("Customer2");
     $cmr2->save();
     $cmr2Id = $cmr2->getId();
     $contest = new BookstoreContest();
     $contest->setBookstoreId($bs1Id);
     $contest->setContestId($ct1Id);
     $contest->save();
     $contest = new BookstoreContest();
     $contest->setBookstoreId($bs2Id);
     $contest->setContestId($ct1Id);
     $contest->save();
     $entry = new BookstoreContestEntry();
     $entry->setBookstoreId($bs1Id);
     $entry->setContestId($ct1Id);
     $entry->setCustomerId($cmr1Id);
     $entry->save();
     $entry = new BookstoreContestEntry();
     $entry->setBookstoreId($bs1Id);
     $entry->setContestId($ct1Id);
     $entry->setCustomerId($cmr2Id);
     $entry->save();
     // Note: this test isn't really working very well.  We setup fkeys that
     // require that the BookstoreContest rows exist and then try to violate
     // the rules ... :-/  This may work in some lenient databases, but an error
     // is expected here.
     /*
      * Commented out for now ... though without it, this test may not really be testing anything
     $entry = new BookstoreContestEntry();
     $entry->setBookstoreId($bs1Id);
     $entry->setContestId($ct2Id);
     $entry->setCustomerId($cmr2Id);
     $entry->save();
     */
     $c = new Criteria();
     $c->addJoin(array(BookstoreContestEntryPeer::BOOKSTORE_ID, BookstoreContestEntryPeer::CONTEST_ID), array(BookstoreContestPeer::BOOKSTORE_ID, BookstoreContestPeer::CONTEST_ID));
     $results = BookstoreContestEntryPeer::doSelect($c);
     $this->assertEquals(2, count($results));
     foreach ($results as $result) {
         $this->assertEquals($bs1Id, $result->getBookstoreId());
         $this->assertEquals($ct1Id, $result->getContestId());
     }
 }
 /**
  * Test that cascading deletes are happening correctly for composite pk.
  * @link       http://propel.phpdb.org/trac/ticket/544
  */
 public function testDoDelete_Cascade_CompositePK()
 {
     $origBceCount = BookstoreContestEntryPeer::doCount(new Criteria());
     $cust1 = new Customer();
     $cust1->setName("Cust1");
     $cust1->save();
     $cust2 = new Customer();
     $cust2->setName("Cust2");
     $cust2->save();
     $c1 = new Contest();
     $c1->setName("Contest1");
     $c1->save();
     $c2 = new Contest();
     $c2->setName("Contest2");
     $c2->save();
     $store1 = new Bookstore();
     $store1->setStoreName("Store1");
     $store1->save();
     $bc1 = new BookstoreContest();
     $bc1->setBookstore($store1);
     $bc1->setContest($c1);
     $bc1->save();
     $bc2 = new BookstoreContest();
     $bc2->setBookstore($store1);
     $bc2->setContest($c2);
     $bc2->save();
     $bce1 = new BookstoreContestEntry();
     $bce1->setEntryDate("now");
     $bce1->setCustomer($cust1);
     $bce1->setBookstoreContest($bc1);
     $bce1->save();
     $bce2 = new BookstoreContestEntry();
     $bce2->setEntryDate("now");
     $bce2->setCustomer($cust1);
     $bce2->setBookstoreContest($bc2);
     $bce2->save();
     // Now, if we remove $bc1, we expect *only* bce1 to be no longer valid.
     BookstoreContestPeer::doDelete($bc1);
     $newCount = BookstoreContestEntryPeer::doCount(new Criteria());
     $this->assertEquals($origBceCount + 1, $newCount, "Expected new number of rows in BCE to be orig + 1");
     $bcetest = BookstoreContestEntryPeer::retrieveByPK($store1->getId(), $c1->getId(), $cust1->getId());
     $this->assertNull($bcetest, "Expected BCE for store1 to be cascade deleted.");
     $bcetest2 = BookstoreContestEntryPeer::retrieveByPK($store1->getId(), $c2->getId(), $cust1->getId());
     $this->assertNotNull($bcetest2, "Expected BCE for store2 to NOT be cascade deleted.");
 }
 /**
  * Test behavior of columns that are implicated in multiple foreign keys.
  * @link       http://propel.phpdb.org/trac/ticket/228
  */
 public function testMultiFkImplication()
 {
     BookstoreDataPopulator::populate();
     // Create a new bookstore, contest, bookstore_contest, and bookstore_contest_entry
     $b = new Bookstore();
     $b->setStoreName("Foo!");
     $b->save();
     $c = new Contest();
     $c->setName("Bookathon Contest");
     $c->save();
     $bc = new BookstoreContest();
     $bc->setBookstore($b);
     $bc->setContest($c);
     $bc->save();
     $c = new Customer();
     $c->setName("Happy Customer");
     $c->save();
     $bce = new BookstoreContestEntry();
     $bce->setBookstore($b);
     $bce->setBookstoreContest($bc);
     $bce->setCustomer($c);
     $bce->save();
     $bce->setBookstoreId(null);
     $this->assertNull($bce->getBookstoreContest());
     $this->assertNull($bce->getBookstore());
 }
 public static function populate($con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     }
     $con->beginTransaction();
     // Add publisher records
     // ---------------------
     $scholastic = new Publisher();
     $scholastic->setName("Scholastic");
     // do not save, will do later to test cascade
     $morrow = new Publisher();
     $morrow->setName("William Morrow");
     $morrow->save($con);
     $morrow_id = $morrow->getId();
     $penguin = new Publisher();
     $penguin->setName("Penguin");
     $penguin->save();
     $penguin_id = $penguin->getId();
     $vintage = new Publisher();
     $vintage->setName("Vintage");
     $vintage->save($con);
     $vintage_id = $vintage->getId();
     $rowling = new Author();
     $rowling->setFirstName("J.K.");
     $rowling->setLastName("Rowling");
     // no save()
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save($con);
     $stephenson_id = $stephenson->getId();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save($con);
     $byron_id = $byron->getId();
     $grass = new Author();
     $grass->setFirstName("Gunter");
     $grass->setLastName("Grass");
     $grass->save($con);
     $grass_id = $grass->getId();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($rowling);
     $phoenix->setPublisher($scholastic);
     $phoenix->setPrice(10.99);
     $phoenix->save($con);
     $phoenix_id = $phoenix->getId();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setPrice(11.99);
     $qs->setAuthor($stephenson);
     $qs->setPublisher($morrow);
     $qs->save($con);
     $qs_id = $qs->getId();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setPrice(12.99);
     $dj->setAuthor($byron);
     $dj->setPublisher($penguin);
     $dj->save($con);
     $dj_id = $dj->getId();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setPrice(13.99);
     $td->setAuthor($grass);
     $td->setPublisher($vintage);
     $td->save($con);
     $td_id = $td->getId();
     $r1 = new Review();
     $r1->setBook($phoenix);
     $r1->setReviewedBy("Washington Post");
     $r1->setRecommended(true);
     $r1->setReviewDate(time());
     $r1->save($con);
     $r1_id = $r1->getId();
     $r2 = new Review();
     $r2->setBook($phoenix);
     $r2->setReviewedBy("New York Times");
     $r2->setRecommended(false);
     $r2->setReviewDate(time());
     $r2->save($con);
     $r2_id = $r2->getId();
     $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif';
     $clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($td);
     $m1->setCoverImage(file_get_contents($blob_path));
     // CLOB is broken in PDO OCI, see http://pecl.php.net/bugs/bug.php?id=7943
     if (get_class(Propel::getDB()) != "DBOracle") {
         $m1->setExcerpt(file_get_contents($clob_path));
     }
     $m1->save($con);
     // Add book list records
     // ---------------------
     // (this is for many-to-many tests)
     $blc1 = new BookClubList();
     $blc1->setGroupLeader("Crazyleggs");
     $blc1->setTheme("Happiness");
     $brel1 = new BookListRel();
     $brel1->setBook($phoenix);
     $brel2 = new BookListRel();
     $brel2->setBook($dj);
     $blc1->addBookListRel($brel1);
     $blc1->addBookListRel($brel2);
     $blc1->save();
     $bemp1 = new BookstoreEmployee();
     $bemp1->setName("John");
     $bemp1->setJobTitle("Manager");
     $bemp2 = new BookstoreEmployee();
     $bemp2->setName("Pieter");
     $bemp2->setJobTitle("Clerk");
     $bemp2->setSupervisor($bemp1);
     $bemp2->save($con);
     $bemp3 = new BookstoreCashier();
     $bemp3->setName("Tim");
     $bemp3->setJobTitle("Cashier");
     $bemp3->save($con);
     $role = new AcctAccessRole();
     $role->setName("Admin");
     $bempacct = new BookstoreEmployeeAccount();
     $bempacct->setBookstoreEmployee($bemp1);
     $bempacct->setAcctAccessRole($role);
     $bempacct->setLogin("john");
     $bempacct->setPassword("johnp4ss");
     $bempacct->save($con);
     // Add bookstores
     $store = new Bookstore();
     $store->setStoreName("Amazon");
     $store->setPopulationServed(5000000000);
     // world population
     $store->setTotalBooks(300);
     $store->save($con);
     $store = new Bookstore();
     $store->setStoreName("Local Store");
     $store->setPopulationServed(20);
     $store->setTotalBooks(500000);
     $store->save($con);
     $summary = new BookSummary();
     $summary->setSummarizedBook($phoenix);
     $summary->setSummary("Harry Potter does some amazing magic!");
     $summary->save();
     $con->commit();
 }