Issues (3627)

Tests/Controller/CompanyControllerTest.php (3 issues)

1
<?php
2
3
namespace Mautic\LeadBundle\Tests\Controller;
4
5
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
6
use Mautic\LeadBundle\Entity\Company;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class CompanyControllerTest extends MauticMysqlTestCase
10
{
11
    private $id;
12
13
    protected function setUp(): void
14
    {
15
        parent::setUp();
16
17
        $companyData = [
18
            'name'     => 'Amazon',
19
            'state'    => 'Washington',
20
            'city'     => 'Seattle',
21
            'country'  => 'United States',
22
            'industry' => 'Goods',
23
        ];
24
25
        /** @var CompanyModel $model */
26
        $model      = $this->container->get('mautic.lead.model.company');
27
        $company    = new Company();
28
        $company->setIsPublished(true)
29
            ->setName($companyData['name'])
30
            ->setState($companyData['state'])
31
            ->setCity($companyData['city'])
32
            ->setCountry($companyData['country'])
33
            ->setIndustry($companyData['industry']);
34
        $model->saveEntity($company);
35
        $this->id = $company->getId();
36
    }
37
38
    /**
39
     * Get company's view page.
40
     */
41
    public function testViewActionCompany(): void
42
    {
43
        $this->client->request('GET', '/s/companies/view/'.$this->id);
44
        $clientResponse         = $this->client->getResponse();
45
        $clientResponseContent  = $clientResponse->getContent();
46
        $model                  = $this->container->get('mautic.lead.model.company');
47
        $company                = $model->getEntity($this->id);
48
        $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
49
        $this->assertStringContainsString($company->getName(), $clientResponseContent, 'The return must contain the name of company');
50
    }
51
52
    /**
53
     * Get company's edit page.
54
     */
55
    public function testEditActionCompany(): void
56
    {
57
        $this->client->request('GET', '/s/companies/edit/'.$this->id);
58
        $clientResponse         = $this->client->getResponse();
59
        $clientResponseContent  = $clientResponse->getContent();
60
        $model                  = $this->container->get('mautic.lead.model.company');
61
        $company                = $model->getEntity($this->id);
62
        $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
63
        $this->assertStringContainsString('Edit Company '.$company->getName(), $clientResponseContent, 'The return must contain \'Edit Company\' text');
64
    }
65
66
    /* Get company contacts list */
67
    public function testListCompanyContacts(): void
68
    {
69
        $this->client->request('GET', 's/company/'.$this->id.'/contacts/');
70
        $clientResponse         = $this->client->getResponse();
71
        $clientResponseContent  = $clientResponse->getContent();
0 ignored issues
show
The assignment to $clientResponseContent is dead and can be removed.
Loading history...
72
        $model                  = $this->container->get('mautic.lead.model.company');
73
        $company                = $model->getEntity($this->id);
0 ignored issues
show
The assignment to $company is dead and can be removed.
Loading history...
74
        $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
75
    }
76
77
    /**
78
     * Get company's create page.
79
     */
80
    public function testNewActionCompany(): void
81
    {
82
        $this->client->request('GET', '/s/companies/new/');
83
        $clientResponse         = $this->client->getResponse();
84
        $clientResponseContent  = $clientResponse->getContent();
0 ignored issues
show
The assignment to $clientResponseContent is dead and can be removed.
Loading history...
85
        $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
86
    }
87
}
88