1 | <?php |
||
13 | class AzineMailgunMailerServiceTest extends WebTestCase |
||
14 | { |
||
15 | public function testSendSpamComplaintNotification() |
||
16 | { |
||
17 | $this->checkApplication(); |
||
18 | |||
19 | // Create a new client to browse the application |
||
20 | $client = static::createClient(); |
||
21 | $client->request("GET", "/"); |
||
22 | $client->followRedirects(); |
||
23 | |||
24 | $mailer = $this->getContainer()->get('mailer'); |
||
25 | $twig = $this->getContainer()->get('twig'); |
||
26 | $translator = $this->getContainer()->get('translator'); |
||
27 | $fromEmail = '[email protected]'; |
||
28 | $ticketId = '123'; |
||
29 | $ticketSubject = 'test'; |
||
30 | $ticketMessage = 'testMessage'; |
||
31 | $spamAlertsRecipientEmail = '[email protected]'; |
||
32 | $entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
33 | $sendIntervalMinutes = 1; |
||
34 | |||
35 | $mailgunMailerService = new AzineMailgunMailerService($mailer, $twig, $translator,$fromEmail, $ticketId, |
||
36 | $ticketSubject, $ticketMessage, $spamAlertsRecipientEmail, $entityManager, $sendIntervalMinutes); |
||
37 | |||
38 | $messageSent = $mailgunMailerService->sendSpamComplaintNotification(123); |
||
39 | |||
40 | // Check that email was sent |
||
41 | $this->assertEquals(1, $messageSent); |
||
42 | |||
43 | $messageSent = $mailgunMailerService->sendSpamComplaintNotification(123); |
||
44 | |||
45 | // Check that an email was not sent because the last email was sent less then azine_mailgun_webhooks_send_spam_alerts_interval |
||
46 | $this->assertEquals(0, $messageSent); |
||
47 | |||
48 | $timeToWait = ($sendIntervalMinutes + 1) * 60; |
||
49 | sleep($timeToWait); |
||
50 | $messageSent = $mailgunMailerService->sendSpamComplaintNotification(123); |
||
51 | |||
52 | // Check that email was sent after azine_mailgun_webhooks_send_spam_alerts_interval have passed |
||
53 | $this->assertEquals(1, $messageSent); |
||
54 | |||
55 | } |
||
56 | |||
57 | |||
58 | /** |
||
59 | * @var ContainerInterface |
||
60 | */ |
||
61 | private $container; |
||
62 | |||
63 | |||
64 | /** |
||
65 | * Get the current container |
||
66 | * @return \Symfony\Component\DependencyInjection\ContainerInterface |
||
67 | */ |
||
68 | private function getContainer() |
||
76 | |||
77 | /** |
||
78 | * Check if the current setup is a full application. |
||
79 | * If not, mark the test as skipped else continue. |
||
80 | */ |
||
81 | private function checkApplication() |
||
91 | } |