From b0262ec239d3a89233d4537ef8ae75cd39ac0789 Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Fri, 26 Feb 2021 08:56:18 +0100 Subject: [PATCH 1/3] Fix import DNC for new contacts --- .../EventListener/DoNotContactSubscriber.php | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php b/app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php index ce960341f4a..2a260ad0ca3 100644 --- a/app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php +++ b/app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php @@ -49,14 +49,23 @@ public function removeDncForLead(DoNotContactRemoveEvent $doNotContactRemoveEven public function addDncForLead(DoNotContactAddEvent $doNotContactAddEvent): void { - $this->doNotContact->addDncForContact( - $doNotContactAddEvent->getLead()->getId(), - $doNotContactAddEvent->getChannel(), - $doNotContactAddEvent->getReason(), - $doNotContactAddEvent->getComments(), - $doNotContactAddEvent->isPersist(), - $doNotContactAddEvent->isCheckCurrentStatus(), - $doNotContactAddEvent->isOverride() - ); + if(empty($doNotContactAddEvent->getLead()->getId())) { + $this->doNotContact->createDncRecord( + $doNotContactAddEvent->getLead(), + $doNotContactAddEvent->getChannel(), + $doNotContactAddEvent->getReason(), + $doNotContactAddEvent->getComments() + ); + }else { + $this->doNotContact->addDncForContact( + $doNotContactAddEvent->getLead()->getId(), + $doNotContactAddEvent->getChannel(), + $doNotContactAddEvent->getReason(), + $doNotContactAddEvent->getComments(), + $doNotContactAddEvent->isPersist(), + $doNotContactAddEvent->isCheckCurrentStatus(), + $doNotContactAddEvent->isOverride() + ); + } } } From 3fb85e35412bb8a6dbea4549fe70fc1e7ffef019 Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Fri, 26 Feb 2021 09:04:14 +0100 Subject: [PATCH 2/3] CS fixer --- .../LeadBundle/EventListener/DoNotContactSubscriber.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php b/app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php index 2a260ad0ca3..973c6122d67 100644 --- a/app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php +++ b/app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php @@ -49,14 +49,14 @@ public function removeDncForLead(DoNotContactRemoveEvent $doNotContactRemoveEven public function addDncForLead(DoNotContactAddEvent $doNotContactAddEvent): void { - if(empty($doNotContactAddEvent->getLead()->getId())) { + if (empty($doNotContactAddEvent->getLead()->getId())) { $this->doNotContact->createDncRecord( $doNotContactAddEvent->getLead(), $doNotContactAddEvent->getChannel(), $doNotContactAddEvent->getReason(), $doNotContactAddEvent->getComments() ); - }else { + } else { $this->doNotContact->addDncForContact( $doNotContactAddEvent->getLead()->getId(), $doNotContactAddEvent->getChannel(), From 9fc8ba729c44e4a2a41125239b5974f678a5f10c Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Sun, 14 Mar 2021 22:22:18 +0100 Subject: [PATCH 3/3] Add unit tests --- .../DoNotContactSubscriberTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 app/bundles/LeadBundle/Tests/EventListener/DoNotContactSubscriberTest.php diff --git a/app/bundles/LeadBundle/Tests/EventListener/DoNotContactSubscriberTest.php b/app/bundles/LeadBundle/Tests/EventListener/DoNotContactSubscriberTest.php new file mode 100644 index 00000000000..42d3bc9863c --- /dev/null +++ b/app/bundles/LeadBundle/Tests/EventListener/DoNotContactSubscriberTest.php @@ -0,0 +1,65 @@ +doNotContact = $this->createMock(DoNotContact::class); + $this->doNotContactSubscriber = new DoNotContactSubscriber($this->doNotContact); + } + + public function testGetSubscribedEvents() + { + $this->assertEquals( + [ + DoNotContactAddEvent::ADD_DONOT_CONTACT => ['addDncForLead', 0], + DoNotContactRemoveEvent::REMOVE_DONOT_CONTACT => ['removeDncForLead', 0], + ], + $this->doNotContactSubscriber->getSubscribedEvents() + ); + } + + public function testAddDncForLeadForNewContacts() + { + $lead = new Lead(); + $doNotContactEvent = new DoNotContactAddEvent($lead, 'email'); + + $this->doNotContact->expects($this->once())->method('createDncRecord'); + $this->doNotContact->expects($this->never())->method('addDncForContact'); + + $this->doNotContactSubscriber->addDncForLead($doNotContactEvent); + } + + public function testAddDncForLeadForExistedContacts() + { + $lead = new Lead(); + $lead->setId(1); + $doNotContactEvent = new DoNotContactAddEvent($lead, 'email'); + + $this->doNotContact->expects($this->never())->method('createDncRecord'); + $this->doNotContact->expects($this->once())->method('addDncForContact'); + + $this->doNotContactSubscriber->addDncForLead($doNotContactEvent); + } +}