/
ValidateEventCommandTest.php
94 lines (73 loc) · 3.72 KB
/
ValidateEventCommandTest.php
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
93
94
<?php
/*
* @copyright 2018 Mautic Contributors. All rights reserved
* @author Mautic, Inc.
*
* @link https://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
namespace Mautic\CampaignBundle\Tests\Command;
class ValidateEventCommandTest extends AbstractCampaignCommand
{
public function testEventsAreExecutedForInactiveEventWithSingleContact()
{
$this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-id' => 1]);
// Wait 20 seconds then execute the campaign again to send scheduled events
sleep(20);
$this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-id' => 1]);
// No open email decisions should be recorded yet
$byEvent = $this->getCampaignEventLogs([3]);
$this->assertCount(0, $byEvent[3]);
// Wait 20 seconds to go beyond the inaction timeframe
sleep(20);
// Now they should be inactive
$this->runCommand('mautic:campaigns:validate', ['--decision-id' => 3, '--contact-id' => 1]);
$byEvent = $this->getCampaignEventLogs([3, 7, 10]);
$this->assertCount(1, $byEvent[3]); // decision recorded
$this->assertCount(1, $byEvent[7]); // inactive event executed
$this->assertCount(0, $byEvent[10]); // the positive path should be 0
}
public function testEventsAreExecutedForInactiveEventWithMultipleContact()
{
$this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']);
// Wait 20 seconds then execute the campaign again to send scheduled events
sleep(20);
$this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']);
// No open email decisions should be recorded yet
$byEvent = $this->getCampaignEventLogs([3]);
$this->assertCount(0, $byEvent[3]);
// Wait 20 seconds to go beyond the inaction timeframe
sleep(20);
// Now they should be inactive
$this->runCommand('mautic:campaigns:validate', ['--decision-id' => 3, '--contact-ids' => '1,2,3']);
$byEvent = $this->getCampaignEventLogs([3, 7, 10]);
$this->assertCount(3, $byEvent[3]); // decision recorded
$this->assertCount(3, $byEvent[7]); // inactive event executed
$this->assertCount(0, $byEvent[10]); // the positive path should be 0
}
public function testContactsRemovedFromTheCampaignAreNotExecutedForInactiveEvents()
{
$this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']);
// Wait 20 seconds then execute the campaign again to send scheduled events
sleep(20);
$this->runCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']);
// No open email decisions should be recorded yet
$byEvent = $this->getCampaignEventLogs([3]);
$this->assertCount(0, $byEvent[3]);
// Wait 20 seconds to go beyond the inaction timeframe
sleep(20);
// Remove a contact from the campaign
$this->db->createQueryBuilder()->update(MAUTIC_TABLE_PREFIX.'campaign_leads')
->set('manually_removed', 1)
->where('lead_id = 1')
->execute();
// Now they should be inactive
$this->runCommand('mautic:campaigns:validate', ['--decision-id' => 3, '--contact-ids' => '1,2,3']);
// Only two contacts should have been considered inactive because one was marked as manually removed
$byEvent = $this->getCampaignEventLogs([3, 7, 10]);
$this->assertCount(2, $byEvent[3]); // decision recorded
$this->assertCount(2, $byEvent[7]); // inactive event executed
$this->assertCount(0, $byEvent[10]); // the positive path should be 0
}
}