|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
4
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace eZ\Publish\Core\REST\Server\Tests\Output\PathExpansion\ValueLoaders; |
|
7
|
|
|
|
|
8
|
|
|
use eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\ControllerUriValueLoader; |
|
9
|
|
|
use PHPUnit_Framework_TestCase; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
|
|
12
|
|
|
class ControllerUriValueLoaderTest extends PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var \eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\ControllerUriValueLoader |
|
16
|
|
|
*/ |
|
17
|
|
|
private $loader; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Symfony\Component\Routing\RouterInterface|\PHPUnit_Framework_MockObject_MockObject |
|
21
|
|
|
*/ |
|
22
|
|
|
private $routerMock; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \Symfony\Component\Routing\RouterInterface|\PHPUnit_Framework_MockObject_MockObject |
|
26
|
|
|
*/ |
|
27
|
|
|
private $controllerResolverMock; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->loader = new ControllerUriValueLoader( |
|
32
|
|
|
$this->routerMock = $this->getMock('Symfony\Component\Routing\RouterInterface'), |
|
33
|
|
|
$this->controllerResolverMock = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface') |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Covers the normal behaviour of the load method. |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
public function testLoad() |
|
41
|
|
|
{ |
|
42
|
|
|
$controllerArray = ['_controller' => 'some:controller', 'id' => 1]; |
|
43
|
|
|
|
|
44
|
|
|
$valueObject = new \stdClass(); |
|
45
|
|
|
|
|
46
|
|
|
$this->routerMock |
|
47
|
|
|
->expects($this->once()) |
|
48
|
|
|
->method('match') |
|
49
|
|
|
->with('/api/ezp/v2/resource/1') |
|
50
|
|
|
->will($this->returnValue($controllerArray)); |
|
51
|
|
|
|
|
52
|
|
|
$this->controllerResolverMock |
|
53
|
|
|
->expects($this->once()) |
|
54
|
|
|
->method('getController') |
|
55
|
|
|
->will($this->returnValue( |
|
56
|
|
|
function () use ($valueObject) { return $valueObject; } |
|
57
|
|
|
)); |
|
58
|
|
|
|
|
59
|
|
|
$this->controllerResolverMock |
|
60
|
|
|
->expects($this->once()) |
|
61
|
|
|
->method('getArguments') |
|
62
|
|
|
->will($this->returnValue(['id' => 1])); |
|
63
|
|
|
|
|
64
|
|
|
self::assertSame( |
|
65
|
|
|
$valueObject, |
|
66
|
|
|
$this->loader->load('/api/ezp/v2/resource/1') |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @expectedException \UnexpectedValueException |
|
72
|
|
|
* @expectedExceptionMessage Expected the controller to return a Value object, got a Response instead |
|
73
|
|
|
*/ |
|
74
|
|
View Code Duplication |
public function testLoadReturnsResponse() |
|
75
|
|
|
{ |
|
76
|
|
|
$controllerArray = ['_controller' => 'some:controller', 'id' => 1]; |
|
77
|
|
|
|
|
78
|
|
|
$valueObject = new Response(); |
|
79
|
|
|
|
|
80
|
|
|
$this->routerMock |
|
81
|
|
|
->expects($this->once()) |
|
82
|
|
|
->method('match') |
|
83
|
|
|
->with('/api/ezp/v2/resource/1') |
|
84
|
|
|
->will($this->returnValue($controllerArray)); |
|
85
|
|
|
|
|
86
|
|
|
$this->controllerResolverMock |
|
87
|
|
|
->expects($this->once()) |
|
88
|
|
|
->method('getController') |
|
89
|
|
|
->will($this->returnValue( |
|
90
|
|
|
function () use ($valueObject) { return $valueObject; } |
|
91
|
|
|
)); |
|
92
|
|
|
|
|
93
|
|
|
$this->controllerResolverMock |
|
94
|
|
|
->expects($this->once()) |
|
95
|
|
|
->method('getArguments') |
|
96
|
|
|
->will($this->returnValue(['id' => 1])); |
|
97
|
|
|
|
|
98
|
|
|
$this->loader->load('/api/ezp/v2/resource/1'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|