Skip to content

Commit

Permalink
Less strict property validation #1887
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle authored and bastianallgeier committed Oct 7, 2019
1 parent f8ea132 commit c712ef0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
12 changes: 6 additions & 6 deletions src/Toolkit/Pagination.php
Expand Up @@ -386,27 +386,27 @@ public function rangeEnd(int $range = 5): int
public function setProperties(array $params)
{
if (isset($params['limit'])) {
if (is_int($params['limit']) !== true || $params['limit'] < 1) {
if (is_numeric($params['limit']) !== true || $params['limit'] < 1) {
throw new Exception('Invalid pagination limit: ' . $params['limit']);
}

$this->limit = $params['limit'];
$this->limit = (int)$params['limit'];
}

if (isset($params['total'])) {
if (is_int($params['total']) !== true || $params['total'] < 0) {
if (is_numeric($params['total']) !== true || $params['total'] < 0) {
throw new Exception('Invalid total number of items: ' . $params['total']);
}

$this->total = $params['total'];
$this->total = (int)$params['total'];
}

if (isset($params['page'])) {
if (is_int($params['page']) !== true || $params['page'] < 0) {
if (is_numeric($params['page']) !== true || $params['page'] < 0) {
throw new Exception('Invalid page number: ' . $params['page']);
}

$this->page = $params['page'];
$this->page = (int)$params['page'];
} elseif ($this->page === null) {
// generate "default page" based on other params if not set already
$this->page = $this->firstPage();
Expand Down
29 changes: 1 addition & 28 deletions tests/Toolkit/PaginationTest.php
Expand Up @@ -303,15 +303,6 @@ public function testSetPropertiesInvalid1()
}

public function testSetPropertiesInvalid2()
{
$this->expectException('Kirby\Exception\Exception');
$this->expectExceptionMessage('Invalid pagination limit: 1');

$pagination = new Pagination();
$pagination->setProperties(['limit' => '1']);
}

public function testSetPropertiesInvalid3()
{
$this->expectException('Kirby\Exception\Exception');
$this->expectExceptionMessage('Invalid total number of items: -1');
Expand All @@ -320,16 +311,7 @@ public function testSetPropertiesInvalid3()
$pagination->setProperties(['total' => -1]);
}

public function testSetPropertiesInvalid4()
{
$this->expectException('Kirby\Exception\Exception');
$this->expectExceptionMessage('Invalid total number of items: 1');

$pagination = new Pagination();
$pagination->setProperties(['total' => '1']);
}

public function testSetPropertiesInvalid5()
public function testSetPropertiesInvalid3()
{
$this->expectException('Kirby\Exception\Exception');
$this->expectExceptionMessage('Invalid page number: -1');
Expand All @@ -338,15 +320,6 @@ public function testSetPropertiesInvalid5()
$pagination->setProperties(['page' => -1]);
}

public function testSetPropertiesInvalid6()
{
$this->expectException('Kirby\Exception\Exception');
$this->expectExceptionMessage('Invalid page number: 1');

$pagination = new Pagination();
$pagination->setProperties(['page' => '1']);
}

public function testSetPropertiesOutOfBounds1()
{
$this->expectException('Kirby\Exception\ErrorPageException');
Expand Down

0 comments on commit c712ef0

Please sign in to comment.