From 6be021a81c478e28d95bc0a58cd903f50ff70275 Mon Sep 17 00:00:00 2001 From: Dirk Wenzel Date: Tue, 11 Sep 2018 13:45:32 +0200 Subject: [PATCH 1/2] [BUGFIX] fixed error in PeriodAwareDemandFactoryTrait caused by invalid argument for DateTime constructor --- .../Dto/PeriodAwareDemandFactoryTrait.php | 33 ++++++-- .../Dto/PeriodAwareDemandFactoryTraitTest.php | 78 ++++++++++++++++++- 2 files changed, 102 insertions(+), 9 deletions(-) diff --git a/Classes/Domain/Factory/Dto/PeriodAwareDemandFactoryTrait.php b/Classes/Domain/Factory/Dto/PeriodAwareDemandFactoryTrait.php index 2c762290..4a5eadd8 100644 --- a/Classes/Domain/Factory/Dto/PeriodAwareDemandFactoryTrait.php +++ b/Classes/Domain/Factory/Dto/PeriodAwareDemandFactoryTrait.php @@ -24,9 +24,9 @@ public function setPeriodConstraints(PeriodAwareDemandInterface $demand, $settin if ($settings['period'] === 'futureOnly' || $settings['period'] === 'pastOnly' ) { - $startDate = new \DateTime('midnight', $timeZone); - $demand->setStartDate($startDate); - $demand->setDate($startDate); + $periodStartDate = new \DateTime('midnight', $timeZone); + $demand->setStartDate($periodStartDate); + $demand->setDate($periodStartDate); } if ($settings['period'] === 'specific') { @@ -40,16 +40,35 @@ public function setPeriodConstraints(PeriodAwareDemandInterface $demand, $settin isset($settings['periodType']) && $settings['periodType'] === 'byDate' ) { - if ($settings['periodStartDate']) { + + if (!empty($settings['periodStartDate'])) { $demand->setStartDate( - new \DateTime($settings['periodStartDate'], $timeZone) + $this->createDate($settings['periodStartDate']) ); } - if ($settings['periodEndDate']) { + if (!empty($settings['periodEndDate'])) { $demand->setEndDate( - new \DateTime($settings['periodEndDate'], $timeZone) + $this->createDate($settings['periodEndDate']) ); } } } + + /** + * Helper method. Creates a date object from + * integers and strings. + * @param $value + * @return \DateTime + */ + protected function createDate($value) { + $timeZone = new \DateTimeZone(date_default_timezone_get()); + if (is_numeric($value)) { + $dateTime = new \DateTime('midnight', $timeZone); + $dateTime->setTimestamp((int)$value); + } else { + $dateTime = new \DateTime($value, $timeZone); + } + + return $dateTime; + } } diff --git a/Tests/Unit/Domain/Factory/Dto/PeriodAwareDemandFactoryTraitTest.php b/Tests/Unit/Domain/Factory/Dto/PeriodAwareDemandFactoryTraitTest.php index d3feb5bf..4a26bc55 100644 --- a/Tests/Unit/Domain/Factory/Dto/PeriodAwareDemandFactoryTraitTest.php +++ b/Tests/Unit/Domain/Factory/Dto/PeriodAwareDemandFactoryTraitTest.php @@ -47,6 +47,32 @@ public function setUp() * @return array */ public function startDateDataProvider(): array + { + $timeZone = new \DateTimeZone(date_default_timezone_get()); + $defaultDate = new \DateTime('midnight', $timeZone); + + $specificDateString = '1536656550'; + $specificDate = clone $defaultDate; + $specificDate->setTimestamp((int)$specificDateString); + + return [ + [ + ['period' => 'futureOnly'], + $defaultDate + ], + [ + ['period' => 'pastOnly'], + $defaultDate + ] + ]; + } + + /** + * Returns parameters for date test + * + * @return array + */ + public function dateDataProvider(): array { $timeZone = new \DateTimeZone(date_default_timezone_get()); $startDate = new \DateTime('midnight', $timeZone); @@ -82,7 +108,7 @@ public function setPeriodConstraintsSetsStartDate($settings, $startDate) /** * @test - * @dataProvider startDateDataProvider + * @dataProvider dateDataProvider * @param array $settings * @param \DateTime $startDate */ @@ -103,7 +129,55 @@ public function setPeriodConstraintsSetsDate($settings, $startDate) protected function getMockPeriodAwareDemand() { /** @var PeriodAwareDemandInterface|MockObject $mockDemand */ - $mockDemand = $this->getMockBuilder(PeriodAwareDemandInterface::class)->getMock(); + $mockDemand = $this->getMockBuilder(PeriodAwareDemandInterface::class) + ->getMock(); return $mockDemand; } + + /** + * @test + */ + public function setPeriodConstraintsSetsStartDateForPeriodTypeByDate() + { + $specificDateString = '1536656550'; + $timeZone = new \DateTimeZone(date_default_timezone_get()); + $specificDate = new \DateTime('midnight', $timeZone); + + $specificDate->setTimestamp((int)$specificDateString); + $settings = [ + 'period' => 'specific', + 'periodType' => 'byDate', + 'periodStartDate' => $specificDateString + ]; + + $mockDemand = $this->getMockPeriodAwareDemand(); + $mockDemand->expects($this->once()) + ->method('setStartDate') + ->with($specificDate); + $this->subject->setPeriodConstraints($mockDemand, $settings); + + } + + /** + * @test + */ + public function setPeriodConstraintsSetsEndDateForPeriodTypeByDate() + { + $specificDateString = '1536656550'; + $timeZone = new \DateTimeZone(date_default_timezone_get()); + $specificDate = new \DateTime('midnight', $timeZone); + + $specificDate->setTimestamp((int)$specificDateString); + $settings = [ + 'period' => 'specific', + 'periodType' => 'byDate', + 'periodEndDate' => $specificDateString + ]; + + $mockDemand = $this->getMockPeriodAwareDemand(); + $mockDemand->expects($this->once()) + ->method('setEndDate') + ->with($specificDate); + $this->subject->setPeriodConstraints($mockDemand, $settings); + } } From cecbde26b36065688943e5305b0069c226fc73a9 Mon Sep 17 00:00:00 2001 From: Dirk Wenzel Date: Tue, 11 Sep 2018 13:59:40 +0200 Subject: [PATCH 2/2] [RELEASE] Release of t3events 0.40.1 (Dirk Wenzel) --- ChangeLog | 3 +++ ext_emconf.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ffff457b..b8bfe5e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-09-11 [RELEASE] Release of t3events 0.40.1 (Dirk Wenzel) +2018-09-11 6be021a [BUGFIX] fixed error in PeriodAwareDemandFactoryTrait caused by invalid argument for DateTime constructor (Dirk Wenzel) + 2018-07-06 [RELEASE] Release of t3events 0.40.0 (Dirk Wenzel) 2018-07-06 7841ba3 [BUGFIX] fixed error caused by missing settings in backend controllers. Parent class ActionController now implements method injectConfigurationManager and fetches the settings there. Therefore we can not use our own implementation anymore. BackendControllers now provide the configuration manager via getter method. (Dirk Wenzel) 2018-07-01 c4ba04d [TASK] constants added to PeriodConstraintRepositoryInterface and SettingsInterfacea (Dirk Wenzel) diff --git a/ext_emconf.php b/ext_emconf.php index eb1587b7..303f28c3 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -14,7 +14,7 @@ 'title' => 'Events', 'description' => 'Manage events, show teasers, list and single views.', 'category' => 'plugin', - 'version' => '0.40.0', + 'version' => '0.40.1', 'state' => 'beta', 'uploadfolder' => 1, 'createDirs' => '',