|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* functional test for /core/config |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\CoreBundle\Tests\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Basic functional test for /core/config. |
|
12
|
|
|
* |
|
13
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
14
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
15
|
|
|
* @link http://swisscom.ch |
|
16
|
|
|
*/ |
|
17
|
|
|
class ConfigControllerTest extends RestTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* setup client and load fixtures |
|
22
|
|
|
* |
|
23
|
|
|
* @return void |
|
24
|
|
|
*/ |
|
25
|
|
|
public function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->loadFixtures( |
|
28
|
|
|
array( |
|
29
|
|
|
'GravitonDyn\ConfigBundle\DataFixtures\MongoDB\LoadConfigData' |
|
30
|
|
|
), |
|
31
|
|
|
null, |
|
32
|
|
|
'doctrine_mongodb' |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* We need to make sure that our Link headers are properly encoded for our RQL parser. |
|
38
|
|
|
* This test tries to ensure that as we have resources named-like-this in /core/config. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $expression expression |
|
41
|
|
|
* @param int $resultCount expected res count |
|
42
|
|
|
* |
|
43
|
|
|
* @dataProvider rqlCheckDataProvider |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testLinkHeaderEncodingDash($expression, $resultCount) |
|
48
|
|
|
{ |
|
49
|
|
|
$client = static::createRestClient(); |
|
50
|
|
|
$_SERVER['QUERY_STRING'] = $expression; |
|
51
|
|
|
$client->request('GET', '/core/config?'.$expression); |
|
52
|
|
|
unset($_SERVER['QUERY_STRING']); |
|
53
|
|
|
$response = $client->getResponse(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertContains($expression, $response->headers->get('Link')); |
|
56
|
|
|
$this->assertEquals($resultCount, count($client->getResults())); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Data provider for self-Link-header check |
|
61
|
|
|
* |
|
62
|
|
|
* @return array data |
|
|
|
|
|
|
63
|
|
|
*/ |
|
64
|
|
|
public function rqlCheckDataProvider() |
|
65
|
|
|
{ |
|
66
|
|
|
return array( |
|
67
|
|
|
array( |
|
68
|
|
|
'eq(id'.$this->encodeString(',tablet-hello-message').')', |
|
69
|
|
|
1 |
|
70
|
|
|
), |
|
71
|
|
|
array( |
|
72
|
|
|
'eq(id'.$this->encodeString(',admin-additional+setting').')', |
|
73
|
|
|
1 |
|
74
|
|
|
), |
|
75
|
|
|
array( |
|
76
|
|
|
'like(key'.$this->encodeString(',hello-').'*)', |
|
77
|
|
|
1 |
|
78
|
|
|
) |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Encodes our expressions |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $value value |
|
86
|
|
|
* |
|
87
|
|
|
* @return string encoded value |
|
88
|
|
|
*/ |
|
89
|
|
|
private function encodeString($value) |
|
90
|
|
|
{ |
|
91
|
|
|
return str_replace( |
|
92
|
|
|
array('-', '_', '.', '~'), |
|
93
|
|
|
array('%2D', '%5F', '%2E', '%7E'), |
|
94
|
|
|
rawurlencode($value) |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
/** |
|
98
|
|
|
* ensure we have nice parse error output in rql parse failure |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
|
View Code Duplication |
public function testRqlSyntaxForUrlError() |
|
103
|
|
|
{ |
|
104
|
|
|
$client = static::createRestClient(); |
|
105
|
|
|
|
|
106
|
|
|
$client->request('GET', '/core/config/?eq(app.$ref,string:http://localhost:8000/core/app/admin)'); |
|
107
|
|
|
|
|
108
|
|
|
$response = $client->getResponse(); |
|
109
|
|
|
$results = $client->getResults(); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertEquals(200, $response->getStatusCode()); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertEquals(2, count($results)); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.