Skip to content

Commit

Permalink
Merge pull request mautic#7853 from Webmecanik/fix-relative-date-to-a…
Browse files Browse the repository at this point in the history
…nniversary

Fix relative date support to anniversary
  • Loading branch information
dennisameling authored Mar 11, 2020
2 parents 77562cd + 26273fb commit 584ce0f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function getDateOption(ContactSegmentFilterCrate $leadSegmentFilterCrate)
switch ($timeframe) {
case 'birthday':
case 'anniversary':
case $timeframe && (
false !== strpos($timeframe, 'anniversary') ||
false !== strpos($timeframe, 'birthday')
):
return new DateAnniversary($this->dateDecorator, $dateOptionParameters);
case 'today':
return new DateDayToday($this->dateDecorator, $dateOptionParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ public function getParameterHolder(ContactSegmentFilterCrate $contactSegmentFilt
*/
public function getParameterValue(ContactSegmentFilterCrate $contactSegmentFilterCrate)
{
$dateTimeHelper = $this->dateOptionParameters->getDefaultDate();
$date = $this->dateOptionParameters->getDefaultDate();
$filter = $contactSegmentFilterCrate->getFilter();
$relativeFilter = trim(str_replace(['anniversary', 'birthday'], '', $filter));

return $dateTimeHelper->toLocalString('%-m-d');
if ($relativeFilter) {
$date->modify($relativeFilter);
}

return $date->toLocalString('%-m-d');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testBirthday()

$this->assertInstanceOf(DateAnniversary::class, $filterDecorator);

$filterName = 'birthday';
$filterName = 'anniversary';

$filterDecorator = $this->getFilterDecorator($filterName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,34 @@ public function testGetParameterValue()

$this->assertEquals('%-03-02', $filterDecorator->getParameterValue($contactSegmentFilterCrate));
}

/**
* @covers \Mautic\LeadBundle\Segment\Decorator\Date\Other\DateAnniversary::getParameterValue
*/
public function testGetParameterValueWithRelativeDate()
{
$dateDecorator = $this->createMock(DateDecorator::class);
$timezoneResolver = $this->createMock(TimezoneResolver::class);

$date = new DateTimeHelper('2018-03-02', null, 'local');

$timezoneResolver->method('getDefaultDate')
->with()
->willReturn($date);

$filter = [
'operator' => '=',
];
$contactSegmentFilterCrate = new ContactSegmentFilterCrate($filter);
$dateOptionParameters = new DateOptionParameters($contactSegmentFilterCrate, [], $timezoneResolver);

$filter = [
'filter' => 'birthday +2days',
];
$contactSegmentFilterCrate = new ContactSegmentFilterCrate($filter);

$filterDecorator = new DateAnniversary($dateDecorator, $dateOptionParameters);

$this->assertEquals('%-03-04', $filterDecorator->getParameterValue($contactSegmentFilterCrate));
}
}

0 comments on commit 584ce0f

Please sign in to comment.