Spaces:
No application file
No application file
File size: 3,619 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
<?php
declare(strict_types=1);
namespace Mautic\IntegrationsBundle\Tests\Functional\Sync\Notification;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\IntegrationsBundle\Helper\SyncIntegrationsHelper;
use Mautic\IntegrationsBundle\Sync\DAO\Sync\Order\NotificationDAO;
use Mautic\IntegrationsBundle\Sync\DAO\Sync\Order\ObjectChangeDAO;
use Mautic\IntegrationsBundle\Sync\Notification\Notifier;
use Mautic\IntegrationsBundle\Sync\SyncDataExchange\Internal\Object\Contact;
use Mautic\IntegrationsBundle\Sync\SyncDataExchange\MauticSyncDataExchange;
use Mautic\IntegrationsBundle\Tests\Functional\Services\SyncService\TestExamples\Integration\ExampleIntegration;
use Mautic\IntegrationsBundle\Tests\Functional\Services\SyncService\TestExamples\Sync\SyncDataExchange\ExampleSyncDataExchange;
use Mautic\LeadBundle\DataFixtures\ORM\LoadLeadData;
use Mautic\LeadBundle\Entity\Lead;
class NotifierTest extends MauticMysqlTestCase
{
public function testNotifications(): void
{
$this->installDatabaseFixtures([LoadLeadData::class]);
$leadRepository = $this->em->getRepository(Lead::class);
/** @var Lead[] $leads */
$leads = $leadRepository->findBy([], [], 2);
/** @var SyncIntegrationsHelper $syncIntegrationsHelper */
$syncIntegrationsHelper = static::getContainer()->get('mautic.integrations.helper.sync_integrations');
$syncIntegrationsHelper->addIntegration(new ExampleIntegration(new ExampleSyncDataExchange()));
/** @var Notifier $notifier */
$notifier = static::getContainer()->get('mautic.integrations.sync.notifier');
$contactNotification = new NotificationDAO(
new ObjectChangeDAO(
ExampleIntegration::NAME,
'Foo',
1,
Contact::NAME,
(int) $leads[0]->getId()
),
'This is the message'
);
$companyNotification = new NotificationDAO(
new ObjectChangeDAO(
ExampleIntegration::NAME,
'Bar',
2,
MauticSyncDataExchange::OBJECT_COMPANY,
(int) $leads[1]->getId()
),
'This is the message'
);
$notifier->noteMauticSyncIssue([$contactNotification, $companyNotification]);
$notifier->finalizeNotifications();
// Check audit log
$qb = $this->connection->createQueryBuilder();
$qb->select('1')
->from(MAUTIC_TABLE_PREFIX.'audit_log')
->where(
$qb->expr()->eq('bundle', $qb->expr()->literal(ExampleIntegration::NAME))
);
$this->assertCount(2, $qb->executeQuery()->fetchAllAssociative());
// Contact event log
$qb = $this->connection->createQueryBuilder();
$qb->select('1')
->from(MAUTIC_TABLE_PREFIX.'lead_event_log')
->where(
$qb->expr()->and(
$qb->expr()->eq('bundle', $qb->expr()->literal('integrations')),
$qb->expr()->eq('object', $qb->expr()->literal(ExampleIntegration::NAME))
)
);
$this->assertCount(1, $qb->executeQuery()->fetchAllAssociative());
// User notifications
$qb = $this->connection->createQueryBuilder();
$qb->select('1')
->from(MAUTIC_TABLE_PREFIX.'notifications')
->where(
$qb->expr()->eq('icon_class', $qb->expr()->literal('ri-refresh-line'))
);
$this->assertCount(2, $qb->executeQuery()->fetchAllAssociative());
}
}
|