1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\CoreBundle\Tests\Controller; |
13
|
|
|
|
14
|
|
|
use Lakion\ApiTestCase\JsonApiTestCase; |
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Joeri Timmermans <[email protected]> |
19
|
|
|
* @group joeri |
20
|
|
|
*/ |
21
|
|
|
class LocaleApiTest extends JsonApiTestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private static $authorizedHeaderWithContentType = [ |
27
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
28
|
|
|
'CONTENT_TYPE' => 'application/json', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private static $authorizedHeaderWithAccept = [ |
35
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
36
|
|
|
'ACCEPT' => 'application/json', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
public function testLocaleAccessDeniedResponse() |
40
|
|
|
{ |
41
|
|
|
$this->client->request('POST', '/api/locales/'); |
42
|
|
|
|
43
|
|
|
$response = $this->client->getResponse(); |
44
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGetLocalesListResponse() |
48
|
|
|
{ |
49
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
50
|
|
|
$this->loadFixturesFromFile('resources/locales.yml'); |
51
|
|
|
|
52
|
|
|
$this->client->request('GET', '/api/locales/', [], [], [ |
53
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
$response = $this->client->getResponse(); |
57
|
|
|
$this->assertResponse($response, 'locale/index_response', Response::HTTP_OK); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetLocaleResponse() |
61
|
|
|
{ |
62
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
63
|
|
|
$locales = $this->loadFixturesFromFile('resources/locales.yml'); |
64
|
|
|
|
65
|
|
|
$this->client->request('GET', '/api/locales/'.$locales['locale_en']->getId(), [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
66
|
|
|
|
67
|
|
|
$response = $this->client->getResponse(); |
68
|
|
|
$this->assertResponse($response, 'locale/show_response', Response::HTTP_OK); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testCreateLocaleValidationFailResponse() |
72
|
|
|
{ |
73
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
74
|
|
|
|
75
|
|
|
$this->client->request('POST', '/api/locales/', [], [], static::$authorizedHeaderWithContentType); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$response = $this->client->getResponse(); |
78
|
|
|
$this->assertResponse($response, 'locale/create_validation_fail_response', Response::HTTP_BAD_REQUEST); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testCreateLocaleResponse() |
82
|
|
|
{ |
83
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
84
|
|
|
|
85
|
|
|
$data = |
86
|
|
|
<<<EOT |
87
|
|
|
{ |
88
|
|
|
"code": "es" |
89
|
|
|
} |
90
|
|
|
EOT; |
91
|
|
|
|
92
|
|
|
$this->client->request('POST', '/api/locales/', [], [], static::$authorizedHeaderWithContentType, $data); |
|
|
|
|
93
|
|
|
|
94
|
|
|
$response = $this->client->getResponse(); |
95
|
|
|
|
96
|
|
|
$this->assertResponse($response, 'locale/create_response', Response::HTTP_CREATED); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testGetLocaleAccessDeniedResponse() |
100
|
|
|
{ |
101
|
|
|
$this->client->request('GET', '/api/locales/1'); |
102
|
|
|
|
103
|
|
|
$response = $this->client->getResponse(); |
104
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testGetLocaleWhichDoesNotExistResponse() |
108
|
|
|
{ |
109
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
110
|
|
|
|
111
|
|
|
$this->client->request('GET', '/api/locales/-1', [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
112
|
|
|
|
113
|
|
|
$response = $this->client->getResponse(); |
114
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testDeleteLocaleWhichDoesNotExistResponse() |
118
|
|
|
{ |
119
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
120
|
|
|
|
121
|
|
|
$this->client->request('DELETE', '/api/locales/-1', [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
122
|
|
|
|
123
|
|
|
$response = $this->client->getResponse(); |
124
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testDeleteLocaleResponse() |
128
|
|
|
{ |
129
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
130
|
|
|
$locales = $this->loadFixturesFromFile('resources/locales.yml'); |
131
|
|
|
|
132
|
|
|
$this->client->request('DELETE', '/api/locales/'.$locales['locale_en']->getId(), [], [], static::$authorizedHeaderWithContentType, []); |
|
|
|
|
133
|
|
|
|
134
|
|
|
$response = $this->client->getResponse(); |
135
|
|
|
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT); |
136
|
|
|
|
137
|
|
|
$this->client->request('GET', '/api/locales/'.$locales['locale_en']->getId(), [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
138
|
|
|
|
139
|
|
|
$response = $this->client->getResponse(); |
140
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: