Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticCrmBundle\Tests\Integration;
|
||||
|
||||
use Mautic\PluginBundle\Model\IntegrationEntityModel;
|
||||
use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase;
|
||||
use MauticPlugin\MauticCrmBundle\Api\ConnectwiseApi;
|
||||
use MauticPlugin\MauticCrmBundle\Integration\ConnectwiseIntegration;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(ConnectwiseIntegration::class)]
|
||||
class ConnectwiseIntegrationTest extends AbstractIntegrationTestCase
|
||||
{
|
||||
use DataGeneratorTrait;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\TestDox('Test that all records are fetched till last page of results are consumed')]
|
||||
public function testMultiplePagesOfRecordsAreFetched(): void
|
||||
{
|
||||
$this->reset();
|
||||
|
||||
$apiHelper = $this->createMock(ConnectwiseApi::class);
|
||||
|
||||
$apiHelper->expects($this->exactly(2))
|
||||
->method('getContacts')
|
||||
->willReturnCallback(
|
||||
fn () => $this->generateData(2)
|
||||
);
|
||||
|
||||
$integration = $this->getMockBuilder(ConnectwiseIntegration::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['isAuthorized', 'getApiHelper', 'getMauticLead'])
|
||||
->getMock();
|
||||
|
||||
$integration->expects($this->once())
|
||||
->method('isAuthorized')
|
||||
->willReturn(true);
|
||||
|
||||
$integration
|
||||
->method('getApiHelper')
|
||||
->willReturn($apiHelper);
|
||||
|
||||
$integration->getRecords([], 'Contact');
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\TestDox('Test that all records are fetched till last page of results are consumed')]
|
||||
public function testMultiplePagesOfCampaignMemberRecordsAreFetched(): void
|
||||
{
|
||||
$this->reset();
|
||||
|
||||
$apiHelper = $this->createMock(ConnectwiseApi::class);
|
||||
|
||||
$apiHelper->expects($this->exactly(2))
|
||||
->method('getCampaignMembers')
|
||||
->willReturnCallback(
|
||||
fn () => $this->generateData(2)
|
||||
);
|
||||
|
||||
$integrationEntityModel = $this->createMock(IntegrationEntityModel::class);
|
||||
|
||||
$integration = $this->getMockBuilder(ConnectwiseIntegration::class)
|
||||
->setConstructorArgs([
|
||||
$this->dispatcher,
|
||||
$this->cache,
|
||||
$this->em,
|
||||
$this->request,
|
||||
$this->router,
|
||||
$this->translator,
|
||||
$this->logger,
|
||||
$this->encryptionHelper,
|
||||
$this->leadModel,
|
||||
$this->companyModel,
|
||||
$this->pathsHelper,
|
||||
$this->notificationModel,
|
||||
$this->fieldModel,
|
||||
$integrationEntityModel,
|
||||
$this->doNotContact,
|
||||
$this->fieldsWithUniqueIdentifier,
|
||||
])
|
||||
->onlyMethods(['isAuthorized', 'getApiHelper', 'getRecords', 'saveCampaignMembers'])
|
||||
->getMock();
|
||||
|
||||
$integration->expects($this->once())
|
||||
->method('isAuthorized')
|
||||
->willReturn(true);
|
||||
|
||||
$integration
|
||||
->method('getApiHelper')
|
||||
->willReturn($apiHelper);
|
||||
|
||||
$integration->getCampaignMembers(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticCrmBundle\Tests\Integration;
|
||||
|
||||
use MauticPlugin\MauticCrmBundle\Integration\ConnectwiseIntegration;
|
||||
|
||||
trait DataGeneratorTrait
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $page = 1;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $id = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $generatedRecords = [];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function generateData($maxPages)
|
||||
{
|
||||
$pageSize = ($this->page === $maxPages) ? ConnectwiseIntegration::PAGESIZE / 2 : ConnectwiseIntegration::PAGESIZE;
|
||||
$fakeData = [];
|
||||
$counter = 0;
|
||||
while ($counter < $pageSize) {
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
];
|
||||
$fakeData[] = $data;
|
||||
$this->generatedRecords[] = $data;
|
||||
|
||||
++$counter;
|
||||
++$this->id;
|
||||
}
|
||||
++$this->page;
|
||||
|
||||
return $fakeData;
|
||||
}
|
||||
|
||||
protected function reset()
|
||||
{
|
||||
$this->id = 0;
|
||||
$this->page = 1;
|
||||
$this->generatedRecords = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MauticCrmBundle\Tests\Integration;
|
||||
|
||||
use Mautic\CoreBundle\Helper\UserHelper;
|
||||
use Mautic\PluginBundle\Entity\Integration;
|
||||
use Mautic\PluginBundle\Event\PluginIntegrationKeyEvent;
|
||||
use Mautic\PluginBundle\PluginEvents;
|
||||
use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase;
|
||||
use MauticPlugin\MauticCrmBundle\Integration\HubspotIntegration;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class HubspotIntegrationTest extends AbstractIntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* @var MockObject&UserHelper
|
||||
*/
|
||||
private MockObject $userHelper;
|
||||
|
||||
private HubspotIntegration $integration;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->userHelper = $this->createMock(UserHelper::class);
|
||||
$this->integration = new HubspotIntegration(
|
||||
$this->dispatcher,
|
||||
$this->cache,
|
||||
$this->em,
|
||||
$this->request,
|
||||
$this->router,
|
||||
$this->translator,
|
||||
$this->logger,
|
||||
$this->encryptionHelper,
|
||||
$this->leadModel,
|
||||
$this->companyModel,
|
||||
$this->pathsHelper,
|
||||
$this->notificationModel,
|
||||
$this->fieldModel,
|
||||
$this->integrationEntityModel,
|
||||
$this->doNotContact,
|
||||
$this->fieldsWithUniqueIdentifier,
|
||||
$this->userHelper
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetRequiredKeyFields(): void
|
||||
{
|
||||
self::assertSame([], $this->integration->getRequiredKeyFields());
|
||||
}
|
||||
|
||||
public function testGetBearerTokenEmpty(): void
|
||||
{
|
||||
$event = $this->createMock(PluginIntegrationKeyEvent::class);
|
||||
$event->expects(self::once())
|
||||
->method('getKeys')
|
||||
->willReturn(['other' => 'data']);
|
||||
$this->dispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
new PluginIntegrationKeyEvent($this->integration, [HubspotIntegration::ACCESS_KEY]),
|
||||
PluginEvents::PLUGIN_ON_INTEGRATION_KEYS_ENCRYPT
|
||||
)
|
||||
->willReturn($event);
|
||||
|
||||
$this->integration->encryptAndSetApiKeys([HubspotIntegration::ACCESS_KEY], $this->createMock(Integration::class));
|
||||
self::assertNull($this->integration->getBearerToken());
|
||||
}
|
||||
|
||||
public function testGetBearerTokenSet(): void
|
||||
{
|
||||
$token = 'token';
|
||||
|
||||
$event = $this->createMock(PluginIntegrationKeyEvent::class);
|
||||
$event->expects(self::once())
|
||||
->method('getKeys')
|
||||
->willReturn(['other' => 'data', HubspotIntegration::ACCESS_KEY => $token]);
|
||||
$this->dispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
new PluginIntegrationKeyEvent($this->integration, [HubspotIntegration::ACCESS_KEY]),
|
||||
PluginEvents::PLUGIN_ON_INTEGRATION_KEYS_ENCRYPT
|
||||
)
|
||||
->willReturn($event);
|
||||
|
||||
$this->integration->encryptAndSetApiKeys([HubspotIntegration::ACCESS_KEY], $this->createMock(Integration::class));
|
||||
self::assertSame($token, $this->integration->getBearerToken());
|
||||
}
|
||||
|
||||
public function testGetFormSettings(): void
|
||||
{
|
||||
self::assertSame(
|
||||
[
|
||||
'requires_callback' => false,
|
||||
'requires_authorization' => false,
|
||||
],
|
||||
$this->integration->getFormSettings()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetAuthenticationTypeNoOauthToken(): void
|
||||
{
|
||||
$event = $this->createMock(PluginIntegrationKeyEvent::class);
|
||||
$event->expects(self::once())
|
||||
->method('getKeys')
|
||||
->willReturn(['other' => 'data']);
|
||||
$this->dispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
new PluginIntegrationKeyEvent($this->integration, [HubspotIntegration::ACCESS_KEY]),
|
||||
PluginEvents::PLUGIN_ON_INTEGRATION_KEYS_ENCRYPT
|
||||
)
|
||||
->willReturn($event);
|
||||
|
||||
$this->integration->encryptAndSetApiKeys([HubspotIntegration::ACCESS_KEY], $this->createMock(Integration::class));
|
||||
self::assertSame('key', $this->integration->getAuthenticationType());
|
||||
}
|
||||
|
||||
public function testGetAuthenticationTypeWithOauthToken(): void
|
||||
{
|
||||
$event = $this->createMock(PluginIntegrationKeyEvent::class);
|
||||
$event->expects(self::once())
|
||||
->method('getKeys')
|
||||
->willReturn(['other' => 'data', HubspotIntegration::ACCESS_KEY => 'token']);
|
||||
$this->dispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
new PluginIntegrationKeyEvent($this->integration, [HubspotIntegration::ACCESS_KEY]),
|
||||
PluginEvents::PLUGIN_ON_INTEGRATION_KEYS_ENCRYPT
|
||||
)
|
||||
->willReturn($event);
|
||||
|
||||
$this->integration->encryptAndSetApiKeys([HubspotIntegration::ACCESS_KEY], $this->createMock(Integration::class));
|
||||
self::assertSame('oauth2', $this->integration->getAuthenticationType());
|
||||
}
|
||||
|
||||
public function testIsAuthorizedNoOauthToken(): void
|
||||
{
|
||||
$event = $this->createMock(PluginIntegrationKeyEvent::class);
|
||||
$event->expects(self::once())
|
||||
->method('getKeys')
|
||||
->willReturn(['other' => 'data']);
|
||||
$this->dispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
new PluginIntegrationKeyEvent($this->integration, [HubspotIntegration::ACCESS_KEY]),
|
||||
PluginEvents::PLUGIN_ON_INTEGRATION_KEYS_ENCRYPT
|
||||
)
|
||||
->willReturn($event);
|
||||
|
||||
$this->integration->encryptAndSetApiKeys([HubspotIntegration::ACCESS_KEY], $this->createMock(Integration::class));
|
||||
self::assertFalse($this->integration->isAuthorized());
|
||||
}
|
||||
|
||||
public function testIsAuthorizedWithOauthToken(): void
|
||||
{
|
||||
$event = $this->createMock(PluginIntegrationKeyEvent::class);
|
||||
$event->expects(self::once())
|
||||
->method('getKeys')
|
||||
->willReturn(['other' => 'data', HubspotIntegration::ACCESS_KEY => 'token']);
|
||||
$this->dispatcher->expects(self::once())
|
||||
->method('dispatch')
|
||||
->with(
|
||||
new PluginIntegrationKeyEvent($this->integration, [HubspotIntegration::ACCESS_KEY]),
|
||||
PluginEvents::PLUGIN_ON_INTEGRATION_KEYS_ENCRYPT
|
||||
)
|
||||
->willReturn($event);
|
||||
|
||||
$this->integration->encryptAndSetApiKeys([HubspotIntegration::ACCESS_KEY], $this->createMock(Integration::class));
|
||||
self::assertTrue($this->integration->isAuthorized());
|
||||
}
|
||||
|
||||
public function testAppendToFormKeys(): void
|
||||
{
|
||||
$builder = $this->createMock(FormBuilderInterface::class);
|
||||
$matcher = self::exactly(2);
|
||||
$builder->expects($matcher)
|
||||
->method('add')->willReturnCallback(function (...$parameters) use ($matcher) {
|
||||
if (1 === $matcher->numberOfInvocations()) {
|
||||
$this->assertSame(HubspotIntegration::ACCESS_KEY, $parameters[0]);
|
||||
$this->assertSame(TextType::class, $parameters[1]);
|
||||
}
|
||||
if (2 === $matcher->numberOfInvocations()) {
|
||||
$this->assertSame($this->integration->getApiKey(), $parameters[0]);
|
||||
$this->assertSame(TextType::class, $parameters[1]);
|
||||
}
|
||||
})->willReturnSelf();
|
||||
|
||||
$this->integration->appendToForm($builder, [], 'keys');
|
||||
}
|
||||
|
||||
public function testAppendToFormFeatures(): void
|
||||
{
|
||||
$builder = $this->createMock(FormBuilderInterface::class);
|
||||
$builder->expects(self::once())
|
||||
->method('add')
|
||||
->with('objects', ChoiceType::class);
|
||||
|
||||
$this->integration->appendToForm($builder, [], 'features');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticCrmBundle\Tests\Integration\Salesforce\CampaignMember;
|
||||
|
||||
use Mautic\PluginBundle\Entity\IntegrationEntityRepository;
|
||||
use MauticPlugin\MauticCrmBundle\Integration\Salesforce\CampaignMember\Fetcher;
|
||||
use MauticPlugin\MauticCrmBundle\Integration\Salesforce\CampaignMember\Organizer;
|
||||
use MauticPlugin\MauticCrmBundle\Integration\Salesforce\Object\CampaignMember;
|
||||
use MauticPlugin\MauticCrmBundle\Integration\Salesforce\Object\Contact;
|
||||
use MauticPlugin\MauticCrmBundle\Integration\Salesforce\Object\Lead;
|
||||
|
||||
class FetcherTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testEntitiesAreFetchedFromOrganizerResults(): void
|
||||
{
|
||||
$organizer = $this->getOrgnanizer();
|
||||
$repo = $this->createMock(IntegrationEntityRepository::class);
|
||||
$matcher = $this->exactly(2);
|
||||
|
||||
$repo->expects($matcher)
|
||||
->method('getIntegrationsEntityId')->willReturnCallback(function (...$parameters) use ($matcher, $organizer) {
|
||||
if (1 === $matcher->numberOfInvocations()) {
|
||||
$this->assertSame('Salesforce', $parameters[0]);
|
||||
$this->assertSame(Lead::OBJECT, $parameters[1]);
|
||||
$this->assertSame('lead', $parameters[2]);
|
||||
$this->assertNull($parameters[3]);
|
||||
$this->assertNull($parameters[4]);
|
||||
$this->assertNull($parameters[5]);
|
||||
$this->assertFalse($parameters[6]);
|
||||
$this->assertSame(0, $parameters[7]);
|
||||
$this->assertSame(0, $parameters[8]);
|
||||
$this->assertSame($organizer->getLeadIds(), $parameters[9]);
|
||||
}
|
||||
if (2 === $matcher->numberOfInvocations()) {
|
||||
$this->assertSame('Salesforce', $parameters[0]);
|
||||
$this->assertSame(Contact::OBJECT, $parameters[1]);
|
||||
$this->assertSame('lead', $parameters[2]);
|
||||
$this->assertNull($parameters[3]);
|
||||
$this->assertNull($parameters[4]);
|
||||
$this->assertNull($parameters[5]);
|
||||
$this->assertFalse($parameters[6]);
|
||||
$this->assertSame(0, $parameters[7]);
|
||||
$this->assertSame(0, $parameters[8]);
|
||||
$this->assertSame($organizer->getContactIds(), $parameters[9]);
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
new Fetcher($repo, $organizer, '701f10000021UnkAAE');
|
||||
}
|
||||
|
||||
public function testThatCampaignMembersAreFetched(): void
|
||||
{
|
||||
$organizer = $this->getOrgnanizer();
|
||||
$repo = $this->createMock(IntegrationEntityRepository::class);
|
||||
$matcher = $this->exactly(4);
|
||||
|
||||
$repo->expects($matcher)
|
||||
->method('getIntegrationsEntityId')->willReturnCallback(function (...$parameters) use ($matcher, $organizer) {
|
||||
if (1 === $matcher->numberOfInvocations()) {
|
||||
$this->assertSame('Salesforce', $parameters[0]);
|
||||
$this->assertSame(Lead::OBJECT, $parameters[1]);
|
||||
$this->assertSame('lead', $parameters[2]);
|
||||
$this->assertNull($parameters[3]);
|
||||
$this->assertNull($parameters[4]);
|
||||
$this->assertNull($parameters[5]);
|
||||
$this->assertFalse($parameters[6]);
|
||||
$this->assertSame(0, $parameters[7]);
|
||||
$this->assertSame(0, $parameters[8]);
|
||||
$this->assertSame($organizer->getLeadIds(), $parameters[9]);
|
||||
|
||||
return [
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYvEEAV',
|
||||
'internal_entity_id' => 1,
|
||||
],
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYvJEAV',
|
||||
'internal_entity_id' => 2,
|
||||
],
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYvOEAV',
|
||||
'internal_entity_id' => 3,
|
||||
],
|
||||
];
|
||||
}
|
||||
if (2 === $matcher->numberOfInvocations()) {
|
||||
$this->assertSame('Salesforce', $parameters[0]);
|
||||
$this->assertSame(Contact::OBJECT, $parameters[1]);
|
||||
$this->assertSame('lead', $parameters[2]);
|
||||
$this->assertNull($parameters[3]);
|
||||
$this->assertNull($parameters[4]);
|
||||
$this->assertNull($parameters[5]);
|
||||
$this->assertFalse($parameters[6]);
|
||||
$this->assertSame(0, $parameters[7]);
|
||||
$this->assertSame(0, $parameters[8]);
|
||||
$this->assertSame($organizer->getContactIds(), $parameters[9]);
|
||||
|
||||
return [
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYvYEAV',
|
||||
'internal_entity_id' => 4,
|
||||
],
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYvdEAF',
|
||||
'internal_entity_id' => 5,
|
||||
],
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYviEAF',
|
||||
'internal_entity_id' => 6,
|
||||
],
|
||||
];
|
||||
}
|
||||
if (3 === $matcher->numberOfInvocations()) {
|
||||
$this->assertSame('Salesforce', $parameters[0]);
|
||||
$this->assertSame(CampaignMember::OBJECT, $parameters[1]);
|
||||
$this->assertSame('lead', $parameters[2]);
|
||||
$this->assertSame([1, 2, 3, 4, 5, 6], $parameters[3]);
|
||||
$this->assertNull($parameters[4]);
|
||||
$this->assertNull($parameters[5]);
|
||||
$this->assertFalse($parameters[6]);
|
||||
$this->assertSame(0, $parameters[7]);
|
||||
$this->assertSame(0, $parameters[8]);
|
||||
$this->assertSame('701f10000021UnkAAE', $parameters[9]);
|
||||
|
||||
return [
|
||||
[
|
||||
'integration_entity' => CampaignMember::OBJECT,
|
||||
'integration_entity_id' => '701f10000021UnkAAE',
|
||||
'internal_entity_id' => 1,
|
||||
],
|
||||
[
|
||||
'integration_entity' => CampaignMember::OBJECT,
|
||||
'integration_entity_id' => '701f10000021UnkAAE',
|
||||
'internal_entity_id' => 4,
|
||||
],
|
||||
];
|
||||
}
|
||||
if (4 === $matcher->numberOfInvocations()) {
|
||||
$this->assertSame('Salesforce', $parameters[0]);
|
||||
$this->assertNull($parameters[1]);
|
||||
$this->assertSame('lead', $parameters[2]);
|
||||
$this->assertNull($parameters[3]);
|
||||
$this->assertNull($parameters[4]);
|
||||
$this->assertNull($parameters[5]);
|
||||
$this->assertFalse($parameters[6]);
|
||||
$this->assertSame(0, $parameters[7]);
|
||||
$this->assertSame(0, $parameters[8]);
|
||||
$this->assertSame(['00Qf100000YjYv4EAF', '00Qf100000YjYv9EAF', '00Qf100000YjYvTEAV', '00Qf100000X1NR5EAN'], $parameters[9]);
|
||||
|
||||
return [
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYv4EAF',
|
||||
'internal_entity_id' => 7,
|
||||
],
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYv9EAF',
|
||||
'internal_entity_id' => 8,
|
||||
],
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000YjYvTEAV',
|
||||
'internal_entity_id' => 9,
|
||||
],
|
||||
[
|
||||
'integration_entity_id' => '00Qf100000X1NR5EAN',
|
||||
'internal_entity_id' => 10,
|
||||
],
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
$fetcher = new Fetcher($repo, $organizer, '701f10000021UnkAAE');
|
||||
|
||||
// The query to fetch unknown members should be the 2 Leads not returned by at(0)
|
||||
$this->assertEquals(
|
||||
"SELECT Test, Id from Lead where Id in ('00Qf100000YjYv4EAF','00Qf100000YjYv9EAF') and ConvertedContactId = NULL",
|
||||
$fetcher->getQueryForUnknownObjects(['Test'], Lead::OBJECT)
|
||||
);
|
||||
|
||||
// The query to fetch unknown members should be the 2 Contacts not returned by at(1)
|
||||
$this->assertEquals(
|
||||
"SELECT Test, Id from Contact where Id in ('00Qf100000YjYvTEAV','00Qf100000X1NR5EAN')",
|
||||
$fetcher->getQueryForUnknownObjects(['Test'], Contact::OBJECT)
|
||||
);
|
||||
|
||||
// Should include all but the two we are already tracking as campaign members
|
||||
$unknown = $fetcher->getUnknownCampaignMembers();
|
||||
|
||||
$this->assertEquals(
|
||||
[2, 3, 5, 6, 7, 8, 9, 10],
|
||||
$unknown
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Organizer
|
||||
*/
|
||||
private function getOrgnanizer()
|
||||
{
|
||||
$records = [
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQe2AAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYv4EAF',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQe7AAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYv9EAF',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeCAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYvEEAV',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeHAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYvJEAV',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeMAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYvOEAV',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeRAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000YjYvTEAV',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeWAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000X1NR5EAN',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQebAAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000YjYvYEAV',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQegAAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000YjYvdEAF',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQelAAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000YjYviEAF',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
];
|
||||
|
||||
return new Organizer($records);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticCrmBundle\Tests\Integration\Salesforce\CampaignMember;
|
||||
|
||||
use MauticPlugin\MauticCrmBundle\Integration\Salesforce\CampaignMember\Organizer;
|
||||
|
||||
class OrganizerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testRecordsAreOrganizedIntoLeadsAndContacts(): void
|
||||
{
|
||||
$records = [
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQe2AAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYv4EAF',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQe7AAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYv9EAF',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeCAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYvEEAV',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeHAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYvJEAV',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeMAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => null,
|
||||
'LeadId' => '00Qf100000YjYvOEAV',
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeRAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000YjYvTEAV',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQeWAAW',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000X1NR5EAN',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQebAAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000YjYvYEAV',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQegAAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000YjYvdEAF',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
[
|
||||
'attributes' => [
|
||||
'type' => 'CampaignMember',
|
||||
'url' => '/services/data/v34.0/sobjects/CampaignMember/00vf100000gFQelAAG',
|
||||
],
|
||||
'CampaignId' => '701f10000021UnkAAE',
|
||||
'ContactId' => '00Qf100000YjYviEAF',
|
||||
'LeadId' => null,
|
||||
'IsDeleted' => false,
|
||||
],
|
||||
];
|
||||
|
||||
$organizer = new Organizer($records);
|
||||
|
||||
$leads = ['00Qf100000YjYv4EAF', '00Qf100000YjYv9EAF', '00Qf100000YjYvEEAV', '00Qf100000YjYvJEAV', '00Qf100000YjYvOEAV'];
|
||||
$this->assertEquals($leads, $organizer->getLeadIds());
|
||||
|
||||
$organizedLeads = $organizer->getLeads();
|
||||
foreach ($leads as $id) {
|
||||
$this->assertArrayHasKey($id, $organizedLeads);
|
||||
$this->assertEquals($id, $organizedLeads[$id]->getId());
|
||||
}
|
||||
|
||||
$contacts = ['00Qf100000YjYvTEAV', '00Qf100000X1NR5EAN', '00Qf100000YjYvYEAV', '00Qf100000YjYvdEAF', '00Qf100000YjYviEAF'];
|
||||
$this->assertEquals($contacts, $organizer->getContactIds());
|
||||
|
||||
$organizedContacts = $organizer->getContacts();
|
||||
foreach ($contacts as $id) {
|
||||
$this->assertArrayHasKey($id, $organizedContacts);
|
||||
$this->assertEquals($id, $organizedContacts[$id]->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace MauticPlugin\MauticCrmBundle\Tests\Integration\Salesforce\Helper;
|
||||
|
||||
use MauticPlugin\MauticCrmBundle\Integration\Salesforce\Helper\StateValidationHelper;
|
||||
|
||||
class StateValidationHelperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testStateIsRemovedWhenCountryIsUnknown(): void
|
||||
{
|
||||
$payload = [
|
||||
'State' => 'Paris',
|
||||
];
|
||||
|
||||
$this->assertEquals([], StateValidationHelper::validate($payload));
|
||||
}
|
||||
|
||||
public function testStateIsRemovedWhenCountryIsNotSupported(): void
|
||||
{
|
||||
$payload = [
|
||||
'Country' => 'France',
|
||||
'State' => 'Paris',
|
||||
];
|
||||
|
||||
$this->assertEquals(['Country' => 'France'], StateValidationHelper::validate($payload));
|
||||
}
|
||||
|
||||
public function testStateIsLeftWhenCountryIsSupported(): void
|
||||
{
|
||||
$payload = [
|
||||
'Country' => 'United States',
|
||||
'State' => 'Texas',
|
||||
];
|
||||
|
||||
$this->assertEquals($payload, StateValidationHelper::validate($payload));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user