1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Christian Blank <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
class NestedResourceRestControllerTest extends RestTest { |
|
|
|
|
7
|
|
|
|
8
|
|
|
public function setUp() { |
9
|
|
|
parent::setUp(); |
10
|
|
|
Config::inst()->update('Director', 'rules', [ |
11
|
|
|
'v/1/RestTestRoute/$ID/Nested/$OtherID' => 'NestedTestController', |
12
|
|
|
]); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
View Code Duplication |
public function testControllerGET() { |
|
|
|
|
16
|
|
|
$id = 'Foo'; |
17
|
|
|
$result = $this->makeApiRequest("RestTestRoute/$id/Nested"); |
18
|
|
|
$this->assertTrue(array_key_exists('message', $result)); |
|
|
|
|
19
|
|
|
$this->assertEquals('Test GET', $result['message']); |
|
|
|
|
20
|
|
|
$this->assertEquals($id, $result['resource']['id']); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testNotProvidedID() { |
24
|
|
|
$this->makeApiRequest("RestTestRoute//Nested", ['code' => 404]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
View Code Duplication |
public function testControllerDELETE() { |
|
|
|
|
29
|
|
|
$id = 'Bar'; |
30
|
|
|
$result = $this->makeApiRequest("RestTestRoute/$id/Nested", ['method' => 'DELETE']); |
31
|
|
|
$this->assertTrue(array_key_exists('message', $result)); |
|
|
|
|
32
|
|
|
$this->assertEquals('Test DELETE', $result['message']); |
|
|
|
|
33
|
|
|
$this->assertEquals($id, $result['resource']['id']); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
class NestedTestController extends NestedResourceRestController implements TestOnly { |
|
|
|
|
38
|
|
|
|
39
|
|
|
private static $allowed_actions = [ |
|
|
|
|
40
|
|
|
'delete' => true, |
41
|
|
|
'get' => true |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
public function get($request, $resource) { |
|
|
|
|
45
|
|
|
return ['message' => 'Test GET', 'resource' => $resource]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function delete($request, $resource) { |
|
|
|
|
49
|
|
|
return ['message' => 'Test DELETE', 'resource' => $resource]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function getRootResource($id) { |
53
|
|
|
return ['id' => $id]; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.