1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2018 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic, Inc. |
||
6 | * |
||
7 | * @link https://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\CampaignBundle\Tests\Command; |
||
13 | |||
14 | class ExecuteEventCommandTest extends AbstractCampaignCommand |
||
15 | { |
||
16 | public function testEventsAreExecutedForInactiveEventWithSingleContact() |
||
17 | { |
||
18 | putenv('CAMPAIGN_EXECUTIONER_SCHEDULER_ACKNOWLEDGE_SECONDS=1'); |
||
19 | |||
20 | $this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']); |
||
21 | |||
22 | // There should be two events scheduled |
||
23 | $byEvent = $this->getCampaignEventLogs([2]); |
||
24 | $this->assertCount(3, $byEvent[2]); |
||
25 | |||
26 | $logIds = []; |
||
27 | foreach ($byEvent[2] as $log) { |
||
28 | if (0 === (int) $log['is_scheduled']) { |
||
29 | $this->fail('Event is not scheduled for lead ID '.$log['lead_id']); |
||
30 | } |
||
31 | |||
32 | $logIds[] = $log['id']; |
||
33 | } |
||
34 | |||
35 | $this->runCommand('mautic:campaigns:execute', ['--scheduled-log-ids' => implode(',', $logIds)]); |
||
36 | |||
37 | // There should still be trhee events scheduled |
||
38 | $byEvent = $this->getCampaignEventLogs([2]); |
||
39 | $this->assertCount(3, $byEvent[2]); |
||
40 | |||
41 | foreach ($byEvent[2] as $log) { |
||
0 ignored issues
–
show
Comprehensibility
Bug
introduced
by
Loading history...
|
|||
42 | if (0 === (int) $log['is_scheduled']) { |
||
43 | $this->fail('Event is not scheduled for lead ID '.$log['lead_id']); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | // Pop off the last so we can test that only the two given are executed |
||
48 | $lastId = array_pop($logIds); |
||
49 | |||
50 | // Wait 20 seconds to go past scheduled time |
||
51 | sleep(20); |
||
52 | |||
53 | $this->runCommand('mautic:campaigns:execute', ['--scheduled-log-ids' => implode(',', $logIds)]); |
||
54 | |||
55 | // The events should have executed |
||
56 | $byEvent = $this->getCampaignEventLogs([2]); |
||
57 | $this->assertCount(3, $byEvent[2]); |
||
58 | |||
59 | foreach ($byEvent[2] as $log) { |
||
0 ignored issues
–
show
|
|||
60 | // Lasta |
||
61 | if ($log['id'] === $lastId) { |
||
62 | if (0 === (int) $log['is_scheduled']) { |
||
63 | $this->fail('Event is not scheduled when it should be for lead ID '.$log['lead_id']); |
||
64 | } |
||
65 | |||
66 | continue; |
||
67 | } |
||
68 | |||
69 | if (1 === (int) $log['is_scheduled']) { |
||
70 | $this->fail('Event is still scheduled for lead ID '.$log['lead_id']); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | putenv('CAMPAIGN_EXECUTIONER_SCHEDULER_ACKNOWLEDGE_SECONDS=0'); |
||
75 | } |
||
76 | } |
||
77 |