1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Lists\Price; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
$this->context = \TestHelper::context(); |
21
|
|
|
$this->object = new \Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Lists\Price\Standard( $this->context ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
protected function tearDown() : void |
26
|
|
|
{ |
27
|
|
|
unset( $this->object, $this->context ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
public function testProcess() |
32
|
|
|
{ |
33
|
|
|
$dom = new \DOMDocument(); |
34
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
35
|
|
|
|
36
|
|
|
$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
37
|
|
|
<price> |
38
|
|
|
<priceitem lists.type="default"> |
39
|
|
|
<price.type><![CDATA[test]]></price.type> |
40
|
|
|
<price.currencyid><![CDATA[EUR]]></price.currencyid> |
41
|
|
|
<price.taxrate><![CDATA[20.00]]></price.taxrate> |
42
|
|
|
<price.quantity><![CDATA[1]]></price.quantity> |
43
|
|
|
<price.value><![CDATA[10.00]]></price.value> |
44
|
|
|
</priceitem> |
45
|
|
|
<priceitem lists.type="test"> |
46
|
|
|
<price.type><![CDATA[default]]></price.type> |
47
|
|
|
<price.currencyid><![CDATA[USD]]></price.currencyid> |
48
|
|
|
<price.taxrate><![CDATA[10.00]]></price.taxrate> |
49
|
|
|
<price.quantity><![CDATA[2]]></price.quantity> |
50
|
|
|
<price.value><![CDATA[20.00]]></price.value> |
51
|
|
|
</priceitem> |
52
|
|
|
</price>' ); |
53
|
|
|
|
54
|
|
|
$product = $this->object->process( $product, $dom->firstChild ); |
55
|
|
|
|
56
|
|
|
$pos = 0; |
57
|
|
|
$expected = [ |
58
|
|
|
['default', 'test', '1', 'EUR', '20.00', '10.00'], |
59
|
|
|
['test', 'default', '2', 'USD', '10.00', '20.00'], |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
$listItems = $product->getListItems( 'price' ); |
63
|
|
|
$this->assertEquals( 2, count( $listItems ) ); |
64
|
|
|
|
65
|
|
|
foreach( $listItems as $listItem ) |
66
|
|
|
{ |
67
|
|
|
$this->assertEquals( $expected[$pos][0], $listItem->getType() ); |
68
|
|
|
$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getType() ); |
69
|
|
|
$this->assertEquals( $expected[$pos][2], $listItem->getRefItem()->getQuantity() ); |
70
|
|
|
$this->assertEquals( $expected[$pos][3], $listItem->getRefItem()->getCurrencyId() ); |
71
|
|
|
$this->assertEquals( $expected[$pos][4], $listItem->getRefItem()->getTaxrate() ); |
72
|
|
|
$this->assertEquals( $expected[$pos][5], $listItem->getRefItem()->getValue() ); |
73
|
|
|
$pos++; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testProcessUpdate() |
79
|
|
|
{ |
80
|
|
|
$dom = new \DOMDocument(); |
81
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'price' ); |
82
|
|
|
$listManager = \Aimeos\MShop::create( $this->context, 'product/lists' ); |
83
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
84
|
|
|
|
85
|
|
|
$product->addListItem( 'price', |
86
|
|
|
$listManager->create()->setType( 'default' )->setId( 1 ), |
87
|
|
|
$manager->create()->setType( 'test' )->setCurrencyId( 'EUR' ) |
88
|
|
|
->setTaxrate( '20.00' )->setQuantity( 1 )->setValue( '10.00' ) |
89
|
|
|
); |
90
|
|
|
$product->addListItem( 'price', |
91
|
|
|
$listManager->create()->setType( 'test' )->setId( 2 ), |
92
|
|
|
$manager->create()->setType( 'default' )->setCurrencyId( 'USD' ) |
93
|
|
|
->setTaxrate( '10.00' )->setQuantity( 2 )->setValue( '20.00' ) |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
97
|
|
|
<price> |
98
|
|
|
<priceitem lists.type="test"> |
99
|
|
|
<price.type><![CDATA[default]]></price.type> |
100
|
|
|
<price.currencyid><![CDATA[USD]]></price.currencyid> |
101
|
|
|
<price.taxrate><![CDATA[10.00]]></price.taxrate> |
102
|
|
|
<price.quantity><![CDATA[2]]></price.quantity> |
103
|
|
|
<price.value><![CDATA[20.00]]></price.value> |
104
|
|
|
</priceitem> |
105
|
|
|
<priceitem lists.type="default"> |
106
|
|
|
<price.type><![CDATA[test]]></price.type> |
107
|
|
|
<price.currencyid><![CDATA[EUR]]></price.currencyid> |
108
|
|
|
<price.taxrate><![CDATA[20.00]]></price.taxrate> |
109
|
|
|
<price.quantity><![CDATA[1]]></price.quantity> |
110
|
|
|
<price.value><![CDATA[10.00]]></price.value> |
111
|
|
|
</priceitem> |
112
|
|
|
</price>' ); |
113
|
|
|
|
114
|
|
|
$product = $this->object->process( $product, $dom->firstChild ); |
115
|
|
|
|
116
|
|
|
$pos = 0; |
117
|
|
|
$expected = [ |
118
|
|
|
['test', 'default', '2', 'USD', '10.00', '20.00'], |
119
|
|
|
['default', 'test', '1', 'EUR', '20.00', '10.00'], |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
$listItems = $product->getListItems(); |
123
|
|
|
$this->assertEquals( 2, count( $listItems ) ); |
124
|
|
|
|
125
|
|
|
foreach( $listItems as $listItem ) |
126
|
|
|
{ |
127
|
|
|
$this->assertEquals( $expected[$pos][0], $listItem->getType() ); |
128
|
|
|
$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getType() ); |
129
|
|
|
$this->assertEquals( $expected[$pos][2], $listItem->getRefItem()->getQuantity() ); |
130
|
|
|
$this->assertEquals( $expected[$pos][3], $listItem->getRefItem()->getCurrencyId() ); |
131
|
|
|
$this->assertEquals( $expected[$pos][4], $listItem->getRefItem()->getTaxrate() ); |
132
|
|
|
$this->assertEquals( $expected[$pos][5], $listItem->getRefItem()->getValue() ); |
133
|
|
|
$pos++; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
public function testProcessDelete() |
139
|
|
|
{ |
140
|
|
|
$dom = new \DOMDocument(); |
141
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'price' ); |
142
|
|
|
$listManager = \Aimeos\MShop::create( $this->context, 'product/lists' ); |
143
|
|
|
$product = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
144
|
|
|
|
145
|
|
|
$product->addListItem( 'price', |
146
|
|
|
$listManager->create()->setType( 'default' )->setId( 1 ), |
147
|
|
|
$manager->create()->setType( 'test' )->setCurrencyId( 'EUR' ) |
148
|
|
|
->setTaxrate( '20.00' )->setQuantity( 1 )->setValue( '10.00' ) |
149
|
|
|
); |
150
|
|
|
$product->addListItem( 'price', |
151
|
|
|
$listManager->create()->setType( 'test' )->setId( 2 ), |
152
|
|
|
$manager->create()->setType( 'default' )->setCurrencyId( 'USD' ) |
153
|
|
|
->setTaxrate( '10.00' )->setQuantity( 2 )->setValue( '20.00' ) |
154
|
|
|
); |
155
|
|
|
|
156
|
|
|
$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
157
|
|
|
<price> |
158
|
|
|
<priceitem lists.type="test"> |
159
|
|
|
<price.type><![CDATA[default]]></price.type> |
160
|
|
|
<price.currencyid><![CDATA[USD]]></price.currencyid> |
161
|
|
|
<price.taxrate><![CDATA[10.00]]></price.taxrate> |
162
|
|
|
<price.quantity><![CDATA[2]]></price.quantity> |
163
|
|
|
<price.value><![CDATA[20.00]]></price.value> |
164
|
|
|
</priceitem> |
165
|
|
|
</price>' ); |
166
|
|
|
|
167
|
|
|
$product = $this->object->process( $product, $dom->firstChild ); |
168
|
|
|
|
169
|
|
|
$pos = 0; |
170
|
|
|
$expected = [['test', 'default', '2', 'USD', '10.00', '20.00']]; |
171
|
|
|
|
172
|
|
|
$listItems = $product->getListItems(); |
173
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
174
|
|
|
|
175
|
|
|
foreach( $listItems as $listItem ) |
176
|
|
|
{ |
177
|
|
|
$this->assertEquals( $expected[$pos][0], $listItem->getType() ); |
178
|
|
|
$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getType() ); |
179
|
|
|
$this->assertEquals( $expected[$pos][2], $listItem->getRefItem()->getQuantity() ); |
180
|
|
|
$this->assertEquals( $expected[$pos][3], $listItem->getRefItem()->getCurrencyId() ); |
181
|
|
|
$this->assertEquals( $expected[$pos][4], $listItem->getRefItem()->getTaxrate() ); |
182
|
|
|
$this->assertEquals( $expected[$pos][5], $listItem->getRefItem()->getValue() ); |
183
|
|
|
$pos++; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|