Esempio n. 1
0
 public function testFindOneWithUsingInstancePool()
 {
     BookstoreDataPopulator::populate();
     // instance pool contains all objects by default, since they were just populated
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->orderBy('Propel\\Tests\\Bookstore\\Book.Title');
     $c->join('Propel\\Tests\\Bookstore\\Book.Author');
     $c->with('Author');
     $c->join('Propel\\Tests\\Bookstore\\Book.Publisher');
     $c->with('Publisher');
     $this->assertCorrectHydration1($c, 'with instance pool');
 }
 public function testSelectArrayWithColumn()
 {
     BookstoreDataPopulator::depopulate($this->con);
     BookstoreDataPopulator::populate($this->con);
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $c->join('Book.Author');
     $c->withColumn('LOWER(Book.Title)', 'LowercaseTitle');
     $c->select(array('LowercaseTitle', 'Book.Title'));
     $c->orderBy('Book.Title');
     $rows = $c->find($this->con);
     $expectedSQL = 'SELECT LOWER(book.TITLE) AS LowercaseTitle, book.TITLE AS "Book.Title" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) ORDER BY book.TITLE ASC';
     $this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) can cope with a column added with withColumn()');
     $expectedRows = array(array('LowercaseTitle' => 'don juan', 'Book.Title' => 'Don Juan'), array('LowercaseTitle' => 'harry potter and the order of the phoenix', 'Book.Title' => 'Harry Potter and the Order of the Phoenix'), array('LowercaseTitle' => 'quicksilver', 'Book.Title' => 'Quicksilver'), array('LowercaseTitle' => 'the tin drum', 'Book.Title' => 'The Tin Drum'));
     $this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
 }
Esempio n. 3
0
 public function testFindOneWithoutUsingInstancePool()
 {
     BookstoreDataPopulator::populate();
     Propel::disableInstancePooling();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $c->orderBy('Propel\\Tests\\Bookstore\\Book.Title');
     $c->join('Propel\\Tests\\Bookstore\\Book.Author');
     $c->with('Author');
     $c->join('Propel\\Tests\\Bookstore\\Book.Publisher');
     $c->with('Publisher');
     $this->assertCorrectHydration1($c, 'without instance pool');
     Propel::enableInstancePooling();
 }
Esempio n. 4
0
 public function testFindPksSimpleKey()
 {
     BookstoreDataPopulator::depopulate();
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     // prepare the test data
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $c->orderBy('Book.Id', 'desc');
     $testBooks = $c->find();
     $testBook1 = $testBooks->pop();
     $testBook2 = $testBooks->pop();
     $q = new BookQuery();
     $books = $q->findPks(array($testBook1->getId(), $testBook2->getId()));
     $this->assertEquals(array($testBook1, $testBook2), $books->getData(), 'BaseQuery overrides findPks() to make it faster');
 }
Esempio n. 5
0
 public function testFindOne()
 {
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
     $c->where('b.Title = ?', 'foo');
     $book = $c->findOne();
     $this->assertNull($book, 'findOne() returns null when the query returns no result');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
     $c->orderBy('b.Title');
     $book = $c->findOne();
     $this->assertTrue($book instanceof Book, 'findOne() returns a Model object by default');
     $this->assertEquals('Don Juan', $book->getTitle(), 'find() returns the model objects matching the query');
 }