|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ProxyControllerTest |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\ProxyBundle\Tests\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\TestBundle\Client; |
|
9
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* functional test for /3rdparty/{api} |
|
13
|
|
|
* |
|
14
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
15
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
16
|
|
|
* @link http://swisscom.ch |
|
17
|
|
|
*/ |
|
18
|
|
|
class ProxyControllerTest extends RestTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
const REQUEST_URL = "/3rdparty/petstore/v2/user"; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var Client |
|
27
|
|
|
*/ |
|
28
|
|
|
private $client; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \stdClass |
|
32
|
|
|
*/ |
|
33
|
|
|
private $testUser; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
private $headers; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @inheritDoc |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setUp() |
|
46
|
|
|
{ |
|
47
|
|
|
parent::setUp(); |
|
48
|
|
|
$this->client = static::createRestClient(); |
|
49
|
|
|
$this->headers = array( |
|
50
|
|
|
'Content_Type' => 'application/json', |
|
51
|
|
|
'Accept' => 'application/json', |
|
52
|
|
|
'Authorization' => 'special_key', |
|
53
|
|
|
); |
|
54
|
|
|
$this->testUser = new \stdClass(); |
|
55
|
|
|
$this->testUser->id = 123456; |
|
56
|
|
|
$this->testUser->username = "tester"; |
|
57
|
|
|
$this->testUser->firstName = "test"; |
|
58
|
|
|
$this->testUser->userStatus = 1; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* test post request with the proxy Action |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testPostProxyAction() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->client->request( |
|
70
|
|
|
'POST', |
|
71
|
|
|
self::REQUEST_URL, |
|
72
|
|
|
array(), |
|
73
|
|
|
array(), |
|
74
|
|
|
$this->headers, |
|
75
|
|
|
json_encode($this->testUser) |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$response = $this->client->getResponse(); |
|
79
|
|
|
$this->assertEquals('application/json', $response->headers->get("Content-Type")); |
|
80
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
81
|
|
|
$this->assertEmpty($response->getContent()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* test the proxy Action |
|
86
|
|
|
* |
|
87
|
|
|
* @depends testPostProxyAction |
|
88
|
|
|
* |
|
89
|
|
|
* @return void |
|
90
|
|
|
*/ |
|
91
|
|
|
public function testProxyAction() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->client->request( |
|
94
|
|
|
'GET', |
|
95
|
|
|
self::REQUEST_URL.'/'.$this->testUser->username, |
|
96
|
|
|
array(), |
|
97
|
|
|
array(), |
|
98
|
|
|
$this->headers |
|
99
|
|
|
); |
|
100
|
|
|
$response = $this->client->getResponse(); |
|
101
|
|
|
$content = json_decode($response->getContent()); |
|
102
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
103
|
|
|
$this->assertEquals($this->testUser, $content); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* test url encoding |
|
108
|
|
|
* |
|
109
|
|
|
* @depends testProxyAction |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
public function testDeleteProxyAction() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->client->request( |
|
116
|
|
|
'DELETE', |
|
117
|
|
|
self::REQUEST_URL.'/'.$this->testUser->username, |
|
118
|
|
|
array(), |
|
119
|
|
|
array(), |
|
120
|
|
|
$this->headers |
|
121
|
|
|
); |
|
122
|
|
|
$response = $this->client->getResponse(); |
|
123
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
124
|
|
|
$this->assertEmpty($response->getContent()); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|