File size: 2,606 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
90
91
92
93
94
95
96
97
98
99
100
<?php

declare(strict_types=1);

namespace Mautic\LeadBundle\Tests\Controller;

use Doctrine\ORM\Exception\ORMException;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\LeadBundle\Entity\Lead;
use PHPUnit\Framework\Assert;

final class LeadControllerListingPageTest extends MauticMysqlTestCase
{
    protected function setUp(): void
    {
        $this->configParams['contact_columns'] = ['name', 'location', 'email'];

        parent::setUp();
    }

    /**
     * @param string[] $location
     *
     * @dataProvider dataForContactListing
     *
     * @throws ORMException
     */
    public function testContactListingForLocation(array $location, string $expected): void
    {
        $this->createContact($location);

        $crawler    = $this->client->request('GET', 's/contacts');
        $rowContent = $crawler->filterXPath("//table[@id='leadTable']//tbody//tr");

        Assert::assertStringEndsWith($expected, $rowContent->text());
    }

    /**
     * @return iterable<string, array<int, string|string[]>>
     */
    public function dataForContactListing(): iterable
    {
        yield 'With no location' => [
            // Location Details
            [
                'setCity'    => '',
                'setState'   => '',
                'setCountry' => '',
            ],
            // Expected suffice
            'John Doe [email protected]',
        ];

        yield 'With whole location details' => [
            // Location Details
            [
                'setCity'    => 'Pune',
                'setState'   => 'MH',
                'setCountry' => 'India',
            ],
            // Expected suffice
            'John Doe Pune, MH [email protected]',
        ];

        yield 'With only City for location' => [
            // Location Details
            [
                'setCity'    => 'Pune',
                'setState'   => '',
                'setCountry' => '',
            ],
            // Expected suffice
            'John Doe Pune [email protected]',
        ];
    }

    /**
     * @param string[] $location
     *
     * @throws ORMException
     */
    private function createContact(array $location = []): void
    {
        $contact = new Lead();
        $contact->setFirstname('John');
        $contact->setLastname('Doe');
        $contact->setEmail('[email protected]');

        foreach ($location as $name => $value) {
            if (empty($value)) {
                continue;
            }
            $contact->$name($value);
        }

        $this->em->persist($contact);
        $this->em->flush();
    }
}