Completed
Push — master ( 3560db...6e658b )
by
unknown
08:14
created

testCreateSecondPrimaryEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 12
loc 12
rs 9.4286
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\ContactBundle\Tests\Functional\API;
4
5
use FOS\RestBundle\Util\Codes;
6
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
7
use OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEmailData;
8
use OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEntitiesData;
9
10
/**
11
 * @outputBuffering enabled
12
 * @dbIsolation
13
 */
14
class RestContactEmailApiTest extends WebTestCase
15
{
16
    protected function setUp()
17
    {
18
        $this->initClient([], $this->generateWsseAuthHeader());
19
        $this->loadFixtures([
20
            'OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEmailData'
21
        ]);
22
    }
23
24 View Code Duplication
    public function testCreateContactEmail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $contact = $this->getReference('Contact_' . LoadContactEntitiesData::THIRD_ENTITY_NAME);
27
        $content = json_encode([
28
            'contactId' => $contact->getId(),
29
            'email' =>'[email protected]',
30
            'primary' => true
31
        ]);
32
33
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_email'), [], [], [], $content);
34
        $contact = $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_CREATED);
35
36
        $this->assertArrayHasKey('id', $contact);
37
        $this->assertNotEmpty($contact['id']);
38
    }
39
40 View Code Duplication
    public function testCreateSecondPrimaryEmail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $contact = $this->getReference('Contact_Brenda');
43
        $content = json_encode([
44
            'contactId' => $contact->getId(),
45
            'email' =>'[email protected]',
46
            'primary' => true
47
        ]);
48
49
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_email'), [], [], [], $content);
50
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
51
    }
52
53 View Code Duplication
    public function testEmptyContactId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $content = json_encode([
56
            'email' =>'[email protected]',
57
            'primary' => true
58
        ]);
59
60
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_email'), [], [], [], $content);
61
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
62
    }
63
64 View Code Duplication
    public function testEmptyEmail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $contact = $this->getReference('Contact_Brenda');
67
        $content = json_encode([
68
            'contactId' => $contact->getId(),
69
            'primary' => true
70
        ]);
71
72
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_email'), [], [], [], $content);
73
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
74
    }
75
76 View Code Duplication
    public function testDeleteEmailForbidden()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        $contactEmail = $this->getReference('ContactEmail_Several_'. LoadContactEmailData::FIRST_ENTITY_NAME);
79
        $routeParams = [
80
            'id' => $contactEmail->getId()
81
        ];
82
        $this->client->request('DELETE', $this->getUrl('oro_api_delete_contact_email', $routeParams));
83
84
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_INTERNAL_SERVER_ERROR);
85
        $this->assertEquals(
86
            '{"code":500,"message":"oro.contact.email.error.delete.more_one"}',
87
            $this->client->getResponse()->getContent()
88
        );
89
    }
90
91 View Code Duplication
    public function testDeleteEmailSuccess()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93
        $contactEmail = $this->getReference('ContactEmail_Single_'. LoadContactEmailData::FIRST_ENTITY_NAME);
94
        $routeParams = [
95
            'id' => $contactEmail->getId()
96
        ];
97
        $this->client->request('DELETE', $this->getUrl('oro_api_delete_contact_email', $routeParams));
98
99
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_OK);
100
        $this->assertEquals('{"id":""}', $this->client->getResponse()->getContent());
101
    }
102
}
103