|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* EmptyObjectControllerTest class file |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\CoreBundle\Tests\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
|
9
|
|
|
use GravitonDyn\TestCaseIdReadOnlyBundle\Document\TestCaseIdReadOnly; |
|
10
|
|
|
use GravitonDyn\TestCaseIdReadOnlyBundle\Document\TestCaseIdReadOnlyObjectEmbedded; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
15
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
16
|
|
|
* @link http://swisscom.ch |
|
17
|
|
|
*/ |
|
18
|
|
|
class ReadOnlyIdControllerTest extends RestTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* load fixtures |
|
22
|
|
|
* |
|
23
|
|
|
* @return void |
|
24
|
|
|
*/ |
|
25
|
|
|
public function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
$object = new TestCaseIdReadOnly(); |
|
28
|
|
|
$object = new TestCaseIdReadOnlyObjectEmbedded(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Test create |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testCreateNewElements() |
|
37
|
|
|
{ |
|
38
|
|
|
$main = $this->buildObject('ok'); |
|
39
|
|
|
|
|
40
|
|
|
$client = static::createRestClient(); |
|
41
|
|
|
// Should it exists |
|
42
|
|
|
$client->request('DELETE', '/testcase/readonlyid/'.$main->id); |
|
43
|
|
|
|
|
44
|
|
|
$client->put('/testcase/readonlyid/'.$main->id, $main); |
|
45
|
|
|
$this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode()); |
|
46
|
|
|
|
|
47
|
|
|
$client = static::createRestClient(); |
|
48
|
|
|
$client->request('GET', '/testcase/readonlyid/'.$main->id); |
|
49
|
|
|
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode()); |
|
50
|
|
|
|
|
51
|
|
|
$result = $client->getResults(); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertTrue($result == $main); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Test create |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testCreateNewElementsWithNoId() |
|
62
|
|
|
{ |
|
63
|
|
|
$main = $this->buildObject('bad'); |
|
64
|
|
|
// Unset a ID |
|
65
|
|
|
unset($main->object->id); |
|
66
|
|
|
|
|
67
|
|
|
$client = static::createRestClient(); |
|
68
|
|
|
// Should it exists |
|
69
|
|
|
$client->request('DELETE', '/testcase/readonlyid/'.$main->id); |
|
70
|
|
|
|
|
71
|
|
|
$client->put('/testcase/readonlyid/'.$main->id, $main); |
|
72
|
|
|
$response = $client->getResponse(); |
|
73
|
|
|
$this->assertEquals(Response::HTTP_BAD_REQUEST, $response->getStatusCode()); |
|
74
|
|
|
|
|
75
|
|
|
// [{"propertyPath":"object.id","message":"The property id is required"}] |
|
76
|
|
|
$result = $client->getResults(); |
|
77
|
|
|
$this->assertEquals('object.id', $result[0]->propertyPath); |
|
78
|
|
|
$this->assertEquals('The property id is required', $result[0]->message); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Simple build of stdClass for testing |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $pre Id string field for testing |
|
85
|
|
|
* @return \stdClass |
|
86
|
|
|
*/ |
|
87
|
|
|
private function buildObject($pre) |
|
88
|
|
|
{ |
|
89
|
|
|
$id = $pre.'read-required-id-main'; |
|
90
|
|
|
$main = new \stdClass(); |
|
91
|
|
|
$main->id = $id; |
|
92
|
|
|
$main->name = 'name_for_'.$id; |
|
93
|
|
|
|
|
94
|
|
|
$id = 'read-required-id-l1-'.$id; |
|
95
|
|
|
$levelA = new \stdClass(); |
|
96
|
|
|
$levelA->id = $id; |
|
97
|
|
|
$levelA->name = 'name_level1_for_'.$id; |
|
98
|
|
|
|
|
99
|
|
|
$id = 'read-required-id-l2-'.$id; |
|
100
|
|
|
$levelB = new \stdClass(); |
|
101
|
|
|
$levelB->id = $id; |
|
102
|
|
|
$levelB->name = 'name_level1_for_'.$id; |
|
103
|
|
|
|
|
104
|
|
|
$levelA->object = $levelB; |
|
105
|
|
|
$main->object = $levelA; |
|
106
|
|
|
|
|
107
|
|
|
return $main; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|