1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use Silex\WebTestCase; |
6
|
|
|
use JsonSchema\Validator; |
7
|
|
|
|
8
|
|
|
class PartTest extends WorkspaceTest |
9
|
|
|
{ |
10
|
|
|
use AbstractAppTest; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/*verifico che una parte si possa scaricare correttamente*/ |
14
|
|
View Code Duplication |
public function testGetWorkspacePart(){ |
|
|
|
|
15
|
|
|
$schema = __DIR__.'/../../../../api/schemas/part.json'; |
16
|
|
|
|
17
|
|
|
$client = $this->createClient(); |
18
|
|
|
$client = $this->logIn($client); |
19
|
|
|
|
20
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/6/part/1'); |
|
|
|
|
21
|
|
|
$response = $client->getResponse(); |
|
|
|
|
22
|
|
|
|
23
|
|
|
//print_r($response); |
24
|
|
|
$data = $client->getResponse()->getContent(); |
25
|
|
|
$validator = $this->askValidation($data,$schema); |
26
|
|
|
|
27
|
|
|
$assert = $this->evalValidation($validator); |
28
|
|
|
$this->assertTrue($assert); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
public function testPostWorkspacePart(){ |
33
|
|
|
//$schema = __DIR__.'/../../../../api/schemas/part.json'; |
|
|
|
|
34
|
|
|
|
35
|
|
|
$client = $this->createClient(); |
36
|
|
|
$client = $this->logIn($client); |
37
|
|
|
|
38
|
|
|
$id = $this->testPostWorkspace(); |
39
|
|
|
$part ='{"part":[ |
40
|
|
|
{ |
41
|
|
|
"type": "image", |
42
|
|
|
"ref": "afaifnanabnawnfawba", |
43
|
|
|
"hash":"'.hash("md5",$id."prova0").'" |
44
|
|
|
}, |
45
|
|
|
{ |
46
|
|
|
"type": "image", |
47
|
|
|
"ref": "awfaowapaegbgepng", |
48
|
|
|
"hash":"'.hash("md5",$id."prova1").'" |
49
|
|
|
}, |
50
|
|
|
{ |
51
|
|
|
"type": "text", |
52
|
|
|
"ref": "afaafaafafafifnanabnawnfawba", |
53
|
|
|
"hash":"'.hash("md5",$id."prova2").'" |
54
|
|
|
}, |
55
|
|
|
{ |
56
|
|
|
"type": "video", |
57
|
|
|
"ref": "aaafawafaggagaagegaa", |
58
|
|
|
"hash":"'.hash("md5",$id."prova3").'" |
59
|
|
|
} |
60
|
|
|
], |
61
|
|
|
"badges":[13,28]}'; |
62
|
|
|
|
63
|
|
|
$client->request( |
64
|
|
|
'POST', |
65
|
|
|
'/api/v1/workspace/'.$id.'/part', |
66
|
|
|
[], |
67
|
|
|
[], |
68
|
|
|
['CONTENT_TYPE' => 'application/json'], |
69
|
|
|
$part); |
70
|
|
|
|
71
|
|
|
$response = $client->getResponse(); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$data = $client->getResponse()->getContent(); |
74
|
|
|
$id = json_decode($data); |
75
|
|
|
|
76
|
|
|
$id=$id->id; |
77
|
|
|
|
78
|
|
|
$this->assertTrue(is_numeric($id)); |
79
|
|
|
return $id; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testPutWorkspacePart(){ |
83
|
|
|
$client = $this->createClient(); |
84
|
|
|
$client = $this->logIn($client); |
85
|
|
|
|
86
|
|
|
$id = $this->testPostWorkspace(); |
87
|
|
|
$part_id = $this->testPostWorkspacePart(); |
88
|
|
|
$part ='{ |
89
|
|
|
"id":'.$part_id.', |
90
|
|
|
"part":[ |
91
|
|
|
{ |
92
|
|
|
"type": "image", |
93
|
|
|
"ref": "afaifnanabnawnfawba", |
94
|
|
|
"hash":"'.hash("md5",$id."prova0").'" |
95
|
|
|
}, |
96
|
|
|
{ |
97
|
|
|
"type": "image", |
98
|
|
|
"ref": "awfaowapaegbgepng", |
99
|
|
|
"hash":"'.hash("md5",$id."prova1").'" |
100
|
|
|
}, |
101
|
|
|
{ |
102
|
|
|
"type": "text", |
103
|
|
|
"ref": "blablablablabla", |
104
|
|
|
"hash":"'.hash("md5",$id."prova2").'" |
105
|
|
|
} |
106
|
|
|
], |
107
|
|
|
"badges":[13,30]}'; |
108
|
|
|
|
109
|
|
|
$client->request( |
110
|
|
|
'PUT', |
111
|
|
|
'/api/v1/workspace/'.$id.'/part/'.$part_id.'', |
112
|
|
|
[], |
113
|
|
|
[], |
114
|
|
|
['CONTENT_TYPE' => 'application/json'], |
115
|
|
|
$part); |
116
|
|
|
|
117
|
|
|
$response = $client->getResponse(); |
|
|
|
|
118
|
|
|
$data = $client->getResponse()->getContent(); |
119
|
|
|
$id = json_decode($data); |
120
|
|
|
|
121
|
|
|
$res_id=$id->id; |
122
|
|
|
|
123
|
|
|
$this->assertEquals($part_id,$res_id); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testDeleteWorkspacePart(){ |
127
|
|
|
$client = $this->createClient(); |
128
|
|
|
$client = $this->logIn($client); |
129
|
|
|
|
130
|
|
|
$id = $this->testPostWorkspace(); |
131
|
|
|
$part_id = $this->testPostWorkspacePart(); |
132
|
|
|
|
133
|
|
|
$client->request( |
134
|
|
|
'DELETE', |
135
|
|
|
'/api/v1/workspace/'.$id.'/part/'.$part_id.'', |
136
|
|
|
[], |
137
|
|
|
[], |
138
|
|
|
[], |
139
|
|
|
''); |
140
|
|
|
|
141
|
|
|
$response = $client->getResponse(); |
142
|
|
|
$this->assertTrue($response->isOk()); |
143
|
|
|
|
144
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/'.$id); |
|
|
|
|
145
|
|
|
|
146
|
|
|
print_r($client->getResponse()); |
147
|
|
|
$data = $client->getResponse()->getContent(); |
148
|
|
|
|
149
|
|
|
$js = json_decode($data); |
150
|
|
|
$trovato = false; |
151
|
|
|
|
152
|
|
|
foreach($js->parts as $w){ |
153
|
|
|
if($w === $part_id){ |
154
|
|
|
$trovato=true; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
$this->assertTrue(!$trovato); |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
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.