8000 Fix import DNC for new contacts by kuzmany · Pull Request #9732 · mautic/mautic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix import DNC for new contacts #9732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions app/bundles/LeadBundle/EventListener/DoNotContactSubscriber.php
10786
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
* @copyright 2021 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Mautic\LeadBundle\Tests\EventListener;

use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Event\DoNotContactAddEvent;
use Mautic\LeadBundle\Event\DoNotContactRemoveEvent;
use Mautic\LeadBundle\EventListener\DoNotContactSubscriber;
use Mautic\LeadBundle\Model\DoNotContact;

class DoNotContactSubscriberTest extends \PHPUnit\Framework\TestCase
{
private $doNotContactSubscriber;

private $doNotContact;

protected function setUp(): void
{
$this->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);
}
}
0