Spaces:
No application file
No application file
File size: 4,512 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 |
<?php
namespace Mautic\CampaignBundle\Tests\Command;
use Mautic\CampaignBundle\Executioner\InactiveExecutioner;
use Mautic\CampaignBundle\Executioner\ScheduledExecutioner;
class ValidateEventCommandTest extends AbstractCampaignCommand
{
public function testEventsAreExecutedForInactiveEventWithSingleContact(): void
{
$this->testSymfonyCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-id' => 1]);
// Wait 6 seconds then execute the campaign again to send scheduled events
static::getContainer()->get(ScheduledExecutioner::class)->setNowTime(new \DateTime('+'.self::CONDITION_SECONDS.' seconds'));
$this->testSymfonyCommand('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 6 seconds to go beyond the inaction timeframe
static::getContainer()->get(InactiveExecutioner::class)->setNowTime(new \DateTime('+'.(self::CONDITION_SECONDS * 2).' seconds'));
// Now they should be inactive
$this->testSymfonyCommand('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(): void
{
$this->testSymfonyCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']);
// Wait 6 seconds then execute the campaign again to send scheduled events
static::getContainer()->get(ScheduledExecutioner::class)->setNowTime(new \DateTime('+'.self::CONDITION_SECONDS.' seconds'));
$this->testSymfonyCommand('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 6 seconds to go beyond the inaction timeframe
static::getContainer()->get(InactiveExecutioner::class)->setNowTime(new \DateTime('+'.(self::CONDITION_SECONDS * 2).' seconds'));
// Now they should be inactive
$this->testSymfonyCommand('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(): void
{
$this->testSymfonyCommand('mautic:campaigns:trigger', ['-i' => 1, '--contact-ids' => '1,2,3']);
// Wait 6 seconds then execute the campaign again to send scheduled events
static::getContainer()->get(ScheduledExecutioner::class)->setNowTime(new \DateTime('+'.self::CONDITION_SECONDS.' seconds'));
$this->testSymfonyCommand('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 6 seconds to go beyond the inaction timeframe
static::getContainer()->get(InactiveExecutioner::class)->setNowTime(new \DateTime('+'.(self::CONDITION_SECONDS * 2).' seconds'));
// Remove a contact from the campaign
$this->db->createQueryBuilder()->update(MAUTIC_TABLE_PREFIX.'campaign_leads')
->set('manually_removed', 1)
->where('lead_id = 1')
->executeStatement();
// Now they should be inactive
$this->testSymfonyCommand('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
}
}
|