1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use Silex\WebTestCase; |
6
|
|
|
|
7
|
|
|
class WorkspaceTest extends WebTestCase |
8
|
|
|
{ |
9
|
|
|
use AbstractAppTest; |
10
|
|
|
|
11
|
|
|
/*Verifico che il Workspace si possa scaricare correttamente*/ |
12
|
|
View Code Duplication |
public function testGetWorkSpace() { |
|
|
|
|
13
|
|
|
$schema = __DIR__.'/../../../../api/schemas/workspace.json'; |
14
|
|
|
|
15
|
|
|
$client = $this->createClient(); |
16
|
|
|
$client = $this->logIn($client); |
17
|
|
|
|
18
|
|
|
$id = $this->testPostWorkspace(); |
19
|
|
|
|
20
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/'.$id); |
|
|
|
|
21
|
|
|
$response = $client->getResponse(); |
|
|
|
|
22
|
|
|
$data = $client->getResponse()->getContent(); |
23
|
|
|
$validator = $this->askValidation($data, $schema); |
24
|
|
|
|
25
|
|
|
$assert = $this->evalValidation($validator); |
26
|
|
|
$this->assertTrue($assert); |
27
|
|
|
|
28
|
|
|
return $data; |
29
|
|
|
} |
30
|
|
|
/*Verifico che l'elenco dei workspace si possa scaricare correttamente*/ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function testGetWorkspaceList(){ |
|
|
|
|
36
|
|
|
$schema = __DIR__.'/../../../../api/schemas/workspaceList.json'; |
37
|
|
|
|
38
|
|
|
$client = $this->createClient(); |
39
|
|
|
$client = $this->logIn($client); |
40
|
|
|
|
41
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/'); |
|
|
|
|
42
|
|
|
$response = $client->getResponse(); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$data = $client->getResponse()->getContent(); |
45
|
|
|
$validator = $this->askValidation($data, $schema); |
46
|
|
|
|
47
|
|
|
$assert = $this->evalValidation($validator); |
48
|
|
|
$this->assertTrue($assert); |
49
|
|
|
return $data; |
50
|
|
|
} |
51
|
|
|
/*verifico che si possa condividere il workspace */ |
52
|
|
View Code Duplication |
public function testGetWorkspaceShare() { |
|
|
|
|
53
|
|
|
$schema = __DIR__.'/../../../../api/schemas/workspaceShare.json'; |
54
|
|
|
|
55
|
|
|
$client = $this->createClient(); |
56
|
|
|
$client = $this->logIn($client); |
57
|
|
|
|
58
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/1/share'); |
|
|
|
|
59
|
|
|
$response = $client->getResponse(); |
|
|
|
|
60
|
|
|
|
61
|
|
|
//print_r($response); |
62
|
|
|
$data = $client->getResponse()->getContent(); |
63
|
|
|
$validator = $this->askValidation($data, $schema); |
64
|
|
|
|
65
|
|
|
$assert = $this->evalValidation($validator); |
66
|
|
|
$this->assertTrue($assert); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testPostWorkspace() { |
70
|
|
|
//$schema = __DIR__.'/../../../../api/schemas/workspace.json'; |
|
|
|
|
71
|
|
|
|
72
|
|
|
$client = $this->createClient(); |
73
|
|
|
$client = $this->logIn($client); |
74
|
|
|
|
75
|
|
|
$wp = '{ |
76
|
|
|
"title":"Sopraelevata", |
77
|
|
|
"description":"I Sarchiaponi sono pronti a lanciarsi nella costruzione di una sopraelevata", |
78
|
|
|
"environment": 22, |
79
|
|
|
"team": { |
80
|
|
|
"patrol":"Sarchiaponi", |
81
|
|
|
"group":"Bologna 18", |
82
|
|
|
"unit": "Marco Polo" |
83
|
|
|
}, |
84
|
|
|
"badges": [ 5, 38, 99] |
85
|
|
|
}'; |
86
|
|
|
|
87
|
|
|
$client->request( |
88
|
|
|
'POST', |
89
|
|
|
'/api/v1/workspace/', |
90
|
|
|
[], |
91
|
|
|
[], |
92
|
|
|
['CONTENT_TYPE' => 'application/json'], |
93
|
|
|
$wp); |
94
|
|
|
|
95
|
|
|
$response = $client->getResponse(); |
|
|
|
|
96
|
|
|
|
97
|
|
|
$data = $client->getResponse()->getContent(); |
98
|
|
|
$id = json_decode($data); |
99
|
|
|
|
100
|
|
|
$id = $id->id; |
101
|
|
|
|
102
|
|
|
$this->assertTrue(is_numeric($id)); |
103
|
|
|
|
104
|
|
|
return $id; |
105
|
|
|
} |
106
|
|
|
public function testPutWorkspace() { |
107
|
|
|
//$schema = __DIR__.'/../../../../api/schemas/workspace.json'; |
|
|
|
|
108
|
|
|
|
109
|
|
|
$id = $this->testPostWorkspace(); |
110
|
|
|
$wp = '{ |
111
|
|
|
"id":'.$id.', |
112
|
|
|
"title":"Sopraelevata_EDIT", |
113
|
|
|
"description":"I Sarchiaponi sono pronti a lanciarsi nella costruzione di una sopraelevata", |
114
|
|
|
"environment": 25, |
115
|
|
|
"team": { |
116
|
|
|
"patrol":"Sarchiaponini", |
117
|
|
|
"group":"Bologna 17", |
118
|
|
|
"unit": "Marco Polo2" |
119
|
|
|
}, |
120
|
|
|
"badges": [ 5, 38, 99] |
121
|
|
|
}'; |
122
|
|
|
|
123
|
|
|
$client = $this->createClient(); |
124
|
|
|
$client = $this->logIn($client); |
125
|
|
|
|
126
|
|
|
//print_r("\nID: ".$id."\n"); |
|
|
|
|
127
|
|
|
$client->request( |
128
|
|
|
'PUT', |
129
|
|
|
'/api/v1/workspace/'.$id.'', |
130
|
|
|
[], |
131
|
|
|
[], |
132
|
|
|
['CONTENT_TYPE' => 'application/json'], |
133
|
|
|
$wp); |
134
|
|
|
|
135
|
|
|
$response = $client->getResponse(); |
136
|
|
|
print($response); |
137
|
|
|
//$data = $client->getResponse()->getContent(); |
|
|
|
|
138
|
|
|
//$id = json_decode($data); |
|
|
|
|
139
|
|
|
|
140
|
|
|
//$id=$id->id; |
|
|
|
|
141
|
|
|
|
142
|
|
|
$this->assertTrue($response->isOk()); |
143
|
|
|
} |
144
|
|
|
public function testDeleteWorkspace() { |
145
|
|
|
//$schema = __DIR__.'/../../../../api/schemas/workspace.json'; |
|
|
|
|
146
|
|
|
$id = $this->testPostWorkspace(); |
147
|
|
|
$client = $this->createClient(); |
148
|
|
|
$client = $this->logIn($client); |
149
|
|
|
|
150
|
|
|
$client->request( |
151
|
|
|
'DELETE', |
152
|
|
|
'/api/v1/workspace/'.$id.'', |
153
|
|
|
[], |
154
|
|
|
[], |
155
|
|
|
[], |
156
|
|
|
''); |
157
|
|
|
|
158
|
|
|
$response = $client->getResponse(); |
159
|
|
|
$this->assertTrue($response->isOk()); |
160
|
|
|
|
161
|
|
|
$data = $this->testGetWorkspaceList(); |
162
|
|
|
$js = json_decode($data); |
163
|
|
|
$trovato = false; |
164
|
|
|
foreach ($js as $w) { |
165
|
|
|
if ($w->id === $id) { |
166
|
|
|
$trovato = true; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
$this->assertTrue(!$trovato); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.