1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2022 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Aimeos\MShop\Order\Manager\Basket; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
12
|
|
|
{ |
13
|
|
|
private $context; |
14
|
|
|
private $object; |
15
|
|
|
private $editor = ''; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
$this->context = \TestHelper::context(); |
21
|
|
|
$this->editor = $this->context->editor(); |
22
|
|
|
|
23
|
|
|
$this->object = new \Aimeos\MShop\Order\Manager\Basket\Standard( $this->context ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
protected function tearDown() : void |
28
|
|
|
{ |
29
|
|
|
unset( $this->object ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function testClear() |
34
|
|
|
{ |
35
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testDeleteItems() |
40
|
|
|
{ |
41
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public function testGetResourceType() |
46
|
|
|
{ |
47
|
|
|
$result = $this->object->getResourceType(); |
48
|
|
|
|
49
|
|
|
$this->assertContains( 'order/basket', $result ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testCreateItem() |
54
|
|
|
{ |
55
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Basket\Iface::class, $this->object->create() ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testGetItem() |
60
|
|
|
{ |
61
|
|
|
$search = $this->object->filter()->slice( 0, 1 ); |
62
|
|
|
$expected = $this->object->search( $search )->first( new \Exception( 'No order basket item found' ) ); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( $expected, $this->object->get( $expected->getId() ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testSaveUpdateDeleteItem() |
69
|
|
|
{ |
70
|
|
|
$search = $this->object->filter()->add( ['order.basket.customerid' => -1] )->slice( 0, 1 ); |
71
|
|
|
$item = $this->object->search( $search )->first( new \Exception( 'No order basket item found' ) ); |
72
|
|
|
|
73
|
|
|
$item->setId( 'unittest_1' ); |
74
|
|
|
$resultSaved = $this->object->save( $item ); |
75
|
|
|
$itemSaved = $this->object->get( $item->getId() ); |
76
|
|
|
|
77
|
|
|
$itemExp = clone $itemSaved; |
78
|
|
|
$itemExp->setName( 'unit test' ); |
79
|
|
|
$resultUpd = $this->object->save( $itemExp ); |
80
|
|
|
$itemUpd = $this->object->get( $itemExp->getId() ); |
81
|
|
|
|
82
|
|
|
$this->object->delete( $itemSaved->getId() ); |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
86
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
87
|
|
|
$this->assertEquals( $item->getCustomerId(), $itemSaved->getCustomerId() ); |
88
|
|
|
$this->assertEquals( $item->getContent(), $itemSaved->getContent() ); |
89
|
|
|
$this->assertEquals( $item->getName(), $itemSaved->getName() ); |
90
|
|
|
|
91
|
|
|
$this->assertEquals( $this->editor, $itemSaved->editor() ); |
92
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
93
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
94
|
|
|
|
95
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
96
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
97
|
|
|
$this->assertEquals( $itemExp->getCustomerId(), $itemUpd->getCustomerId() ); |
98
|
|
|
$this->assertEquals( $itemExp->getContent(), $itemUpd->getContent() ); |
99
|
|
|
$this->assertEquals( $itemExp->getName(), $itemUpd->getName() ); |
100
|
|
|
|
101
|
|
|
$this->assertEquals( $this->editor, $itemUpd->editor() ); |
102
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
103
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
104
|
|
|
|
105
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
106
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
107
|
|
|
|
108
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
109
|
|
|
$this->object->get( $itemSaved->getId() ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testCreateSearch() |
114
|
|
|
{ |
115
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $this->object->filter() ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testSearchItems() |
120
|
|
|
{ |
121
|
|
|
$total = 0; |
122
|
|
|
$search = $this->object->filter(); |
123
|
|
|
$siteid = $this->context->locale()->getSiteId(); |
124
|
|
|
|
125
|
|
|
$expr = []; |
126
|
|
|
$expr[] = $search->compare( '!=', 'order.basket.id', null ); |
127
|
|
|
$expr[] = $search->compare( '==', 'order.basket.siteid', $siteid ); |
128
|
|
|
$expr[] = $search->compare( '==', 'order.basket.customerid', '-1' ); |
129
|
|
|
$expr[] = $search->compare( '>=', 'order.basket.name', '' ); |
130
|
|
|
$expr[] = $search->compare( '>=', 'order.basket.content', '' ); |
131
|
|
|
$expr[] = $search->compare( '>=', 'order.basket.mtime', '1970-01-01 00:00:00' ); |
132
|
|
|
$expr[] = $search->compare( '>=', 'order.basket.ctime', '1970-01-01 00:00:00' ); |
133
|
|
|
$expr[] = $search->compare( '==', 'order.basket.editor', $this->editor ); |
134
|
|
|
|
135
|
|
|
$search->setConditions( $search->and( $expr ) ); |
136
|
|
|
$result = $this->object->search( $search, [], $total )->toArray(); |
137
|
|
|
|
138
|
|
|
$this->assertEquals( 1, count( $result ) ); |
139
|
|
|
$this->assertEquals( 1, $total ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
public function testGetSubManager() |
144
|
|
|
{ |
145
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
146
|
|
|
$this->object->getSubManager( 'unknown' ); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|