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
|
|
|
public function testDuplicateContentApi() |
19
|
|
|
{ |
20
|
|
|
$repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.content'); |
21
|
|
|
$source = $repository->findOneByContentId('206_3_portes'); |
22
|
|
|
$source = static::$kernel->getContainer()->get('open_orchestra_api.transformer_manager')->get('content')->transform($source); |
23
|
|
|
$source = static::$kernel->getContainer()->get('jms_serializer')->serialize( |
24
|
|
|
$source, |
25
|
|
|
'json' |
26
|
|
|
); |
27
|
|
|
$this->client->request("POST", '/api/content/duplicate', array(), array(), array(), $source); |
28
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
29
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
30
|
|
|
|
31
|
|
|
$element = $repository->findOneByContentId(new \MongoRegex('/^206_3_portes_.*$/')); |
32
|
|
|
while (!is_null($element)) { |
33
|
|
|
static::$kernel->getContainer()->get('object_manager')->remove($element); |
34
|
|
|
static::$kernel->getContainer()->get('object_manager')->flush(); |
35
|
|
|
$element = $repository->findOneByContentId(new \MongoRegex('/^206_3_portes_.*$/')); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* test duplicate Api |
41
|
|
|
*/ |
42
|
|
|
public function testDuplicateGroupApi() |
43
|
|
|
{ |
44
|
|
|
$repository = static::$kernel->getContainer()->get('open_orchestra_user.repository.group'); |
45
|
|
|
$dm = static::$kernel->getContainer()->get('object_manager'); |
46
|
|
|
|
47
|
|
|
$source = $repository->findOneBy(array('labels.en' => 'Demo group')); |
48
|
|
|
$source = static::$kernel->getContainer()->get('open_orchestra_api.transformer_manager')->get('group')->transform($source); |
49
|
|
|
$source = static::$kernel->getContainer()->get('jms_serializer')->serialize( |
50
|
|
|
$source, |
51
|
|
|
'json' |
52
|
|
|
); |
53
|
|
|
$this->client->request("POST", '/api/group/duplicate', array(), array(), array(), $source); |
54
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
55
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
56
|
|
|
|
57
|
|
|
$source = json_decode($source, true); |
58
|
|
|
$groups = $repository->createQueryBuilder() |
59
|
|
|
->field('labels.en')->equals('Demo group') |
60
|
|
|
->field('_id')->notEqual(new \MongoId($source['id'])) |
61
|
|
|
->getQuery() |
62
|
|
|
->execute(); |
63
|
|
|
foreach ($groups as $group){ |
64
|
|
|
$dm->remove($group); |
65
|
|
|
} |
66
|
|
|
$dm->flush(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $url |
71
|
|
|
* @param string $getParameter |
72
|
|
|
* @param string $method |
73
|
|
|
* |
74
|
|
|
* @dataProvider provideApiUrl |
75
|
|
|
*/ |
76
|
|
|
public function testApi($url, $getParameter = '', $method = 'GET') |
77
|
|
|
{ |
78
|
|
|
$baseGetParameter = '?access_token=' . $this->getAccessToken(); |
79
|
|
|
$this->client->request($method, $url . $baseGetParameter . $getParameter); |
80
|
|
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
81
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type')); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public function provideApiUrl() |
88
|
|
|
{ |
89
|
|
|
return array( |
90
|
|
|
1 => array('/api/node/show/root/2/fr'), |
91
|
|
|
5 => array('/api/node/list/not-published-by-author'), |
92
|
|
|
6 => array('/api/node/list/by-author'), |
93
|
|
|
7 => array('/api/node/list/2/fr'), |
94
|
|
|
8 => array('/api/block/list/shared/fr'), |
95
|
|
|
9 => array('/api/content/list/by-author'), |
96
|
|
|
10 => array('/api/content/list/not-published-by-author'), |
97
|
|
|
12 => array('/api/content-type'), |
98
|
|
|
13 => array('/api/site'), |
99
|
|
|
14 => array('/api/site/list/available'), |
100
|
|
|
17 => array('/api/group/delete-multiple', '', 'DELETE'), |
101
|
|
|
18 => array('/api/redirection/delete-multiple', '', 'DELETE'), |
102
|
|
|
19 => array('/api/status'), |
103
|
|
|
20 => array('/api/status/list'), |
104
|
|
|
24 => array('/api/node/list/tree/2/fr'), |
105
|
|
|
25 => array('/api/node/list/tree/2/fr/root'), |
106
|
|
|
26 => array('/api/group/user/list'), |
107
|
|
|
27 => array('/api/group/list'), |
108
|
|
|
28 => array('/api/block/list/block-component'), |
109
|
|
|
29 => array('/api/content-type/content/content-type-list'), |
110
|
|
|
30 => array('/api/content/delete-multiple', '', 'DELETE'), |
111
|
|
|
31 => array('/api/keyword/delete-multiple', '', "DELETE"), |
112
|
|
|
32 => array('/api/keyword'), |
113
|
|
|
33 => array('/api/node/list/with-block-in-area/root/2/header'), |
114
|
|
|
34 => array('/api/content/list-version/r5_3_portes/fr'), |
115
|
|
|
35 => array('/api/content/delete-multiple-version', '', 'DELETE'), |
116
|
|
|
36 => array('/api/content/new-version/r5_3_portes/fr/2', '', 'POST'), |
117
|
|
|
37 => array('/api/node/new-version/root/fr/1', '', 'POST'), |
118
|
|
|
38 => array('/api/node/list-version/root/fr'), |
119
|
|
|
39 => array('/api/node/delete-multiple-version', '', 'DELETE'), |
120
|
|
|
40 => array('/api/content-type'), |
121
|
|
|
41 => array('/api/content-type/news'), |
122
|
|
|
42 => array('/api/content-type/content/content-type-list'), |
123
|
|
|
43 => array('/api/trashcan/list'), |
124
|
|
|
44 => array('/api/trashcan/delete-multiple', '', "DELETE"), |
125
|
|
|
45 => array('/api/content/show/lorem_ipsum/fr'), |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|