From c80ece6e6ff568baa429384d909613b28b5868e9 Mon Sep 17 00:00:00 2001 From: Dirk Wenzel Date: Wed, 2 Sep 2015 15:21:24 +0200 Subject: [PATCH] [BUGFIX] prevent NULL value for limit in EventRepository Closes: #30 --- Classes/Domain/Repository/EventRepository.php | 2 +- .../Unit/Domain/Model/AbstractDemandTest.php | 188 +++++++++--------- 2 files changed, 98 insertions(+), 92 deletions(-) diff --git a/Classes/Domain/Repository/EventRepository.php b/Classes/Domain/Repository/EventRepository.php index edf1f923..9b8e57b7 100644 --- a/Classes/Domain/Repository/EventRepository.php +++ b/Classes/Domain/Repository/EventRepository.php @@ -90,7 +90,7 @@ protected function buildQuery($demand, $respectEnableFields = TRUE){ $query->setOrderings(array($demand->getSortBy() => $sortOrder)); } // limit - if ($demand->getLimit()) { + if ($demand->getLimit() !== NULL) { $query->setLimit($demand->getLimit()); } if ($demand->getStoragePages()) { diff --git a/Tests/Unit/Domain/Model/AbstractDemandTest.php b/Tests/Unit/Domain/Model/AbstractDemandTest.php index 242f537a..7e1e14b7 100644 --- a/Tests/Unit/Domain/Model/AbstractDemandTest.php +++ b/Tests/Unit/Domain/Model/AbstractDemandTest.php @@ -1,51 +1,45 @@ , Agentur Webfox - * Michael Kasten , Agentur Webfox - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + + /*************************************************************** + * Copyright notice + * (c) 2012 Dirk Wenzel , Agentur Webfox + * Michael Kasten , Agentur Webfox + * All rights reserved + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ + +/** + * Test case for class \Webfox\T3events\Domain\Model\Dto\AbstractDemand. * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - /** - * Test case for class \Webfox\T3events\Domain\Model\Dto\AbstractDemand. - * - * @version $Id$ - * @copyright Copyright belongs to the respective authors - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later - * - * @package TYPO3 - * @subpackage Events - * - * @author Dirk Wenzel - * @author Michael Kasten - * @coversDefaultClass \Webfox\T3events\Domain\Model\Dto\AbstractDemand - */ - class AbstractDemandTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { + * @version $Id$ + * @copyright Copyright belongs to the respective authors + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later + * @package TYPO3 + * @subpackage Events + * @author Dirk Wenzel + * @author Michael Kasten + * @coversDefaultClass \Webfox\T3events\Domain\Model\Dto\AbstractDemand + */ +class AbstractDemandTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { + /** * @var \Webfox\T3events\Domain\Model\Dto\AbstractDemand */ protected $fixture; - public function setUp(){ + public function setUp() { $this->fixture = new \Webfox\T3events\Domain\Model\Dto\AbstractDemand(); } @@ -57,7 +51,7 @@ public function tearDown() { * @test * @covers ::getPeriod */ - public function getPeriodReturnsInitialValueForString(){ + public function getPeriodReturnsInitialValueForString() { $this->assertNull($this->fixture->getPeriod()); } @@ -65,11 +59,11 @@ public function getPeriodReturnsInitialValueForString(){ * @test * @covers ::setPeriod */ - public function setPeriodForStringSetsDefaultEmptyString(){ + public function setPeriodForStringSetsDefaultEmptyString() { $this->fixture->setPeriod(); $this->assertSame( - '', - $this->fixture->getPeriod() + '', + $this->fixture->getPeriod() ); } @@ -77,11 +71,11 @@ public function setPeriodForStringSetsDefaultEmptyString(){ * @test * @covers ::setPeriod */ - public function setPeriodForStringSetsPeriod(){ + public function setPeriodForStringSetsPeriod() { $this->fixture->setPeriod('foo'); $this->assertSame( - 'foo', - $this->fixture->getPeriod() + 'foo', + $this->fixture->getPeriod() ); } @@ -89,66 +83,78 @@ public function setPeriodForStringSetsPeriod(){ * @test * @covers ::getLimit */ - public function getLimitReturnsInitialValueForInteger(){ + public function getLimitReturnsInitialValueForInteger() { $this->assertSame(100, $this->fixture->getLimit()); } /** - * @test - * @covers ::setLimit - */ - public function setLimitForIntegerSetsLimit(){ + * @test + * @covers ::setLimit + */ + public function setLimitForIntegerSetsLimit() { $this->fixture->setLimit(3); $this->assertSame(3, $this->fixture->getLimit()); } /** - * @test - * @covers ::getOffset - */ - public function getOffsetReturnsInitialNull(){ + * @test + * @covers ::setLimit + */ + public function setLimitCastsStringToInteger () { + $this->fixture->setLimit('2'); + $this->assertInternalType( + 'int', + $this->fixture->getLimit() + ); + } + + /** + * @test + * @covers ::getOffset + */ + public function getOffsetReturnsInitialNull() { $this->assertNull($this->fixture->getOffset()); } /** - * @test - * @covers ::setOffset - */ - public function setOffsetSetsDefaultValueZeroForInteger(){ + * @test + * @covers ::setOffset + */ + public function setOffsetSetsDefaultValueZeroForInteger() { $this->fixture->setOffset(); $this->assertSame( - 0, - $this->fixture->getOffset()); + 0, + $this->fixture->getOffset()); } /** - * @test - * @covers ::setOffset - */ - public function setOffsetSetsOffsetForInteger(){ + * @test + * @covers ::setOffset + */ + public function setOffsetSetsOffsetForInteger() { $this->fixture->setOffset(99); $this->assertSame( - 99, - $this->fixture->getOffset()); + 99, + $this->fixture->getOffset()); } /** - * @test - * @covers ::getSortDirection - */ - public function getSortDirectionReturnsInitialNull(){ + * @test + * @covers ::getSortDirection + */ + public function getSortDirectionReturnsInitialNull() { $this->assertNull($this->fixture->getSortDirection()); } /** - * @test - * @covers ::setSortDirection - */ - public function setSortDirectionForStringSetsSort(){ + * @test + * @covers ::setSortDirection + */ + public function setSortDirectionForStringSetsSort() { $this->fixture->setSortDirection('baz'); $this->assertSame( - 'baz', - $this->fixture->getSortDirection() + 'baz', + $this->fixture->getSortDirection() ); } @@ -161,14 +167,14 @@ public function getSortByReturnsInitiallyNull() { } /** - * @test - * @covers ::setSortBy - */ + * @test + * @covers ::setSortBy + */ public function setSortByForStringSetsSortBy() { $this->fixture->setSortBy('my.sort.string.with.dots'); $this->assertSame( - 'my.sort.string.with.dots', - $this->fixture->getSortBy() + 'my.sort.string.with.dots', + $this->fixture->getSortBy() ); } @@ -176,7 +182,7 @@ public function setSortByForStringSetsSortBy() { * @test * @covers ::getPeriodType */ - public function getPeriodTypeReturnsInitialNull(){ + public function getPeriodTypeReturnsInitialNull() { $this->assertNull($this->fixture->getPeriodType()); } @@ -185,7 +191,7 @@ public function getPeriodTypeReturnsInitialNull(){ * @covers ::setPeriodType */ public function setPeriodTypeForStringSetsPeriodType() { - $type= 'aType'; + $type = 'aType'; $this->fixture->setPeriodType($type); $this->assertSame($type, $this->fixture->getPeriodType()); } @@ -194,7 +200,7 @@ public function setPeriodTypeForStringSetsPeriodType() { * @test * @covers ::getStoragePages */ - public function getStoragePagesReturnsInitialNull(){ + public function getStoragePagesReturnsInitialNull() { $this->assertNull($this->fixture->getStoragePages()); } @@ -202,7 +208,7 @@ public function getStoragePagesReturnsInitialNull(){ * @test * @covers ::setStoragePages */ - public function setStoragePagesForStringSetsStoragePages(){ + public function setStoragePagesForStringSetsStoragePages() { $this->fixture->setStoragePages('15,78,39'); $this->assertSame('15,78,39', $this->fixture->getStoragePages()); } @@ -263,7 +269,7 @@ public function setStartDateForDateTimeSetsStartDate() { * @test * @covers ::getEndDate */ - public function getEndDateReturnsInitialNull(){ + public function getEndDateReturnsInitialNull() { $this->assertNull($this->fixture->getEndDate()); } @@ -271,7 +277,7 @@ public function getEndDateReturnsInitialNull(){ * @test * @covers ::setEndDate */ - public function setEndDateForDateTimeSetsEndDate(){ + public function setEndDateForDateTimeSetsEndDate() { $date = new \DateTime(); $this->fixture->setEndDate($date); $this->assertSame($date, $this->fixture->getEndDate()); @@ -281,7 +287,7 @@ public function setEndDateForDateTimeSetsEndDate(){ * @test * @covers ::getUidList */ - public function getUidListReturnsInitialNull(){ + public function getUidListReturnsInitialNull() { $this->assertNull($this->fixture->getUidList()); } @@ -289,7 +295,7 @@ public function getUidListReturnsInitialNull(){ * @test * @covers ::setUidList */ - public function setUidListForStringSetsUidList(){ + public function setUidListForStringSetsUidList() { $this->fixture->setUidList('1,3,5'); $this->assertSame('1,3,5', $this->fixture->getUidList()); }