From 7ee2a4d0bae98de84c62294778f3ecb6ba9dbd5d Mon Sep 17 00:00:00 2001 From: Enc3phale Date: Fri, 6 Sep 2019 09:56:49 +0200 Subject: [PATCH 1/3] Fix relative birthday date --- .../Segment/Decorator/Date/DateOptionFactory.php | 4 ++++ .../Segment/Decorator/Date/Other/DateAnniversary.php | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/bundles/LeadBundle/Segment/Decorator/Date/DateOptionFactory.php b/app/bundles/LeadBundle/Segment/Decorator/Date/DateOptionFactory.php index a443610dada..ed8b654309c 100644 --- a/app/bundles/LeadBundle/Segment/Decorator/Date/DateOptionFactory.php +++ b/app/bundles/LeadBundle/Segment/Decorator/Date/DateOptionFactory.php @@ -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); diff --git a/app/bundles/LeadBundle/Segment/Decorator/Date/Other/DateAnniversary.php b/app/bundles/LeadBundle/Segment/Decorator/Date/Other/DateAnniversary.php index c0b3edaa873..265775aa37e 100644 --- a/app/bundles/LeadBundle/Segment/Decorator/Date/Other/DateAnniversary.php +++ b/app/bundles/LeadBundle/Segment/Decorator/Date/Other/DateAnniversary.php @@ -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'); } /** From ba643acf02fb8ded86c74013c805bd4367eea954 Mon Sep 17 00:00:00 2001 From: Enc3phale Date: Fri, 6 Sep 2019 09:57:21 +0200 Subject: [PATCH 2/3] Fix wrong TU --- .../Tests/Segment/Decorator/Date/DateOptionFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/bundles/LeadBundle/Tests/Segment/Decorator/Date/DateOptionFactoryTest.php b/app/bundles/LeadBundle/Tests/Segment/Decorator/Date/DateOptionFactoryTest.php index 42f86491837..7bfefbc97d0 100644 --- a/app/bundles/LeadBundle/Tests/Segment/Decorator/Date/DateOptionFactoryTest.php +++ b/app/bundles/LeadBundle/Tests/Segment/Decorator/Date/DateOptionFactoryTest.php @@ -45,7 +45,7 @@ public function testBirthday() $this->assertInstanceOf(DateAnniversary::class, $filterDecorator); - $filterName = 'birthday'; + $filterName = 'anniversary'; $filterDecorator = $this->getFilterDecorator($filterName); From 26273fbba95fa3b230aaf60e7f906f34e8df2d07 Mon Sep 17 00:00:00 2001 From: Enc3phale Date: Fri, 6 Sep 2019 10:17:43 +0200 Subject: [PATCH 3/3] Add TU --- .../Date/Other/DateAnniversaryTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/bundles/LeadBundle/Tests/Segment/Decorator/Date/Other/DateAnniversaryTest.php b/app/bundles/LeadBundle/Tests/Segment/Decorator/Date/Other/DateAnniversaryTest.php index f5579a8c334..2c94061eba6 100644 --- a/app/bundles/LeadBundle/Tests/Segment/Decorator/Date/Other/DateAnniversaryTest.php +++ b/app/bundles/LeadBundle/Tests/Segment/Decorator/Date/Other/DateAnniversaryTest.php @@ -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)); + } }