1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Service\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $stub; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
22
|
|
|
|
23
|
|
|
$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Standard::class ) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Decorator\Base::class ) |
28
|
|
|
->setConstructorArgs( [$this->stub, $this->context] ) |
29
|
|
|
->getMockForAbstractClass(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function tearDown() |
34
|
|
|
{ |
35
|
|
|
unset( $this->context, $this->object, $this->stub ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testConstructException() |
40
|
|
|
{ |
41
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Iface::class )->getMock(); |
42
|
|
|
|
43
|
|
|
$this->setExpectedException( \Aimeos\MW\Common\Exception::class ); |
44
|
|
|
|
45
|
|
|
$this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Decorator\Base::class ) |
46
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
47
|
|
|
->getMockForAbstractClass(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testCall() |
52
|
|
|
{ |
53
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Standard::class ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->setMethods( ['invalid'] ) |
56
|
|
|
->getMock(); |
57
|
|
|
|
58
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\Decorator\Base::class ) |
59
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
60
|
|
|
->getMockForAbstractClass(); |
61
|
|
|
|
62
|
|
|
$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) ); |
63
|
|
|
|
64
|
|
|
$this->assertTrue( $object->invalid() ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testCompare() |
69
|
|
|
{ |
70
|
|
|
$this->assertSame( $this->object, $this->object->compare( '==', 'service.type', 'delivery' ) ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
public function testFind() |
75
|
|
|
{ |
76
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem(); |
77
|
|
|
|
78
|
|
|
$this->stub->expects( $this->once() )->method( 'find' ) |
79
|
|
|
->will( $this->returnValue( $item ) ); |
80
|
|
|
|
81
|
|
|
$this->assertSame( $item, $this->object->find( 'test' ) ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testFunction() |
86
|
|
|
{ |
87
|
|
|
$this->stub->expects( $this->once() )->method( 'function' ) |
88
|
|
|
->will( $this->returnValue( 'service:has("domain","type","refid")' ) ); |
89
|
|
|
|
90
|
|
|
$str = $this->object->function( 'service:has', ['domain', 'type', 'refid'] ); |
91
|
|
|
$this->assertEquals( 'service:has("domain","type","refid")', $str ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
public function testGet() |
96
|
|
|
{ |
97
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem(); |
98
|
|
|
|
99
|
|
|
$this->stub->expects( $this->once() )->method( 'get' ) |
100
|
|
|
->will( $this->returnValue( $item ) ); |
101
|
|
|
|
102
|
|
|
$this->assertSame( $item, $this->object->get( -1 ) ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testGetProvider() |
107
|
|
|
{ |
108
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'service' ); |
109
|
|
|
$provider = $manager->getProvider( $manager->findItem( 'unitcode', [], 'service', 'delivery' ), 'delivery' ); |
110
|
|
|
|
111
|
|
|
$this->stub->expects( $this->once() )->method( 'getProvider' ) |
112
|
|
|
->will( $this->returnValue( $provider ) ); |
113
|
|
|
|
114
|
|
|
$this->assertSame( $provider, $this->object->getProvider( -1 ) ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testGetProviders() |
119
|
|
|
{ |
120
|
|
|
$this->stub->expects( $this->once() )->method( 'getProviders' ) |
121
|
|
|
->will( $this->returnValue( [] ) ); |
122
|
|
|
|
123
|
|
|
$this->assertEquals( [], $this->object->getProviders( 'payment' ) ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testParse() |
128
|
|
|
{ |
129
|
|
|
$this->assertSame( $this->object, $this->object->parse( [] ) ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
public function testProcess() |
134
|
|
|
{ |
135
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem(); |
136
|
|
|
|
137
|
|
|
$this->stub->expects( $this->once() )->method( 'process' ) |
138
|
|
|
->will( $this->returnValue( new \Aimeos\MShop\Common\Helper\Form\Standard() ) ); |
139
|
|
|
|
140
|
|
|
$this->assertInstanceOf( 'Aimeos\MShop\Common\Helper\Form\Iface', $this->object->process( $item, -1, [], [] ) ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
public function testSearch() |
145
|
|
|
{ |
146
|
|
|
$total = 0; |
147
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem(); |
148
|
|
|
|
149
|
|
|
$this->stub->expects( $this->once() )->method( 'search' ) |
150
|
|
|
->will( $this->returnValue( [$item] ) ); |
151
|
|
|
|
152
|
|
|
$this->assertEquals( [$item], $this->object->search( $total ) ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
public function testSlice() |
157
|
|
|
{ |
158
|
|
|
$this->assertSame( $this->object, $this->object->slice( 0, 100 ) ); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
public function testSort() |
163
|
|
|
{ |
164
|
|
|
$this->assertSame( $this->object, $this->object->sort( 'type' ) ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function testUpdatePush() |
169
|
|
|
{ |
170
|
|
|
$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
171
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
172
|
|
|
|
173
|
|
|
$this->stub->expects( $this->once() )->method( 'updatePush' ) |
174
|
|
|
->will( $this->returnValue( $response ) ); |
175
|
|
|
|
176
|
|
|
$this->assertInstanceOf( \Psr\Http\Message\ResponseInterface::class, $this->object->updatePush( $request, $response, 'test' ) ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
public function testUpdateSync() |
181
|
|
|
{ |
182
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
183
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem(); |
184
|
|
|
|
185
|
|
|
$this->stub->expects( $this->once() )->method( 'updateSync' ) |
186
|
|
|
->will( $this->returnValue( $item ) ); |
187
|
|
|
|
188
|
|
|
$this->assertInstanceOf( 'Aimeos\MShop\Order\Item\Iface', $this->object->updateSync( $request, 'test', -1 ) ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testUses() |
193
|
|
|
{ |
194
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
public function testGetController() |
199
|
|
|
{ |
200
|
|
|
$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
protected function access( $name ) |
205
|
|
|
{ |
206
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Service\Decorator\Base::class ); |
207
|
|
|
$method = $class->getMethod( $name ); |
208
|
|
|
$method->setAccessible( true ); |
209
|
|
|
|
210
|
|
|
return $method; |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|