public function testFindOneWithUsingInstancePool() { BookstoreDataPopulator::populate(); // instance pool contains all objects by default, since they were just populated $c = new ModelCriteria('bookstore', 'Book'); $c->setFormatter(ModelCriteria::FORMAT_ARRAY); $c->orderBy('Book.Title'); $c->join('Book.Author'); $c->with('Author'); $c->join('Book.Publisher'); $c->with('Publisher'); $this->assertCorrectHydration1($c, 'with instance pool'); }
public function testFindOneWithoutUsingInstancePool() { BookstoreDataPopulator::populate(); Propel::disableInstancePooling(); $c = new ModelCriteria('bookstore', 'Book'); $c->orderBy('Book.Title'); $c->join('Book.Author'); $c->with('Author'); $c->join('Book.Publisher'); $c->with('Publisher'); $this->assertCorrectHydration1($c, 'without instance pool'); Propel::enableInstancePooling(); }
public function testFindOne() { $c = new ModelCriteria('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', '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'); }
public function testFindPksSimpleKey() { BookstoreDataPopulator::depopulate(); BookstoreDataPopulator::populate(); BookPeer::clearInstancePool(); // prepare the test data $c = new ModelCriteria('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'); }
public function testOrderByWithInsensitiveCase() { $sql = 'SELECT FROM ORDER BY book.TITLE ASC'; $params = array(); $c = new ModelCriteria('bookstore', 'Book'); $c->orderBy('Book.title'); $this->assertCriteriaTranslation($c, $sql, $params); $c = new ModelCriteria('bookstore', 'Book'); $c->orderBy('Book.TiTle'); $this->assertCriteriaTranslation($c, $sql, $params); $c = new ModelCriteria('bookstore', 'Book'); $c->orderBy('Book.Title'); $this->assertCriteriaTranslation($c, $sql, $params); $c = new ModelCriteria('bookstore', 'Book'); $c->orderBy('Book.TITLE'); $this->assertCriteriaTranslation($c, $sql, $params); $c = new ModelCriteria('bookstore', 'Book'); $c->orderBy('title'); $this->assertCriteriaTranslation($c, $sql, $params); $c = new ModelCriteria('bookstore', 'Book'); $c->orderBy('Title'); $this->assertCriteriaTranslation($c, $sql, $params); $c = new ModelCriteria('bookstore', 'Book'); $c->orderBy('TITLE'); $this->assertCriteriaTranslation($c, $sql, $params); }
public function testSelectArrayWithColumn() { BookstoreDataPopulator::depopulate($this->con); BookstoreDataPopulator::populate($this->con); $c = new ModelCriteria('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()'); }
public function testSelectArrayWithColumnOrder() { BookstoreDataPopulator::depopulate($this->con); BookstoreDataPopulator::populate($this->con); $c = new ModelCriteria('bookstore', 'Book'); $c->join('Book.Author'); $c->withColumn('LOWER(Book.Title)', 'LowercaseTitle'); $c->withColumn('UPPER(Book.Title)', 'UppercaseTitle'); $c->select(array('Book.ISBN', 'LowercaseTitle', 'Book.Title', 'UppercaseTitle')); $c->orderBy('Book.Title'); $rows = $c->find($this->con); $expectedSQL = 'SELECT book.isbn AS "Book.ISBN", LOWER(book.title) AS LowercaseTitle, book.title AS "Book.Title", UPPER(book.title) AS UppercaseTitle 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('Book.ISBN' => '0140422161', 'LowercaseTitle' => 'don juan', 'Book.Title' => 'Don Juan', 'UppercaseTitle' => 'DON JUAN'), array('Book.ISBN' => '043935806X', 'LowercaseTitle' => 'harry potter and the order of the phoenix', 'Book.Title' => 'Harry Potter and the Order of the Phoenix', 'UppercaseTitle' => 'HARRY POTTER AND THE ORDER OF THE PHOENIX'), array('Book.ISBN' => '0380977427', 'LowercaseTitle' => 'quicksilver', 'Book.Title' => 'Quicksilver', 'UppercaseTitle' => 'QUICKSILVER'), array('Book.ISBN' => '067972575X', 'LowercaseTitle' => 'the tin drum', 'Book.Title' => 'The Tin Drum', 'UppercaseTitle' => 'THE TIN DRUM')); $this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()'); }