diff --git a/src/Propel/Runtime/ActiveQuery/Criteria.php b/src/Propel/Runtime/ActiveQuery/Criteria.php index 1b64ce5f15..59079994f6 100644 --- a/src/Propel/Runtime/ActiveQuery/Criteria.php +++ b/src/Propel/Runtime/ActiveQuery/Criteria.php @@ -1259,8 +1259,7 @@ public function isSingleRecord() */ public function setLimit($limit) { - // TODO: do we enforce int here? 32bit issue if we do - $this->limit = $limit; + $this->limit = (int) $limit; return $this; } @@ -1278,8 +1277,7 @@ public function getLimit() /** * Set offset. * - * @param int $offset An int with the value for offset. (Note this values is - * cast to a 32bit integer and may result in truncation) + * @param int $offset An int with the value for offset. * @return $this|Criteria Modified Criteria object (for fluent API) */ public function setOffset($offset) diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaTest.php index 11824f689d..4854498174 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/CriteriaTest.php @@ -1064,16 +1064,160 @@ public function testClear() $this->assertFalse($c->getUseTransaction(), 'useTransaction is false by default'); } - public function testLimit() + public function testDefaultLimit() { $c = new Criteria(); $this->assertEquals(-1, $c->getLimit(), 'Limit is -1 by default'); + } + + /** + * @dataProvider dataLimit + */ + public function testLimit($limit, $expected) + { + $c = new Criteria(); + $c2 = $c->setLimit($limit); - $c2 = $c->setLimit(1); - $this->assertEquals(1, $c->getLimit(), 'Limit is set by setLimit'); + $this->assertSame($expected, $c->getLimit(), 'Correct limit is set by setLimit()'); $this->assertSame($c, $c2, 'setLimit() returns the current Criteria'); } + public function dataLimit() + { + return array( + 'Negative value' => array( + 'limit' => -1, + 'expected' => -1 + ), + 'Zero' => array( + 'limit' => 0, + 'expected' => 0 + ), + + 'Small integer' => array( + 'limit' => 38427, + 'expected' => 38427 + ), + 'Small integer as a string' => array( + 'limit' => '38427', + 'expected' => 38427 + ), + + 'Largest 32-bit integer' => array( + 'limit' => 2147483647, + 'expected' => 2147483647 + ), + 'Largest 32-bit integer as a string' => array( + 'limit' => '2147483647', + 'expected' => 2147483647 + ), + + 'Largest 64-bit integer' => array( + 'limit' => 9223372036854775807, + 'expected' => 9223372036854775807 + ), + 'Largest 64-bit integer as a string' => array( + 'limit' => '9223372036854775807', + 'expected' => 9223372036854775807 + ), + + 'Decimal value' => array( + 'limit' => 123.9, + 'expected' => 123 + ), + 'Decimal value as a string' => array( + 'limit' => '123.9', + 'expected' => 123 + ), + + 'Non-numeric string' => array( + 'limit' => 'foo', + 'expected' => 0 + ), + 'Injected SQL' => array( + 'limit' => '3;DROP TABLE abc', + 'expected' => 3 + ), + ); + } + + public function testDefaultOffset() + { + $c = new Criteria(); + $this->assertEquals(0, $c->getOffset(), 'Offset is 0 by default'); + } + + /** + * @dataProvider dataOffset + */ + public function testOffset($offset, $expected) + { + $c = new Criteria(); + $c2 = $c->setOffset($offset); + + $this->assertSame($expected, $c->getOffset(), 'Correct offset is set by setOffset()'); + $this->assertSame($c, $c2, 'setOffset() returns the current Criteria'); + } + + public function dataOffset() + { + return array( + 'Negative value' => array( + 'offset' => -1, + 'expected' => -1 + ), + 'Zero' => array( + 'offset' => 0, + 'expected' => 0 + ), + + 'Small integer' => array( + 'offset' => 38427, + 'expected' => 38427 + ), + 'Small integer as a string' => array( + 'offset' => '38427', + 'expected' => 38427 + ), + + 'Largest 32-bit integer' => array( + 'offset' => 2147483647, + 'expected' => 2147483647 + ), + 'Largest 32-bit integer as a string' => array( + 'offset' => '2147483647', + 'expected' => 2147483647 + ), + + 'Largest 64-bit integer' => array( + 'offset' => 9223372036854775807, + 'expected' => 9223372036854775807 + ), + 'Largest 64-bit integer as a string' => array( + 'offset' => '9223372036854775807', + 'expected' => 9223372036854775807 + ), + + 'Decimal value' => array( + 'offset' => 123.9, + 'expected' => 123 + ), + 'Decimal value as a string' => array( + 'offset' => '123.9', + 'expected' => 123 + ), + + 'Non-numeric string' => array( + 'offset' => 'foo', + 'expected' => 0 + ), + 'Injected SQL' => array( + 'offset' => '3;DROP TABLE abc', + 'expected' => 3 + ), + ); + } + public function testCombineAndFilterBy() { $params = [];