protected function setUp()
 {
     parent::setUp();
     $b1 = new BookstoreEmployee();
     $b1->setName('b1');
     $b1->save();
     $b2 = new BookstoreManager();
     $b2->setName('b2');
     $b2->save();
     $b3 = new BookstoreCashier();
     $b3->setName('b3');
     $b3->save();
 }
 public function testDeleteAllFilter()
 {
     BookstoreDataPopulator::depopulate($this->con);
     $manager = new BookstoreManager();
     $manager->save($this->con);
     $cashier1 = new BookstoreCashier();
     $cashier1->save($this->con);
     $cashier2 = new BookstoreCashier();
     $cashier2->save($this->con);
     BookstoreManagerQuery::create()->deleteAll();
     $nbCash = BookstoreEmployeeQuery::create()->count();
     $this->assertEquals(2, $nbCash, 'Delete in sub query affects only child results');
 }
 public function testFindPkSimpleWithSingleTableInheritanceReturnCorrectClass()
 {
     Propel::disableInstancePooling();
     $employee = new BookstoreEmployee();
     $employee->save($this->con);
     $manager = new BookstoreManager();
     $manager->save($this->con);
     $cashier1 = new BookstoreCashier();
     $cashier1->save($this->con);
     $cashier2 = new BookstoreCashier();
     $cashier2->save($this->con);
     $this->assertInstanceOf('BookstoreEmployee', BookstoreEmployeeQuery::create()->findPk($employee->getId()), 'findPk() return right object : BookstoreEmployee');
     $this->assertInstanceOf('BookstoreManager', BookstoreEmployeeQuery::create()->findPk($manager->getId()), 'findPk() return right object : BookstoreManager');
     $this->assertInstanceOf('BookstoreCashier', BookstoreEmployeeQuery::create()->findPk($cashier1->getId()), 'findPk() return right object : BookstoreCashier');
     $this->assertInstanceOf('BookstoreCashier', BookstoreEmployeeQuery::create()->findPk($cashier2->getId()), 'findPk() return right object : BookstoreCashier');
     Propel::enableInstancePooling();
 }
 /**
  * Test inheritance features.
  */
 public function testInheritance()
 {
     $manager = new BookstoreManager();
     $manager->setName("Manager 1");
     $manager->setJobTitle("Warehouse Manager");
     $manager->save();
     $managerId = $manager->getId();
     $employee = new BookstoreEmployee();
     $employee->setName("Employee 1");
     $employee->setJobTitle("Janitor");
     $employee->setSupervisorId($managerId);
     $employee->save();
     $empId = $employee->getId();
     $cashier = new BookstoreCashier();
     $cashier->setName("Cashier 1");
     $cashier->setJobTitle("Cashier");
     $cashier->save();
     $cashierId = $cashier->getId();
     // 1) test the pooled instances'
     $c = new Criteria();
     $c->add(BookstoreEmployeePeer::ID, array($managerId, $empId, $cashierId), Criteria::IN);
     $c->addAscendingOrderByColumn(BookstoreEmployeePeer::ID);
     $objects = BookstoreEmployeePeer::doSelect($c);
     $this->assertEquals(3, count($objects), "Expected 3 objects to be returned.");
     list($o1, $o2, $o3) = $objects;
     $this->assertSame($o1, $manager);
     $this->assertSame($o2, $employee);
     $this->assertSame($o3, $cashier);
     // 2) test a forced reload from database
     BookstoreEmployeePeer::clearInstancePool();
     list($o1, $o2, $o3) = BookstoreEmployeePeer::doSelect($c);
     $this->assertTrue($o1 instanceof BookstoreManager, "Expected BookstoreManager object, got " . get_class($o1));
     $this->assertTrue($o2 instanceof BookstoreEmployee, "Expected BookstoreEmployee object, got " . get_class($o2));
     $this->assertTrue($o3 instanceof BookstoreCashier, "Expected BookstoreCashier object, got " . get_class($o3));
 }
 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();
 }
 public function testFindOneOrCreateFunction()
 {
     $cashier1 = new BookstoreCashier();
     $cashier1->save($this->con);
     $cashier2 = BookstoreCashierQuery::create()->findOneOrCreate($this->con);
     $this->assertInstanceOf('BookstoreCashier', $cashier2, 'findOneOrCreate return right object when find one : BookstoreCashier');
     BookstoreCashierQuery::create()->deleteAll($this->con);
     $cashier3 = BookstoreCashierQuery::create()->findOneOrCreate($this->con);
     $this->assertInstanceOf('BookstoreCashier', $cashier3, 'findOneOrCreate return right object when create one : BookstoreCashier');
 }