1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aimeos\Controller\Frontend\Service; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
8
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
9
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
10
|
|
|
*/ |
11
|
|
|
class StandardTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
private $object; |
14
|
|
|
private $context; |
15
|
|
|
private static $basket; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
\Aimeos\MShop\Factory::setCache( true ); |
21
|
|
|
|
22
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
23
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Service\Standard( $this->context ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
public static function setUpBeforeClass() |
28
|
|
|
{ |
29
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
30
|
|
|
$orderBaseMgr = $orderManager->getSubManager( 'base' ); |
31
|
|
|
self::$basket = $orderBaseMgr->createItem(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
protected function tearDown() |
36
|
|
|
{ |
37
|
|
|
unset( $this->object, $this->context ); |
38
|
|
|
|
39
|
|
|
\Aimeos\MShop\Factory::setCache( false ); |
40
|
|
|
\Aimeos\MShop\Factory::clear(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testCheckAttributes() |
45
|
|
|
{ |
46
|
|
|
$attributes = $this->object->checkAttributes( $this->getServiceItem()->getId(), [] ); |
47
|
|
|
$this->assertEquals( [], $attributes ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testGetProviders() |
52
|
|
|
{ |
53
|
|
|
$providers = $this->object->getProviders( 'delivery' ); |
54
|
|
|
$this->assertGreaterThan( 0, count( $providers ) ); |
55
|
|
|
|
56
|
|
|
foreach( $providers as $provider ) { |
57
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Provider\\Iface', $provider ); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testGetProvider() |
63
|
|
|
{ |
64
|
|
|
$provider = $this->object->getProvider( $this->getServiceItem()->getId() ); |
65
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Provider\\Iface', $provider ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testProcess() |
70
|
|
|
{ |
71
|
|
|
$form = new \Aimeos\MShop\Common\Item\Helper\Form\Standard(); |
72
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem(); |
73
|
|
|
$serviceId = \Aimeos\MShop\Factory::createManager( $this->context, 'service' )->findItem( 'unitcode' )->getId(); |
74
|
|
|
|
75
|
|
|
$provider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' ) |
76
|
|
|
->disableOriginalConstructor() |
77
|
|
|
->setMethods( ['process'] ) |
78
|
|
|
->getMock(); |
79
|
|
|
|
80
|
|
|
$manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' ) |
81
|
|
|
->setConstructorArgs( [$this->context] ) |
82
|
|
|
->setMethods( ['getProvider'] ) |
83
|
|
|
->getMock(); |
84
|
|
|
|
85
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'service', $manager ); |
86
|
|
|
|
87
|
|
|
$provider->expects( $this->once() )->method( 'process' )->will( $this->returnValue( $form ) ); |
88
|
|
|
$manager->expects( $this->once() )->method( 'getProvider' )->will( $this->returnValue( $provider ) ); |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
$result = $this->object->process( $item, $serviceId, [], [] ); |
92
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Helper\Form\Iface', $result ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testUpdateSync() |
97
|
|
|
{ |
98
|
|
|
$item = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem(); |
99
|
|
|
|
100
|
|
|
$response = $this->getMockBuilder( '\Psr\Http\Message\ResponseInterface' )->getMock(); |
101
|
|
|
$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock(); |
102
|
|
|
|
103
|
|
|
$provider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' ) |
104
|
|
|
->setMethods( ['updateSync', 'query', 'isImplemented'] ) |
105
|
|
|
->disableOriginalConstructor() |
106
|
|
|
->getMock(); |
107
|
|
|
|
108
|
|
|
$manager = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' ) |
109
|
|
|
->setConstructorArgs( array( $this->context ) ) |
110
|
|
|
->setMethods( ['getProvider'] ) |
111
|
|
|
->getMock(); |
112
|
|
|
|
113
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'service', $manager ); |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
$request->expects( $this->once() )->method( 'getQueryParams' )->will( $this->returnValue( ['code' => 'unitcode'] ) ); |
117
|
|
|
$manager->expects( $this->once() )->method( 'getProvider' )->will( $this->returnValue( $provider ) ); |
118
|
|
|
$provider->expects( $this->once() )->method( 'updateSync' )->will( $this->returnValue( $item ) ); |
119
|
|
|
$provider->expects( $this->once() )->method( 'isImplemented' )->will( $this->returnValue( true ) ); |
120
|
|
|
$provider->expects( $this->once() )->method( 'query' ); |
121
|
|
|
|
122
|
|
|
$this->object->updateSync( $request, $response, [] ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
public function testGetServices() |
127
|
|
|
{ |
128
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
129
|
|
|
$basket = $orderManager->getSubManager( 'base' )->createItem(); |
130
|
|
|
|
131
|
|
|
$services = $this->object->getServices( 'delivery', $basket ); |
|
|
|
|
132
|
|
|
$this->assertGreaterThan( 0, count( $services ) ); |
133
|
|
|
|
134
|
|
|
foreach( $services as $service ) { |
135
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Service\\Item\\Iface', $service ); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function testGetServiceAttributes() |
141
|
|
|
{ |
142
|
|
|
$service = $this->getServiceItem(); |
143
|
|
|
$attributes = $this->object->getServiceAttributes( 'delivery', $service->getId(), self::$basket ); |
|
|
|
|
144
|
|
|
|
145
|
|
|
$this->assertEquals( 0, count( $attributes ) ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
public function testGetServiceAttributesCache() |
150
|
|
|
{ |
151
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
152
|
|
|
$basket = $orderManager->getSubManager( 'base' )->createItem(); |
153
|
|
|
|
154
|
|
|
$services = $this->object->getServices( 'delivery', $basket ); |
|
|
|
|
155
|
|
|
|
156
|
|
|
if( ( $service = reset( $services ) ) === false ) { |
157
|
|
|
throw new \RuntimeException( 'No service item found' ); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$attributes = $this->object->getServiceAttributes( 'delivery', $service->getId(), self::$basket ); |
|
|
|
|
161
|
|
|
|
162
|
|
|
$this->assertEquals( 0, count( $attributes ) ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
public function testGetServiceAttributesNoItems() |
167
|
|
|
{ |
168
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
169
|
|
|
$this->object->getServiceAttributes( 'invalid', -1, self::$basket ); |
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testGetServicePrice() |
174
|
|
|
{ |
175
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
176
|
|
|
$basket = $orderManager->getSubManager( 'base' )->createItem(); |
177
|
|
|
|
178
|
|
|
$service = $this->getServiceItem(); |
179
|
|
|
$price = $this->object->getServicePrice( 'delivery', $service->getId(), $basket ); |
|
|
|
|
180
|
|
|
|
181
|
|
|
$this->assertEquals( '12.95', $price->getValue() ); |
182
|
|
|
$this->assertEquals( '1.99', $price->getCosts() ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testGetServicePriceCache() |
187
|
|
|
{ |
188
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
189
|
|
|
$basket = $orderManager->getSubManager( 'base' )->createItem(); |
190
|
|
|
|
191
|
|
|
$services = $this->object->getServices( 'delivery', $basket ); |
|
|
|
|
192
|
|
|
|
193
|
|
|
if( ( $service = reset( $services ) ) === false ) { |
194
|
|
|
throw new \RuntimeException( 'No service item found' ); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$price = $this->object->getServicePrice( 'delivery', $service->getId(), $basket ); |
|
|
|
|
198
|
|
|
|
199
|
|
|
$this->assertEquals( '12.95', $price->getValue() ); |
200
|
|
|
$this->assertEquals( '1.99', $price->getCosts() ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function testGetServicePriceNoItems() |
205
|
|
|
{ |
206
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
207
|
|
|
$basket = $orderManager->getSubManager( 'base' )->createItem(); |
208
|
|
|
|
209
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
210
|
|
|
$this->object->getServicePrice( 'invalid', -1, $basket ); |
|
|
|
|
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
public function testCheckServiceAttributes() |
215
|
|
|
{ |
216
|
|
|
$service = $this->getServiceItem(); |
217
|
|
|
$attributes = $this->object->checkServiceAttributes( 'delivery', $service->getId(), array() ); |
|
|
|
|
218
|
|
|
|
219
|
|
|
$this->assertEquals( array(), $attributes ); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface |
225
|
|
|
*/ |
226
|
|
|
protected function getServiceItem() |
227
|
|
|
{ |
228
|
|
|
$manager = \Aimeos\MShop\Service\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
229
|
|
|
return $manager->findItem( 'unitcode' ); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.