1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenOrchestra\FunctionalTests\ApiBundle\Controller; |
4
|
|
|
|
5
|
|
|
use OpenOrchestra\FunctionalTests\Utils\AbstractAuthenticatedTest; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ApiControllersTest |
9
|
|
|
* |
10
|
|
|
* @group apiFunctional |
11
|
|
|
*/ |
12
|
|
|
class ApiControllersTest extends AbstractAuthenticatedTest |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* test duplicate Api |
17
|
|
|
* |
18
|
|
|
* |
19
|
|
|
* @dataProvider provideDuplicateApiElements |
20
|
|
|
*/ |
21
|
|
|
public function testDuplicateApi($repositoryName, $method, $value, $type, $url) |
22
|
|
|
{ |
23
|
|
|
$repository = static::$kernel->getContainer()->get($repositoryName); |
24
|
|
|
$source = $repository->$method($value); |
25
|
|
|
$source = static::$kernel->getContainer()->get('open_orchestra_api.transformer_manager')->get($type)->transform($source); |
26
|
|
|
$source = static::$kernel->getContainer()->get('jms_serializer')->serialize( |
27
|
|
|
$source, |
28
|
|
|
'json' |
29
|
|
|
); |
30
|
|
|
$this->client->request("POST", $url, array(), array(), array(), $source); |
31
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
32
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
33
|
|
|
|
34
|
|
|
$element = $repository->$method(new \MongoRegex('/^'.$value.'_.*$/')); |
35
|
|
|
while (!is_null($element)) { |
36
|
|
|
static::$kernel->getContainer()->get('object_manager')->remove($element); |
37
|
|
|
static::$kernel->getContainer()->get('object_manager')->flush(); |
38
|
|
|
$element = $repository->$method(new \MongoRegex('/^'.$value.'_.*$/')); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function provideDuplicateApiElements() |
46
|
|
|
{ |
47
|
|
|
return array( |
48
|
|
|
0 => array('open_orchestra_user.repository.group', 'findOneByName', 'Demo group', 'group', '/api/group/duplicate'), |
49
|
|
|
1 => array('open_orchestra_model.repository.content', 'findOneByContentId', '206_3_portes', 'content', '/api/content/duplicate'), |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $url |
55
|
|
|
* @param string $getParameter |
56
|
|
|
* |
57
|
|
|
* @dataProvider provideApiUrl |
58
|
|
|
*/ |
59
|
|
|
public function testApi($url, $getParameter = '', $method = 'GET') |
60
|
|
|
{ |
61
|
|
|
$baseGetParameter = '?access_token=' . $this->getAccessToken(); |
62
|
|
|
$this->client->request($method, $url . $baseGetParameter . $getParameter); |
63
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
64
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
|
|
public function provideApiUrl() |
71
|
|
|
{ |
72
|
|
|
return array( |
73
|
|
|
1 => array('/api/node/root/show-or-create'), |
74
|
|
|
2 => array('/api/node/root/show-or-create', '&language=en'), |
75
|
|
|
3 => array('/api/node/fixture_page_community/show-or-create'), |
76
|
|
|
4 => array('/api/node/fixture_page_community/show-or-create', '&language=en'), |
77
|
|
|
5 => array('/api/node/list/not-published-by-author'), |
78
|
|
|
6 => array('/api/node/list/by-author'), |
79
|
|
|
7 => array('/api/node/list/2/fr'), |
80
|
|
|
8 => array('/api/block/list/shared/fr'), |
81
|
|
|
//8 => array('/api/content'), |
|
|
|
|
82
|
|
|
9 => array('/api/content/list/by-author'), |
83
|
|
|
10 => array('/api/content/list/not-published-by-author'), |
84
|
|
|
//11 => array('/api/content', '&content_type=news'), |
|
|
|
|
85
|
|
|
12 => array('/api/content-type'), |
86
|
|
|
13 => array('/api/site'), |
87
|
|
|
14 => array('/api/site/list/available'), |
88
|
|
|
// 15 => array('/api/theme'), |
|
|
|
|
89
|
|
|
17 => array('/api/group/delete-multiple', '', 'DELETE'), |
90
|
|
|
//18 => array('/api/redirection'), |
|
|
|
|
91
|
|
|
//19 => array('/api/status'), |
|
|
|
|
92
|
|
|
//20 => array('/api/status/list'), |
|
|
|
|
93
|
|
|
// 22 => array('/api/trashcan/list'), |
|
|
|
|
94
|
|
|
23 => array('/api/translation/tinymce'), |
95
|
|
|
24 => array('/api/node/list/tree/2/fr'), |
96
|
|
|
25 => array('/api/node/list/tree/2/fr/root'), |
97
|
|
|
26 => array('/api/group/user/list'), |
98
|
|
|
27 => array('/api/group/list'), |
99
|
|
|
28 => array('/api/block/list/block-component'), |
100
|
|
|
29 => array('/api/content-type/content/content-type-list'), |
101
|
|
|
30 => array('/api/content/delete-multiple', '', 'DELETE'), |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.