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\Base\Service\Transaction; |
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\Base\Service\Transaction\Standard( $this->context ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
protected function tearDown() : void |
28
|
|
|
{ |
29
|
|
|
unset( $this->object, $this->context ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function testAggregate() |
34
|
|
|
{ |
35
|
|
|
$filter = $this->object->filter()->add( 'order.base.service.transaction.editor', '==', 'core' ); |
36
|
|
|
$result = $this->object->aggregate( $filter, 'order.base.service.transaction.type' )->toArray(); |
37
|
|
|
|
38
|
|
|
$this->assertEquals( 1, count( $result ) ); |
39
|
|
|
$this->assertEquals( 3, $result['payment'] ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testClear() |
44
|
|
|
{ |
45
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testDeleteItems() |
50
|
|
|
{ |
51
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testGetResourceType() |
56
|
|
|
{ |
57
|
|
|
$result = $this->object->getResourceType(); |
58
|
|
|
|
59
|
|
|
$this->assertContains( 'order/base/service/transaction', $result ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function testGetSearchAttributes() |
64
|
|
|
{ |
65
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
66
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute ); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testCreateItem() |
72
|
|
|
{ |
73
|
|
|
$actual = $this->object->create(); |
74
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Transaction\Iface::class, $actual ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testCreateSearch() |
79
|
|
|
{ |
80
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $this->object->filter() ); |
81
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $this->object->filter( true ) ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testSearchItem() |
86
|
|
|
{ |
87
|
|
|
$siteid = $this->context->locale()->getSiteId(); |
88
|
|
|
|
89
|
|
|
$total = 0; |
90
|
|
|
$search = $this->object->filter(); |
91
|
|
|
|
92
|
|
|
$expr = []; |
93
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.transaction.id', null ); |
94
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.transaction.siteid', $siteid ); |
95
|
|
|
$expr[] = $search->compare( '!=', 'order.base.service.transaction.parentid', null ); |
96
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.transaction.type', 'payment' ); |
97
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.transaction.currencyid', 'EUR' ); |
98
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.transaction.price', '2465.00' ); |
99
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.transaction.status', 6 ); |
100
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.transaction.mtime', '1970-01-01 00:00:00' ); |
101
|
|
|
$expr[] = $search->compare( '>=', 'order.base.service.transaction.ctime', '1970-01-01 00:00:00' ); |
102
|
|
|
$expr[] = $search->compare( '==', 'order.base.service.transaction.editor', $this->editor ); |
103
|
|
|
|
104
|
|
|
$search->setConditions( $search->and( $expr ) ); |
105
|
|
|
$result = $this->object->search( $search, [], $total ); |
106
|
|
|
|
107
|
|
|
$this->assertEquals( 1, count( $result ) ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testGetItem() |
112
|
|
|
{ |
113
|
|
|
$search = $this->object->filter()->slice( 0, 1 )->add( [ |
114
|
|
|
'order.base.service.transaction.price' => '2465.00', |
115
|
|
|
'order.base.service.transaction.editor' => $this->editor |
116
|
|
|
] ); |
117
|
|
|
$item = $this->object->search( $search )->first( new \RuntimeException( 'empty results' ) ); |
118
|
|
|
|
119
|
|
|
$actual = $this->object->get( $item->getId() ); |
120
|
|
|
$this->assertEquals( $item->getId(), $actual->getId() ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testSaveUpdateDeleteItem() |
125
|
|
|
{ |
126
|
|
|
$search = $this->object->filter()->add( ['order.base.service.transaction.price' => '2465.00'] ); |
127
|
|
|
$item = $this->object->search( $search )->first( new \RuntimeException( 'empty search result' ) ); |
128
|
|
|
|
129
|
|
|
$item->setId( null ); |
130
|
|
|
$resultSaved = $this->object->save( $item ); |
131
|
|
|
$itemSaved = $this->object->get( $item->getId() ); |
132
|
|
|
|
133
|
|
|
$itemExp = clone $itemSaved; |
134
|
|
|
$resultUpd = $this->object->save( $itemExp ); |
135
|
|
|
$itemUpd = $this->object->get( $itemExp->getId() ); |
136
|
|
|
|
137
|
|
|
$this->object->delete( $itemSaved->getId() ); |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
$this->assertTrue( $item->getId() !== null ); |
141
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
142
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
143
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
144
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
145
|
|
|
$this->assertEquals( $item->getPrice(), $itemSaved->getPrice() ); |
146
|
|
|
$this->assertEquals( $item->getConfig(), $itemSaved->getConfig() ); |
147
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
148
|
|
|
|
149
|
|
|
$this->assertEquals( $this->editor, $itemSaved->editor() ); |
150
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
151
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
152
|
|
|
|
153
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
154
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
155
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
156
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
157
|
|
|
$this->assertEquals( $itemExp->getPrice(), $itemUpd->getPrice() ); |
158
|
|
|
$this->assertEquals( $itemExp->getConfig(), $itemUpd->getConfig() ); |
159
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
160
|
|
|
|
161
|
|
|
$this->assertEquals( $this->editor, $itemUpd->editor() ); |
162
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
163
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
164
|
|
|
|
165
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
166
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
167
|
|
|
|
168
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
169
|
|
|
$this->object->get( $itemSaved->getId() ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testGetSubManager() |
174
|
|
|
{ |
175
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
176
|
|
|
$this->object->getSubManager( 'unknown' ); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|