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