1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Controller\Frontend\Service; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $context; |
17
|
|
|
private static $basket; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
\Aimeos\MShop::cache( true ); |
23
|
|
|
|
24
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
25
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Service\Standard( $this->context ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
public static function setUpBeforeClass() |
30
|
|
|
{ |
31
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::create( \TestHelperFrontend::getContext() ); |
32
|
|
|
$orderBaseMgr = $orderManager->getSubManager( 'base' ); |
33
|
|
|
self::$basket = $orderBaseMgr->createItem(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
protected function tearDown() |
38
|
|
|
{ |
39
|
|
|
\Aimeos\MShop::cache( false ); |
40
|
|
|
unset( $this->object, $this->context ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testCompare() |
45
|
|
|
{ |
46
|
|
|
$this->assertEquals( 1, count( $this->object->compare( '==', 'service.type', 'delivery' )->search() ) ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function testFind() |
51
|
|
|
{ |
52
|
|
|
$item = $this->object->uses( ['price'] )->find( 'unitcode' ); |
53
|
|
|
|
54
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Service\Item\Iface::class, $item ); |
55
|
|
|
$this->assertEquals( 2, count( $item->getRefItems( 'price' ) ) ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testFunction() |
60
|
|
|
{ |
61
|
|
|
$str = $this->object->function( 'service:has', ['domain', 'type', 'refid'] ); |
62
|
|
|
$this->assertEquals( 'service:has("domain","type","refid")', $str ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testGet() |
67
|
|
|
{ |
68
|
|
|
$item = $this->object->uses( ['price'] )->get( $this->getServiceItem()->getId() ); |
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Service\Item\Iface::class, $item ); |
71
|
|
|
$this->assertEquals( 2, count( $item->getRefItems( 'price' ) ) ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testGetProvider() |
76
|
|
|
{ |
77
|
|
|
$provider = $this->object->getProvider( $this->getServiceItem()->getId() ); |
78
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Service\Provider\Iface::class, $provider ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testGetProviders() |
83
|
|
|
{ |
84
|
|
|
$providers = $this->object->getProviders( 'delivery' ); |
85
|
|
|
$this->assertGreaterThan( 0, count( $providers ) ); |
86
|
|
|
|
87
|
|
|
foreach( $providers as $provider ) { |
88
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Service\Provider\Iface::class, $provider ); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testParse() |
94
|
|
|
{ |
95
|
|
|
$cond = ['&&' => [['>' => ['service.status' => 0]], ['==' => ['service.type' => 'delivery']]]]; |
96
|
|
|
$this->assertEquals( 1, count( $this->object->parse( $cond )->search() ) ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
public function testProcess() |
101
|
|
|
{ |
102
|
|
|
$form = new \Aimeos\MShop\Common\Helper\Form\Standard(); |
103
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem(); |
104
|
|
|
$serviceId = \Aimeos\MShop::create( $this->context, 'service' )->findItem( 'unitcode' )->getId(); |
105
|
|
|
|
106
|
|
|
$provider = $this->getMockBuilder( \Aimeos\MShop\Service\Provider\Delivery\Standard::class ) |
107
|
|
|
->disableOriginalConstructor() |
108
|
|
|
->setMethods( ['process'] ) |
109
|
|
|
->getMock(); |
110
|
|
|
|
111
|
|
|
$manager = $this->getMockBuilder( \Aimeos\MShop\Service\Manager\Standard::class ) |
112
|
|
|
->setConstructorArgs( [$this->context] ) |
113
|
|
|
->setMethods( ['getProvider'] ) |
114
|
|
|
->getMock(); |
115
|
|
|
|
116
|
|
|
\Aimeos\MShop::inject( 'service', $manager ); |
117
|
|
|
|
118
|
|
|
$manager->expects( $this->once() )->method( 'getProvider' )->will( $this->returnValue( $provider ) ); |
119
|
|
|
$provider->expects( $this->once() )->method( 'process' )->will( $this->returnValue( $form ) ); |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
$object = new \Aimeos\Controller\Frontend\Service\Standard( $this->context ); |
123
|
|
|
$result = $object->process( $item, $serviceId, [], [] ); |
124
|
|
|
|
125
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Helper\Form\Iface::class, $result ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testSearch() |
130
|
|
|
{ |
131
|
|
|
$total = 0; |
132
|
|
|
$items = $this->object->uses( ['price'] )->type( 'delivery' )->search( $total ); |
133
|
|
|
|
134
|
|
|
$this->assertEquals( 1, count( $items ) ); |
135
|
|
|
$this->assertEquals( 1, $total ); |
136
|
|
|
$this->assertEquals( 2, count( current( $items )->getRefItems( 'price' ) ) ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function testSlice() |
141
|
|
|
{ |
142
|
|
|
$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
public function testSort() |
147
|
|
|
{ |
148
|
|
|
$this->assertEquals( 4, count( $this->object->sort( 'type' )->search() ) ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testSortGeneric() |
153
|
|
|
{ |
154
|
|
|
$this->assertEquals( 4, count( $this->object->sort( 'service.status' )->search() ) ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testSortMultiple() |
159
|
|
|
{ |
160
|
|
|
$this->assertEquals( 4, count( $this->object->sort( 'service.status,-service.id' )->search() ) ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testSortType() |
165
|
|
|
{ |
166
|
|
|
$result = $this->object->sort( 'type' )->search(); |
167
|
|
|
$this->assertEquals( 'unitcode', current( $result )->getCode() ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
public function testSortTypeDesc() |
172
|
|
|
{ |
173
|
|
|
$result = $this->object->sort( '-type' )->search(); |
174
|
|
|
$this->assertStringStartsWith( 'unitpaymentcode', current( $result )->getCode() ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
public function testUpdatePush() |
179
|
|
|
{ |
180
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
181
|
|
|
$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
182
|
|
|
|
183
|
|
|
$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnValue( $response ) ); |
184
|
|
|
|
185
|
|
|
$this->assertInstanceOf( \Psr\Http\Message\ResponseInterface::class, $this->object->updatePush( $request, $response, 'unitcode' ) ); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
public function testUpdateSync() |
190
|
|
|
{ |
191
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem(); |
192
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
193
|
|
|
|
194
|
|
|
$provider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' ) |
195
|
|
|
->setMethods( ['updateSync', 'query', 'isImplemented'] ) |
196
|
|
|
->disableOriginalConstructor() |
197
|
|
|
->getMock(); |
198
|
|
|
|
199
|
|
|
$orderManager = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' ) |
200
|
|
|
->setConstructorArgs( array( $this->context ) ) |
201
|
|
|
->setMethods( ['getItem'] ) |
202
|
|
|
->getMock(); |
203
|
|
|
|
204
|
|
|
$serviceManager = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' ) |
205
|
|
|
->setConstructorArgs( array( $this->context ) ) |
206
|
|
|
->setMethods( ['getProvider'] ) |
207
|
|
|
->getMock(); |
208
|
|
|
|
209
|
|
|
\Aimeos\MShop::inject( 'order', $orderManager ); |
210
|
|
|
\Aimeos\MShop::inject( 'service', $serviceManager ); |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
$orderManager->expects( $this->once() )->method( 'getItem' )->will( $this->returnValue( $item ) ); |
214
|
|
|
$serviceManager->expects( $this->once() )->method( 'getProvider' )->will( $this->returnValue( $provider ) ); |
215
|
|
|
$provider->expects( $this->once() )->method( 'updateSync' )->will( $this->returnValue( $item ) ); |
216
|
|
|
$provider->expects( $this->once() )->method( 'isImplemented' )->will( $this->returnValue( true ) ); |
217
|
|
|
$provider->expects( $this->once() )->method( 'query' ); |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
$object = new \Aimeos\Controller\Frontend\Service\Standard( $this->context ); |
221
|
|
|
$object->updateSync( $request, 'unitcode', -1 ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
public function testUses() |
226
|
|
|
{ |
227
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface |
233
|
|
|
*/ |
234
|
|
|
protected function getServiceItem() |
235
|
|
|
{ |
236
|
|
|
$manager = \Aimeos\MShop\Service\Manager\Factory::create( \TestHelperFrontend::getContext() ); |
237
|
|
|
return $manager->findItem( 'unitcode' ); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|