|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JsonAdm\Common\Decorator; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class BaseTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $object; |
|
15
|
|
|
private $stub; |
|
16
|
|
|
private $view; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
protected function setUp() |
|
20
|
|
|
{ |
|
21
|
|
|
$context = \TestHelperJadm::getContext(); |
|
22
|
|
|
$this->view = $context->getView(); |
|
23
|
|
|
|
|
24
|
|
|
$this->stub = $this->getMockBuilder( '\\Aimeos\\Admin\\JsonAdm\\Standard' ) |
|
25
|
|
|
->setConstructorArgs( array( $context, $this->view, array(), 'attribute' ) ) |
|
26
|
|
|
->getMock(); |
|
27
|
|
|
|
|
28
|
|
|
$this->object = new TestBase( $this->stub, $context, $this->view, array(), 'attribute' ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
protected function tearDown() |
|
33
|
|
|
{ |
|
34
|
|
|
unset( $this->object, $this->stub ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testDelete() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->stub->expects( $this->once() )->method( 'delete' )->will( $this->returnArgument( 1 ) ); |
|
41
|
|
|
$response = $this->view->response(); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertSame( $response, $this->object->delete( $this->view->request(), $response ) ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
public function testGet() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->stub->expects( $this->once() )->method( 'get' )->will( $this->returnArgument( 1 ) ); |
|
50
|
|
|
$response = $this->view->response(); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertSame( $response, $this->object->get( $this->view->request(), $response ) ); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
public function testPatch() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->stub->expects( $this->once() )->method( 'patch' )->will( $this->returnArgument( 1 ) ); |
|
59
|
|
|
$response = $this->view->response(); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertSame( $response, $this->object->patch( $this->view->request(), $response ) ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
public function testPost() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->stub->expects( $this->once() )->method( 'post' )->will( $this->returnArgument( 1 ) ); |
|
68
|
|
|
$response = $this->view->response(); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertSame( $response, $this->object->post( $this->view->request(), $response ) ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function testPut() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->stub->expects( $this->once() )->method( 'put' )->will( $this->returnArgument( 1 ) ); |
|
77
|
|
|
$response = $this->view->response(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertSame( $response, $this->object->put( $this->view->request(), $response ) ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
public function testOptions() |
|
84
|
|
|
{ |
|
85
|
|
|
$this->stub->expects( $this->once() )->method( 'options' )->will( $this->returnArgument( 1 ) ); |
|
86
|
|
|
$response = $this->view->response(); |
|
87
|
|
|
|
|
88
|
|
|
$this->assertSame( $response, $this->object->options( $this->view->request(), $response ) ); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
public function testGetContext() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Context\\Item\\Iface', $this->object->getContextPublic() ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
public function testGetTemplatePaths() |
|
99
|
|
|
{ |
|
100
|
|
|
$this->assertEquals( array(), $this->object->getTemplatePathsPublic() ); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
public function testGetPath() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->assertEquals( 'attribute', $this->object->getPathPublic() ); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
class TestBase |
|
|
|
|
|
|
112
|
|
|
extends \Aimeos\Admin\JsonAdm\Common\Decorator\Base |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
public function getContextPublic() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->getContext(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getTemplatePathsPublic() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->getTemplatePaths(); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getPathPublic() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->getPath(); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.