Skip to content

Commit

Permalink
Merge branch 'hotfix/0.40.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dwenzel committed Sep 11, 2018
2 parents 01b5903 + cecbde2 commit e6b07a0
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
33 changes: 26 additions & 7 deletions Classes/Domain/Factory/Dto/PeriodAwareDemandFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -82,7 +108,7 @@ public function setPeriodConstraintsSetsStartDate($settings, $startDate)

/**
* @test
* @dataProvider startDateDataProvider
* @dataProvider dateDataProvider
* @param array $settings
* @param \DateTime $startDate
*/
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down

0 comments on commit e6b07a0

Please sign in to comment.