public function testFormat()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     BookstoreEmployeeTableMap::clearInstancePool();
     $stmt = $con->query('SELECT id, class_key, name, job_title, supervisor_id, photo FROM bookstore_employee');
     $formatter = new ObjectFormatter();
     $formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookstoreEmployee'));
     $emps = $formatter->format($stmt);
     $expectedClass = ['b1' => 'Propel\\Tests\\Bookstore\\BookstoreEmployee', 'b2' => 'Propel\\Tests\\Bookstore\\BookstoreManager', 'b3' => 'Propel\\Tests\\Bookstore\\BookstoreCashier'];
     foreach ($emps as $emp) {
         $this->assertEquals($expectedClass[$emp->getName()], get_class($emp), 'format() creates objects of the correct class when using inheritance');
     }
 }
 public function testFindOneWithRelationName()
 {
     BookstoreDataPopulator::populate();
     BookstoreEmployeeTableMap::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');
     $c->limit(1);
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $emps = $c->find($con);
     foreach ($emps as $emp) {
         break;
     }
     $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');
 }
 /**
  * Test foreign key relationships based on references to unique cols but not PK.
  * @link       http://propel.phpdb.org/trac/ticket/691
  */
 public function testUniqueFkRel()
 {
     BookstoreEmployeeAccountTableMap::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();
     BookstoreEmployeeTableMap::clearInstancePool();
     BookstoreEmployeeAccountTableMap::clearInstancePool();
     AcctAuditLogTableMap::clearInstancePool();
     $al2 = AcctAuditLogQuery::create()->findPk($alId);
     /* @var $al2 AcctAuditLog */
     $mapacct = $al2->getBookstoreEmployeeAccount();
     $lookupacct = BookstoreEmployeeAccountQuery::create()->findPk($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();
     BookstoreEmployeeTableMap::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');
 }
 public function testGetRelation()
 {
     $bookTable = BookTableMap::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 = BookstoreEmployeeTableMap::getTableMap();
     $supervisorColumn = $bookstoreTable->getColumn('SUPERVISOR_ID');
     $this->assertEquals($supervisorColumn->getRelation(), $supervisorColumn->getRelation('Supervisor'), 'getRelation() returns the RelationMap object even whit ha specific refPhpName');
 }
 /**
  * Test hydration of joined rows that contain lazy load columns.
  * @link       http://propel.phpdb.org/trac/ticket/464
  */
 public function testHydrationJoinLazyLoad()
 {
     BookstoreEmployeeAccountTableMap::doDeleteAll();
     BookstoreEmployeeTableMap::doDeleteAll();
     AcctAccessRoleTableMap::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();
     $results = BookstoreEmployeeAccountQuery::create()->find();
     $o = $results[0];
     $this->assertEquals('Admin', $o->getAcctAccessRole()->getName());
 }