1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use Silex\WebTestCase; |
6
|
|
|
use JsonSchema\Validator; |
7
|
|
|
|
8
|
|
|
class WorkspaceTest extends WebTestCase |
9
|
|
|
{ |
10
|
|
|
use AbstractAppTest; |
11
|
|
|
|
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
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/1'); |
|
|
|
|
19
|
|
|
$response = $client->getResponse(); |
|
|
|
|
20
|
|
|
$data = $client->getResponse()->getContent(); |
21
|
|
|
$validator = $this->askValidation($data,$schema); |
22
|
|
|
|
23
|
|
|
$assert = $this->evalValidation($validator); |
24
|
|
|
$this->assertTrue($assert); |
25
|
|
|
} |
26
|
|
View Code Duplication |
public function testGetWorkspaceList(){ |
|
|
|
|
27
|
|
|
$schema = __DIR__.'/../../../../api/schemas/workspaceList.json'; |
28
|
|
|
|
29
|
|
|
$client = $this->createClient(); |
30
|
|
|
$client = $this->logIn($client); |
31
|
|
|
|
32
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/'); |
|
|
|
|
33
|
|
|
$response = $client->getResponse(); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$data = $client->getResponse()->getContent(); |
36
|
|
|
$validator = $this->askValidation($data,$schema); |
37
|
|
|
|
38
|
|
|
$assert = $this->evalValidation($validator); |
39
|
|
|
$this->assertTrue($assert); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
public function testGetWorkspaceShare(){ |
|
|
|
|
43
|
|
|
$schema = __DIR__.'/../../../../api/schemas/workspaceShare.json'; |
44
|
|
|
|
45
|
|
|
$client = $this->createClient(); |
46
|
|
|
$client = $this->logIn($client); |
47
|
|
|
|
48
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/1/share'); |
|
|
|
|
49
|
|
|
$response = $client->getResponse(); |
|
|
|
|
50
|
|
|
|
51
|
|
|
//print_r($response); |
52
|
|
|
$data = $client->getResponse()->getContent(); |
53
|
|
|
$validator = $this->askValidation($data,$schema); |
54
|
|
|
|
55
|
|
|
$assert = $this->evalValidation($validator); |
56
|
|
|
$this->assertTrue($assert); |
57
|
|
|
} |
58
|
|
View Code Duplication |
public function testGetWorkspacePart(){ |
|
|
|
|
59
|
|
|
$schema = __DIR__.'/../../../../api/schemas/part.json'; |
60
|
|
|
|
61
|
|
|
$client = $this->createClient(); |
62
|
|
|
$client = $this->logIn($client); |
63
|
|
|
|
64
|
|
|
$crawler = $client->request('GET', '/api/v1/workspace/6/part/1'); |
|
|
|
|
65
|
|
|
$response = $client->getResponse(); |
|
|
|
|
66
|
|
|
|
67
|
|
|
//print_r($response); |
68
|
|
|
$data = $client->getResponse()->getContent(); |
69
|
|
|
$validator = $this->askValidation($data,$schema); |
70
|
|
|
|
71
|
|
|
$assert = $this->evalValidation($validator); |
72
|
|
|
$this->assertTrue($assert); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testPostWorkspace(){ |
76
|
|
|
//$schema = __DIR__.'/../../../../api/schemas/workspace.json'; |
|
|
|
|
77
|
|
|
|
78
|
|
|
$client = $this->createClient(); |
79
|
|
|
$client = $this->logIn($client); |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
|
83
|
|
|
$client->request( |
84
|
|
|
'POST', |
85
|
|
|
'/api/v1/workspace/', |
86
|
|
|
[], |
87
|
|
|
[], |
88
|
|
|
['CONTENT_TYPE' => 'application/json'], |
89
|
|
|
'{ |
90
|
|
|
"title":"Sopraelevata", |
91
|
|
|
"description":"I Sarchiaponi sono pronti a lanciarsi nella costruzione di una sopraelevata", |
92
|
|
|
"environment": 22, |
93
|
|
|
"team": { |
94
|
|
|
"patrol":"Sarchiaponi", |
95
|
|
|
"group":"Bologna 18", |
96
|
|
|
"unit": "Marco Polo" |
97
|
|
|
}, |
98
|
|
|
"badges": [ 5, 38, 99] |
99
|
|
|
}'); |
100
|
|
|
|
101
|
|
|
$response = $client->getResponse(); |
|
|
|
|
102
|
|
|
|
103
|
|
|
$data = $client->getResponse()->getContent(); |
104
|
|
|
$id = json_decode($data); |
105
|
|
|
|
106
|
|
|
$id=$id->id; |
107
|
|
|
|
108
|
|
|
$this->assertTrue(is_numeric($id)); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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.