1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018-2020 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Subscription\Manager; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $editor = ''; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->editor = \TestHelperMShop::getContext()->getEditor(); |
22
|
|
|
$this->context = \TestHelperMShop::getContext(); |
23
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\MShop\Subscription\Manager\Standard( $this->context ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function tearDown() : void |
29
|
|
|
{ |
30
|
|
|
unset( $this->object ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testAggregate() |
35
|
|
|
{ |
36
|
|
|
$search = $this->object->createSearch(); |
37
|
|
|
$search->setConditions( $search->compare( '==', 'subscription.editor', 'core:lib/mshoplib' ) ); |
38
|
|
|
$result = $this->object->aggregate( $search, 'subscription.status' )->toArray(); |
39
|
|
|
|
40
|
|
|
$this->assertEquals( 2, count( $result ) ); |
41
|
|
|
$this->assertArrayHasKey( '0', $result ); |
42
|
|
|
$this->assertArrayHasKey( '1', $result ); |
43
|
|
|
$this->assertEquals( 1, $result['0'] ); |
44
|
|
|
$this->assertEquals( 1, $result['1'] ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testClear() |
49
|
|
|
{ |
50
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testDeleteItems() |
55
|
|
|
{ |
56
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->deleteItems( [-1] ) ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
public function testGetResourceType() |
61
|
|
|
{ |
62
|
|
|
$result = $this->object->getResourceType(); |
63
|
|
|
|
64
|
|
|
$this->assertContains( 'subscription', $result ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testCreateItem() |
69
|
|
|
{ |
70
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Subscription\Item\Iface::class, $this->object->createItem() ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
public function testGetItem() |
75
|
|
|
{ |
76
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
77
|
|
|
$conditions = array( |
78
|
|
|
$search->compare( '==', 'subscription.status', 1 ), |
79
|
|
|
$search->compare( '==', 'subscription.editor', $this->editor ) |
80
|
|
|
); |
81
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
82
|
|
|
$results = $this->object->searchItems( $search )->toArray(); |
83
|
|
|
|
84
|
|
|
if( ( $expected = reset( $results ) ) === false ) { |
85
|
|
|
throw new \RuntimeException( sprintf( 'No subscription found in mshop_subscription with status "%1$s"', 1 ) ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$actual = $this->object->getItem( $expected->getId() ); |
89
|
|
|
$this->assertEquals( $expected, $actual ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testSaveUpdateDeleteItem() |
94
|
|
|
{ |
95
|
|
|
$search = $this->object->createSearch(); |
96
|
|
|
$conditions = array( |
97
|
|
|
$search->compare( '==', 'subscription.status', 1 ), |
98
|
|
|
$search->compare( '==', 'subscription.editor', $this->editor ) |
99
|
|
|
); |
100
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
101
|
|
|
$results = $this->object->searchItems( $search )->toArray(); |
102
|
|
|
|
103
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
104
|
|
|
throw new \RuntimeException( 'No subscription item found.' ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$item->setId( null ); |
108
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
109
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
110
|
|
|
|
111
|
|
|
$itemExp = clone $itemSaved; |
112
|
|
|
$itemExp->setInterval( 'P0Y0M1W0D' ); |
113
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
114
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
115
|
|
|
|
116
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
$this->assertTrue( $item->getId() !== null ); |
120
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
121
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
122
|
|
|
$this->assertEquals( $item->getOrderProductId(), $itemSaved->getOrderProductId() ); |
123
|
|
|
$this->assertEquals( $item->getProductId(), $itemSaved->getProductId() ); |
124
|
|
|
$this->assertEquals( $item->getDateNext(), $itemSaved->getDateNext() ); |
125
|
|
|
$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
126
|
|
|
$this->assertEquals( $item->getInterval(), $itemSaved->getInterval() ); |
127
|
|
|
$this->assertEquals( $item->getPeriod(), $itemSaved->getPeriod() ); |
128
|
|
|
$this->assertEquals( $item->getReason(), $itemSaved->getReason() ); |
129
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
130
|
|
|
|
131
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
132
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
133
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
134
|
|
|
|
135
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
136
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
137
|
|
|
$this->assertEquals( $itemExp->getOrderProductId(), $itemUpd->getOrderProductId() ); |
138
|
|
|
$this->assertEquals( $itemExp->getProductId(), $itemUpd->getProductId() ); |
139
|
|
|
$this->assertEquals( $itemExp->getDateNext(), $itemUpd->getDateNext() ); |
140
|
|
|
$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
141
|
|
|
$this->assertEquals( $itemExp->getInterval(), $itemUpd->getInterval() ); |
142
|
|
|
$this->assertEquals( $itemExp->getPeriod(), $itemUpd->getPeriod() ); |
143
|
|
|
$this->assertEquals( $itemExp->getReason(), $itemUpd->getReason() ); |
144
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
145
|
|
|
|
146
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
147
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
148
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
149
|
|
|
|
150
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
151
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
152
|
|
|
|
153
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
154
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testCreateSearch() |
159
|
|
|
{ |
160
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Iface::class, $this->object->createSearch() ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testCreateSearchDefault() |
165
|
|
|
{ |
166
|
|
|
$result = $this->object->createSearch( true ); |
167
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Expression\Compare\Iface::class, $result->getConditions() ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
public function testCreateSearchSite() |
172
|
|
|
{ |
173
|
|
|
$result = $this->object->createSearch( false, true ); |
174
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Expression\Combine\Iface::class, $result->getConditions() ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
public function testSearchItems() |
179
|
|
|
{ |
180
|
|
|
$siteid = $this->context->getLocale()->getSiteId(); |
181
|
|
|
|
182
|
|
|
$total = 0; |
183
|
|
|
$search = $this->object->createSearch(); |
184
|
|
|
|
185
|
|
|
$expr = []; |
186
|
|
|
$expr[] = $search->compare( '!=', 'subscription.id', null ); |
187
|
|
|
$expr[] = $search->compare( '==', 'subscription.siteid', $siteid ); |
188
|
|
|
$expr[] = $search->compare( '!=', 'subscription.ordbaseid', null ); |
189
|
|
|
$expr[] = $search->compare( '!=', 'subscription.ordprodid', null ); |
190
|
|
|
$expr[] = $search->compare( '==', 'subscription.datenext', '2000-01-01' ); |
191
|
|
|
$expr[] = $search->compare( '==', 'subscription.dateend', '2010-01-01' ); |
192
|
|
|
$expr[] = $search->compare( '==', 'subscription.interval', 'P0Y1M0W0D' ); |
193
|
|
|
$expr[] = $search->compare( '>=', 'subscription.productid', '' ); |
194
|
|
|
$expr[] = $search->compare( '==', 'subscription.period', 120 ); |
195
|
|
|
$expr[] = $search->compare( '==', 'subscription.reason', 1 ); |
196
|
|
|
$expr[] = $search->compare( '==', 'subscription.status', 1 ); |
197
|
|
|
$expr[] = $search->compare( '>=', 'subscription.mtime', '1970-01-01 00:00:00' ); |
198
|
|
|
$expr[] = $search->compare( '>=', 'subscription.ctime', '1970-01-01 00:00:00' ); |
199
|
|
|
$expr[] = $search->compare( '==', 'subscription.editor', $this->editor ); |
200
|
|
|
|
201
|
|
|
$expr[] = $search->compare( '!=', 'order.base.address.id', null ); |
202
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.siteid', $siteid ); |
203
|
|
|
$expr[] = $search->compare( '==', 'order.base.address.type', 'payment' ); |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
207
|
|
|
$result = $this->object->searchItems( $search, [], $total )->toArray(); |
208
|
|
|
|
209
|
|
|
$this->assertEquals( 1, count( $result ) ); |
210
|
|
|
$this->assertEquals( 1, $total ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
public function testSearchItemsTotal() |
215
|
|
|
{ |
216
|
|
|
$total = 0; |
217
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
218
|
|
|
$search->setConditions( $search->compare( '==', 'subscription.editor', $this->editor ) ); |
219
|
|
|
$items = $this->object->searchItems( $search, [], $total )->toArray(); |
220
|
|
|
|
221
|
|
|
$this->assertEquals( 1, count( $items ) ); |
222
|
|
|
$this->assertEquals( 2, $total ); |
223
|
|
|
|
224
|
|
|
foreach( $items as $itemId => $item ) { |
225
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
public function testSearchItemsRef() |
231
|
|
|
{ |
232
|
|
|
$total = 0; |
233
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
234
|
|
|
$search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) ); |
235
|
|
|
$item = $this->object->searchItems( $search, ['order/base', 'order/base/product'], $total )->first(); |
236
|
|
|
|
237
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $item->getBaseItem() ); |
238
|
|
|
$this->assertEquals( 4, count( $item->getBaseItem()->getProducts() ) ); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
|
242
|
|
|
public function testGetSubManager() |
243
|
|
|
{ |
244
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
245
|
|
|
$this->object->getSubManager( 'unknown' ); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|