File size: 1,786 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
<?php

declare(strict_types=1);

namespace Mautic\IntegrationsBundle\Tests\Functional\Sync\Notification;

use Mautic\CoreBundle\Entity\Notification;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\IntegrationsBundle\Sync\Notification\BulkNotification;
use PHPUnit\Framework\Assert;

class BulkNotificationTest extends MauticMysqlTestCase
{
    /**
     * @var BulkNotification
     */
    private $bulkNotification;

    protected function setUp(): void
    {
        parent::setUp();

        $this->bulkNotification = static::getContainer()->get('mautic.integrations.sync.notification.bulk_notification');
    }

    public function testNotifications(): void
    {
        $notificationRepository = $this->em->getRepository(Notification::class);

        $this->bulkNotification->addNotification('dup1', 'message 1', 'Integration name', 'Lead', 'lead', 0, 'link 1');
        $this->bulkNotification->addNotification('dup2', 'message 2', 'Integration name', 'Lead', 'lead', 0, 'link 2');
        $this->bulkNotification->addNotification('dup1', 'message 3', 'Integration name', 'Lead', 'lead', 0, 'link 3');

        Assert::assertCount(0, $notificationRepository->findAll());

        $this->bulkNotification->flush();

        $notifications = $notificationRepository->findAll();
        Assert::assertCount(2, $notifications);
        $this->assertNotification($notifications[0], 'message 1', 'link 1');
        $this->assertNotification($notifications[1], 'message 2', 'link 2');
    }

    private function assertNotification(Notification $notification, string $message, string $link): void
    {
        Assert::assertSame(sprintf('<a href="/s/contacts/view">%s</a> failed to sync with message, &quot;%s&quot;', $link, $message), $notification->getMessage());
    }
}