Permalink
Browse files

Add unit tests for paginate() used together with select()

Refs #257.
  • Loading branch information...
1 parent 209e34d commit f216a1a76f9045a03cb543d4485cc302b6d5b5e7 @fzaninotto fzaninotto committed Feb 13, 2012
@@ -365,6 +365,20 @@ public function testSelectArrayWithColumn()
$this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
}
+ public function testSelectArrayPaginate()
+ {
+ BookstoreDataPopulator::depopulate($this->con);
+ BookstoreDataPopulator::populate($this->con);
+
+ $pager = BookQuery::create()
+ ->select(array('Id', 'Title', 'ISBN', 'Price'))
+ ->paginate(1, 10, $this->con);
+ $this->assertInstanceOf('PropelModelPager', $pager);
+ foreach ($pager as $result) {
+ $this->assertEquals(array('Id', 'Title', 'ISBN', 'Price'), array_keys($result));
+ }
+ }
+
public function testGetSelectReturnsNullByDefault()
{
$c = new ModelCriteria('bookstore', 'Book');
@@ -2387,7 +2387,7 @@ public function testAddUsingAliasTrueAliasTwice()
$this->assertEquals($c2, $c1, 'addUsingalias() translates to addAnd() when the table already has a condition on the column');
}
- public function testClone()
+ public function testCloneCopiesConditions()
{
$bookQuery1 = BookQuery::create()
->filterByPrice(1);
@@ -2398,6 +2398,28 @@ public function testClone()
$sql = BasePeer::createSelectSql($bookQuery1, $params);
$this->assertEquals('SELECT FROM `book` WHERE book.PRICE=:p1', $sql, 'conditions applied on a cloned query don\'t get applied on the original query');
}
+
+ public function testCloneCopiesFormatter()
+ {
+ $formatter1 = new PropelArrayFormatter();
+ $formatter1->test = false;
+ $bookQuery1 = BookQuery::create();
+ $bookQuery1->setFormatter($formatter1);
+ $bookQuery2 = clone $bookQuery1;
+ $formatter2 = $bookQuery2->getFormatter();
+ $this->assertFalse($formatter2->test);
+ $formatter2->test = true;
+ $this->assertFalse($formatter1->test);
+ }
+
+ public function testCloneCopiesSelect()
+ {
+ $bookQuery1 = BookQuery::create();
+ $bookQuery1->select(array('Id', 'Title'));
+ $bookQuery2 = clone $bookQuery1;
+ $bookQuery2->select(array('ISBN', 'Price'));
+ $this->assertEquals(array('Id', 'Title'), $bookQuery1->getSelect());
+ }
}
class TestableModelCriteria extends ModelCriteria

0 comments on commit f216a1a

Please sign in to comment.