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

declare(strict_types=1);

namespace Mautic\LeadBundle\Tests\Entity;

use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Entity\LeadList;
use Mautic\LeadBundle\Entity\ListLead;
use Mautic\LeadBundle\Entity\ListLeadRepository;

final class ListLeadRepositoryTest extends MauticMysqlTestCase
{
    private ListLeadRepository $listLeadRepository;

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

        $this->listLeadRepository = static::getContainer()->get(ListLeadRepository::class);
    }

    public function testGetContactsCountBySegment(): void
    {
        $filters       = ['manually_removed' => 0];
        $contact       = new Lead();
        $segment       = new LeadList();
        $segmentMember = new ListLead();

        $segment->setName('A segment');
        $segment->setPublicName('A segment');
        $segment->setAlias('asegment');

        $segmentMember->setLead($contact);
        $segmentMember->setList($segment);
        $segmentMember->setManuallyRemoved(false);
        $segmentMember->setDateAdded(new \DateTime());

        $this->em->persist($contact);
        $this->em->persist($segment);
        $this->em->persist($segmentMember);
        $this->em->flush();

        $this->assertSame(1, $this->listLeadRepository->getContactsCountBySegment($segment->getId(), $filters));

        $segmentMember->setManuallyRemoved(true);
        $this->em->persist($segmentMember);
        $this->em->flush();

        $this->assertSame(0, $this->listLeadRepository->getContactsCountBySegment($segment->getId(), $filters));
    }
}