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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.