Completed
Push — master ( 0b658a...cae295 )
by
unknown
54:13
created

CallControllerTest::testGet()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 29
rs 8.8571
cc 1
eloc 17
nc 1
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\CallBundle\Tests\Functional\API\Rest;
4
5
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
6
7
/**
8
 * @outputBuffering enabled
9
 * @dbIsolation
10
 */
11
class CallControllerTest extends WebTestCase
12
{
13
    protected function setUp()
14
    {
15
        $this->initClient(array(), $this->generateWsseAuthHeader());
16
    }
17
18
    public function testCreate()
19
    {
20
        $request = [
21
            "call" => [
22
                "subject"      => 'Test Call ' . mt_rand(),
23
                "owner"        => '1',
24
                "duration"     => '00:00:05',
25
                "direction"    => 'outgoing',
26
                "callDateTime" => date('c'),
27
                "phoneNumber"  => '123-123=123',
28
                "callStatus"   => 'completed',
29
                "associations" => [
30
                    [
31
                        "entityName" => 'Oro\Bundle\UserBundle\Entity\User',
32
                        "entityId"   => 1,
33
                        "type"       => 'activity'
34
                    ],
35
                ]
36
            ]
37
        ];
38
        $this->client->request(
39
            'POST',
40
            $this->getUrl('oro_api_post_call'),
41
            $request
42
        );
43
44
        $result = $this->getJsonResponseContent($this->client->getResponse(), 201);
45
46
        $this->assertArrayHasKey('id', $result);
47
48
        $request['id'] = $result['id'];
49
        return $request;
50
    }
51
52
    /**
53
     * @param array $request
54
     * @depends testCreate
55
     */
56
    public function testGet(array $request)
57
    {
58
        $this->client->request(
59
            'GET',
60
            $this->getUrl('oro_api_get_calls')
61
        );
62
63
        $result = $this->getJsonResponseContent($this->client->getResponse(), 200);
64
65
        $id = $request['id'];
66
        $result = array_filter(
67
            $result,
68
            function ($a) use ($id) {
69
                return $a['id'] == $id;
70
            }
71
        );
72
73
        $this->assertNotEmpty($result);
74
        $this->assertEquals($request['call']['subject'], reset($result)['subject']);
75
76
        $this->client->request(
77
            'GET',
78
            $this->getUrl('oro_api_get_call', array('id' => $id))
79
        );
80
81
        $result = $this->getJsonResponseContent($this->client->getResponse(), 200);
82
83
        $this->assertEquals($request['call']['subject'], $result['subject']);
84
    }
85
86
    /**
87
     * @param array $request
88
     * @depends testCreate
89
     * @depends testGet
90
     */
91 View Code Duplication
    public function testUpdate(array $request)
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
        $request['call']['subject'] .= "_Updated";
94
        $this->client->request(
95
            'PUT',
96
            $this->getUrl('oro_api_put_call', array('id' => $request['id'])),
97
            $request
98
        );
99
        $result = $this->client->getResponse();
100
101
        $this->assertEmptyResponseStatusCodeEquals($result, 204);
102
103
        $this->client->request(
104
            'GET',
105
            $this->getUrl('oro_api_get_call', array('id' => $request['id']))
106
        );
107
108
        $result = $this->getJsonResponseContent($this->client->getResponse(), 200);
109
110
        $this->assertEquals(
111
            $request['call']['subject'],
112
            $result['subject']
113
        );
114
    }
115
116
    /**
117
     * @param array $request
118
     * @depends testCreate
119
     */
120
    public function testDelete(array $request)
121
    {
122
        $this->client->request(
123
            'DELETE',
124
            $this->getUrl('oro_api_delete_call', array('id' => $request['id']))
125
        );
126
        $result = $this->client->getResponse();
127
        $this->assertEmptyResponseStatusCodeEquals($result, 204);
128
        $this->client->request(
129
            'GET',
130
            $this->getUrl('oro_api_get_call', array('id' => $request['id']))
131
        );
132
        $result = $this->client->getResponse();
133
        $this->assertJsonResponseStatusCodeEquals($result, 404);
134
    }
135
}
136