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

testCreateSecondPrimaryPhone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 13
loc 13
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
7
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
8
9
use OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactEntitiesData;
10
use OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactPhoneData;
11
12
/**
13
 * @outputBuffering enabled
14
 * @dbIsolation
15
 */
16
class RestContactPhoneApiTest extends WebTestCase
17
{
18
    protected function setUp()
19
    {
20
        $this->initClient([], $this->generateWsseAuthHeader());
21
        $this->loadFixtures([
22
            'OroCRM\Bundle\ContactBundle\Tests\Functional\DataFixtures\LoadContactPhoneData'
23
        ]);
24
    }
25
26 View Code Duplication
    public function testCreateContactPhone()
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...
27
    {
28
        $contact = $this->getReference('Contact_'. LoadContactEntitiesData::THIRD_ENTITY_NAME);
29
        $content = json_encode([
30
            'contactId' => $contact->getId(),
31
            'phone' => '111',
32
            'primary' => true
33
        ]);
34
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_phone'), [], [], [], $content);
35
        $contact = $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_CREATED);
36
37
        $this->assertArrayHasKey('id', $contact);
38
        $this->assertNotEmpty($contact['id']);
39
    }
40
41 View Code Duplication
    public function testCreateSecondPrimaryPhone()
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...
42
    {
43
        $contact = $this->getReference('Contact_'. LoadContactEntitiesData::THIRD_ENTITY_NAME);
44
45
        $content = json_encode([
46
            'contactId' => $contact->getId(),
47
            'phone' =>'[email protected]',
48
            'primary' => true
49
        ]);
50
51
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_phone'), [], [], [], $content);
52
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
53
    }
54
55 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...
56
    {
57
        $content = json_encode([
58
            'phone' =>'[email protected]',
59
            'primary' => true
60
        ]);
61
62
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_phone'), [], [], [], $content);
63
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
64
    }
65
66 View Code Duplication
    public function testEmptyPhone()
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...
67
    {
68
        $contact = $this->getReference('Contact_'. LoadContactEntitiesData::THIRD_ENTITY_NAME);
69
        $content = json_encode([
70
            'contactId' => $contact->getId(),
71
            'primary' => true
72
        ]);
73
74
        $this->client->request('POST', $this->getUrl('oro_api_post_contact_phone'), [], [], [], $content);
75
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_BAD_REQUEST);
76
    }
77
78 View Code Duplication
    public function testDeletePhoneForbidden()
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...
79
    {
80
        $contactPhone = $this->getReference('ContactPhone_Several_'. LoadContactPhoneData::FIRST_ENTITY_NAME);
81
        $routeParams = [
82
            'id' => $contactPhone->getId()
83
        ];
84
        $this->client->request('DELETE', $this->getUrl('oro_api_delete_contact_phone', $routeParams));
85
86
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_INTERNAL_SERVER_ERROR);
87
        $this->assertEquals(
88
            '{"code":500,"message":"oro.contact.phone.error.delete.more_one"}',
89
            $this->client->getResponse()->getContent()
90
        );
91
    }
92
93 View Code Duplication
    public function testDeletePhoneSuccess()
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...
94
    {
95
        $contactPhone = $this->getReference('ContactPhone_Single_'. LoadContactPhoneData::FIRST_ENTITY_NAME);
96
        $routeParams = [
97
            'id' => $contactPhone->getId()
98
        ];
99
        $this->client->request('DELETE', $this->getUrl('oro_api_delete_contact_phone', $routeParams));
100
101
        $this->getJsonResponseContent($this->client->getResponse(), Codes::HTTP_OK);
102
        $this->assertEquals('{"id":""}', $this->client->getResponse()->getContent());
103
    }
104
}
105