|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests; |
|
4
|
|
|
|
|
5
|
|
|
class PartTest extends WorkspaceTest |
|
6
|
|
|
{ |
|
7
|
|
|
/*verifico che una parte si possa scaricare correttamente*/ |
|
8
|
|
|
public function testGetWorkspacePart() |
|
9
|
|
|
{ |
|
10
|
|
|
$schema = __DIR__.'/../../../../api/schemas/part.json'; |
|
11
|
|
|
|
|
12
|
|
|
$client = $this->createClient(); |
|
13
|
|
|
$client = $this->logIn($client); |
|
14
|
|
|
|
|
15
|
|
|
$blob = $this->testPostWorkspacePart(); |
|
16
|
|
|
$id = $blob[0]; |
|
17
|
|
|
$part_id = $blob[1]; |
|
18
|
|
|
|
|
19
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/'.$id.'/part/'.$part_id); |
|
|
|
|
|
|
20
|
|
|
$response = $client->getResponse(); |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
//print_r($response); |
|
23
|
|
|
$data = $client->getResponse()->getContent(); |
|
24
|
|
|
$validator = $this->askValidation($data, $schema); |
|
25
|
|
|
|
|
26
|
|
|
$assert = $this->evalValidation($validator); |
|
27
|
|
|
$this->assertTrue($assert); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testPostWorkspacePart() |
|
31
|
|
|
{ |
|
32
|
|
|
//$schema = __DIR__.'/../../../../api/schemas/part.json'; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
$client = $this->createClient(); |
|
35
|
|
|
$client = $this->logIn($client); |
|
36
|
|
|
|
|
37
|
|
|
$id = $this->testPostWorkspace(); |
|
38
|
|
|
$part = '{"part":[ |
|
39
|
|
|
{ |
|
40
|
|
|
"type": "image", |
|
41
|
|
|
"ref": "afaifnanabnawnfawba", |
|
42
|
|
|
"hash":"'.hash('md5', $id.'prova0').'" |
|
43
|
|
|
}, |
|
44
|
|
|
{ |
|
45
|
|
|
"type": "image", |
|
46
|
|
|
"ref": "awfaowapaegbgepng", |
|
47
|
|
|
"hash":"'.hash('md5', $id.'prova1').'" |
|
48
|
|
|
}, |
|
49
|
|
|
{ |
|
50
|
|
|
"type": "text", |
|
51
|
|
|
"ref": "afaafaafafafifnanabnawnfawba", |
|
52
|
|
|
"hash":"'.hash('md5', $id.'prova2').'" |
|
53
|
|
|
}, |
|
54
|
|
|
{ |
|
55
|
|
|
"type": "video", |
|
56
|
|
|
"ref": "aaafawafaggagaagegaa", |
|
57
|
|
|
"hash":"'.hash('md5', $id.'prova3').'" |
|
58
|
|
|
} |
|
59
|
|
|
], |
|
60
|
|
|
"badges":[13,28]}'; |
|
61
|
|
|
|
|
62
|
|
|
$client->request('POST', '/api/v1/workspace/'.$id.'/part', [], [], ['CONTENT_TYPE' => 'application/json'], $part); |
|
63
|
|
|
|
|
64
|
|
|
$response = $client->getResponse(); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$data = $client->getResponse()->getContent(); |
|
67
|
|
|
$part_id = json_decode($data); |
|
68
|
|
|
|
|
69
|
|
|
$part_id = $part_id->id; |
|
70
|
|
|
|
|
71
|
|
|
$this->assertTrue(is_numeric($id)); |
|
72
|
|
|
|
|
73
|
|
|
return [$id, $part_id]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testPutWorkspacePart() |
|
77
|
|
|
{ |
|
78
|
|
|
$client = $this->createClient(); |
|
79
|
|
|
$client = $this->logIn($client); |
|
80
|
|
|
|
|
81
|
|
|
$blob = $this->testPostWorkspacePart(); |
|
82
|
|
|
$id = $blob[0]; |
|
83
|
|
|
$part_id = $blob[1]; |
|
84
|
|
|
$part = '{ |
|
85
|
|
|
"id":'.$part_id.', |
|
86
|
|
|
"part":[ |
|
87
|
|
|
{ |
|
88
|
|
|
"type": "image", |
|
89
|
|
|
"ref": "afaifnanabnawnfawba", |
|
90
|
|
|
"hash":"'.hash('md5', $id.'prova0').'" |
|
91
|
|
|
}, |
|
92
|
|
|
{ |
|
93
|
|
|
"type": "image", |
|
94
|
|
|
"ref": "awfaowapaegbgepng", |
|
95
|
|
|
"hash":"'.hash('md5', $id.'prova1').'" |
|
96
|
|
|
}, |
|
97
|
|
|
{ |
|
98
|
|
|
"type": "text", |
|
99
|
|
|
"ref": "blablablablabla", |
|
100
|
|
|
"hash":"'.hash('md5', $id.'prova2').'" |
|
101
|
|
|
} |
|
102
|
|
|
], |
|
103
|
|
|
"badges":[13,30]}'; |
|
104
|
|
|
|
|
105
|
|
|
$client->request('PUT', '/api/v1/workspace/'.$id.'/part/'.$part_id.'', [], [], ['CONTENT_TYPE' => 'application/json'], $part); |
|
106
|
|
|
|
|
107
|
|
|
$response = $client->getResponse(); |
|
|
|
|
|
|
108
|
|
|
$data = $client->getResponse()->getContent(); |
|
109
|
|
|
$id = json_decode($data); |
|
110
|
|
|
|
|
111
|
|
|
$res_id = $id->id; |
|
112
|
|
|
|
|
113
|
|
|
$this->assertEquals($part_id, $res_id); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testDeleteWorkspacePart() |
|
117
|
|
|
{ |
|
118
|
|
|
$client = $this->createClient(); |
|
119
|
|
|
$client = $this->logIn($client); |
|
120
|
|
|
|
|
121
|
|
|
$blob = $this->testPostWorkspacePart(); |
|
122
|
|
|
$id = $blob[0]; |
|
123
|
|
|
$part_id = $blob[1]; |
|
124
|
|
|
|
|
125
|
|
|
$client->request('DELETE', '/api/v1/workspace/'.$id.'/part/'.$part_id.'', [], [], [], ''); |
|
126
|
|
|
|
|
127
|
|
|
$response = $client->getResponse(); |
|
128
|
|
|
$this->assertTrue($response->isOk()); |
|
129
|
|
|
|
|
130
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/'.$id); |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
//print_r($client->getResponse()); |
|
|
|
|
|
|
133
|
|
|
$data = $client->getResponse()->getContent(); |
|
134
|
|
|
|
|
135
|
|
|
$js = json_decode($data); |
|
136
|
|
|
|
|
137
|
|
|
//var_dump($data); |
|
138
|
|
|
$trovato = false; |
|
139
|
|
|
|
|
140
|
|
|
foreach ($js->parts as $w) { |
|
141
|
|
|
if ($w === $part_id) { |
|
142
|
|
|
$trovato = true; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
$this->assertTrue(!$trovato); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.