public function testFormat()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     BookstoreEmployeePeer::clearInstancePool();
     $stmt = $con->query('SELECT * FROM bookstore_employee');
     $formatter = new PropelObjectFormatter();
     $formatter->init(new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\BookstoreEmployee'));
     $emps = $formatter->format($stmt);
     $expectedClass = array('b1' => 'BookstoreEmployee', 'b2' => 'BookstoreManager', 'b3' => 'BookstoreCashier');
     foreach ($emps as $emp) {
         $this->assertEquals($expectedClass[$emp->getName()], get_class($emp), 'format() creates objects of the correct class when using inheritance');
     }
 }
 /**
  * Test copyInto method.
  */
 public function testCopyInto_Deep()
 {
     BookstoreDataPopulator::populate();
     // Test a "normal" object
     $c = new Criteria();
     $c->add(BookPeer::TITLE, 'Harry%', Criteria::LIKE);
     $book = BookPeer::doSelectOne($c);
     $reviews = $book->getReviews();
     $b2 = $book->copy(true);
     $this->assertInstanceOf('\\Propel\\Tests\\Bookstore\\Book', $b2);
     $this->assertNull($b2->getId());
     $r2 = $b2->getReviews();
     $this->assertEquals(count($reviews), count($r2));
     // Test a one-to-one object
     $emp = BookstoreEmployeePeer::doSelectOne(new Criteria());
     $e2 = $emp->copy(true);
     $this->assertInstanceOf('\\Propel\\Tests\\Bookstore\\BookstoreEmployee', $e2);
     $this->assertNull($e2->getId());
     $this->assertEquals($emp->getBookstoreEmployeeAccount()->getLogin(), $e2->getBookstoreEmployeeAccount()->getLogin());
 }
 public function testFindOneWithRelationName()
 {
     BookstoreDataPopulator::populate();
     BookstoreEmployeePeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookstoreEmployee');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->join('Propel\\Tests\\Bookstore\\BookstoreEmployee.Supervisor s');
     $c->with('s');
     $c->where('s.Name = ?', 'John');
     $emp = $c->findOne();
     $this->assertEquals($emp['Name'], 'Pieter', 'Main object is correctly hydrated');
     $sup = $emp['Supervisor'];
     $this->assertEquals($sup['Name'], 'John', 'Related object is correctly hydrated');
 }
Beispiel #4
0
 public function testGetRelation()
 {
     $bookTable = BookPeer::getTableMap();
     $titleColumn = $bookTable->getColumn('TITLE');
     $this->assertNull($titleColumn->getRelation(), 'getRelation() returns null for non-foreign key columns');
     $publisherColumn = $bookTable->getColumn('PUBLISHER_ID');
     $this->assertEquals($publisherColumn->getRelation(), $bookTable->getRelation('Publisher'), 'getRelation() returns the RelationMap object for this foreign key');
     $bookstoreTable = BookstoreEmployeePeer::getTableMap();
     $supervisorColumn = $bookstoreTable->getColumn('SUPERVISOR_ID');
     $this->assertEquals($supervisorColumn->getRelation(), $supervisorColumn->getRelation('Supervisor'), 'getRelation() returns the RelationMap object even whit ha specific refPhpName');
 }
Beispiel #5
0
 /**
  * Test foreign key relationships based on references to unique cols but not PK.
  * @link       http://propel.phpdb.org/trac/ticket/691
  */
 public function testUniqueFkRel()
 {
     BookstoreEmployeeAccountPeer::doDeleteAll();
     $employee = new BookstoreEmployee();
     $employee->setName("Johnny Walker");
     $acct = new BookstoreEmployeeAccount();
     $acct->setBookstoreEmployee($employee);
     $acct->setLogin("test-login");
     $acct->save();
     $acctId = $acct->getEmployeeId();
     $al = new AcctAuditLog();
     $al->setBookstoreEmployeeAccount($acct);
     $al->save();
     $alId = $al->getId();
     BookstoreEmployeePeer::clearInstancePool();
     BookstoreEmployeeAccountPeer::clearInstancePool();
     AcctAuditLogPeer::clearInstancePool();
     $al2 = AcctAuditLogPeer::retrieveByPK($alId);
     /* @var $al2 AcctAuditLog */
     $mapacct = $al2->getBookstoreEmployeeAccount();
     $lookupacct = BookstoreEmployeeAccountPeer::retrieveByPK($acctId);
     $logs = $lookupacct->getAcctAuditLogs();
     $this->assertTrue(count($logs) == 1, "Expected 1 audit log result.");
     $this->assertEquals($logs[0]->getId(), $al->getId(), "Expected returned audit log to match created audit log.");
 }
 public function testFindOneWithRelationName()
 {
     BookstoreDataPopulator::populate();
     BookstoreEmployeePeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookstoreEmployee');
     $c->join('Propel\\Tests\\Bookstore\\BookstoreEmployee.Supervisor s');
     $c->with('s');
     $c->where('s.Name = ?', 'John');
     $con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
     $emp = $c->findOne($con);
     $count = $con->getQueryCount();
     $this->assertEquals($emp->getName(), 'Pieter', 'Main object is correctly hydrated');
     $sup = $emp->getSupervisor();
     $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query');
     $this->assertEquals($sup->getName(), 'John', 'Related object is correctly hydrated');
 }
Beispiel #7
0
 public function testJoinAliasQuery()
 {
     $con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
     $c->join('b.Author a');
     $c->where('a.FirstName = ?', 'Leo');
     $books = BookPeer::doSelect($c, $con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` INNER JOIN `author` `a` ON (book.AUTHOR_ID=a.ID) WHERE a.FIRST_NAME = 'Leo'";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'join() allows the use of relation alias in where()');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookstoreEmployee', 'be');
     $c->join('be.Supervisor sup');
     $c->join('sup.Subordinate sub');
     $c->where('sub.Name = ?', 'Foo');
     $employees = BookstoreEmployeePeer::doSelect($c, $con);
     $expectedSQL = "SELECT bookstore_employee.ID, bookstore_employee.CLASS_KEY, bookstore_employee.NAME, bookstore_employee.JOB_TITLE, bookstore_employee.SUPERVISOR_ID FROM `bookstore_employee` INNER JOIN `bookstore_employee` `sup` ON (bookstore_employee.SUPERVISOR_ID=sup.ID) INNER JOIN `bookstore_employee` `sub` ON (sup.ID=sub.SUPERVISOR_ID) WHERE sub.NAME = 'Foo'";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'join() allows the use of relation alias in further joins()');
 }
 /**
  * Test hydration of joined rows that contain lazy load columns.
  * @link       http://propel.phpdb.org/trac/ticket/464
  */
 public function testHydrationJoinLazyLoad()
 {
     BookstoreEmployeeAccountPeer::doDeleteAll();
     BookstoreEmployeePeer::doDeleteAll();
     AcctAccessRolePeer::doDeleteAll();
     $bemp2 = new BookstoreEmployee();
     $bemp2->setName("Pieter");
     $bemp2->setJobTitle("Clerk");
     $bemp2->save();
     $role = new AcctAccessRole();
     $role->setName("Admin");
     $bempacct = new BookstoreEmployeeAccount();
     $bempacct->setBookstoreEmployee($bemp2);
     $bempacct->setAcctAccessRole($role);
     $bempacct->setLogin("john");
     $bempacct->setPassword("johnp4ss");
     $bempacct->save();
     $c = new Criteria();
     $results = BookstoreEmployeeAccountPeer::doSelectJoinAll($c);
     $o = $results[0];
     $this->assertEquals('Admin', $o->getAcctAccessRole()->getName());
 }