1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JQAdm\Product\Price; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $view; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->view = \TestHelper::view(); |
22
|
|
|
$this->context = \TestHelper::context(); |
23
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Product\Price\Standard( $this->context ); |
25
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context ); |
26
|
|
|
$this->object->setAimeos( \TestHelper::getAimeos() ); |
27
|
|
|
$this->object->setView( $this->view ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function tearDown() : void |
32
|
|
|
{ |
33
|
|
|
unset( $this->object, $this->view, $this->context ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testBatch() |
38
|
|
|
{ |
39
|
|
|
$this->view->items = map( \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNC', ['price'] ) ); |
40
|
|
|
|
41
|
|
|
$param = array( |
42
|
|
|
'site' => 'unittest', |
43
|
|
|
'price' => array( |
44
|
|
|
'price.taxrate' => '15', |
45
|
|
|
'rebatepercent' => 10, |
46
|
|
|
'valuepercent' => 10, |
47
|
|
|
'costspercent' => '5' |
48
|
|
|
), |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
52
|
|
|
$this->view->addHelper( 'param', $helper ); |
53
|
|
|
|
54
|
|
|
$result = $this->object->batch(); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$prices = $this->view->items->first()->getRefItems( 'price' ); |
57
|
|
|
|
58
|
|
|
$this->assertEquals( 2, count( $prices ) ); |
59
|
|
|
$this->assertEquals( '15.00', $prices->getTaxrate()->first() ); |
60
|
|
|
$this->assertEquals( '0.00', $prices->getRebate()->first() ); |
61
|
|
|
$this->assertEquals( '660.00', $prices->getValue()->first() ); |
62
|
|
|
$this->assertEquals( '31.50', $prices->getCosts()->first() ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testCreate() |
67
|
|
|
{ |
68
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
69
|
|
|
|
70
|
|
|
$this->view->item = $manager->create(); |
71
|
|
|
$result = $this->object->create(); |
72
|
|
|
|
73
|
|
|
$this->assertStringContainsString( 'item-price', $result ); |
74
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testCopy() |
79
|
|
|
{ |
80
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
81
|
|
|
|
82
|
|
|
$this->view->item = $manager->find( 'CNC', array( 'price' ) ); |
83
|
|
|
$result = $this->object->copy(); |
84
|
|
|
|
85
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
86
|
|
|
$this->assertStringContainsString( '"price.type":"default"', $result ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testDelete() |
91
|
|
|
{ |
92
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
93
|
|
|
|
94
|
|
|
$this->view->item = $manager->create(); |
95
|
|
|
$result = $this->object->delete(); |
96
|
|
|
|
97
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
98
|
|
|
$this->assertEmpty( $result ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testGet() |
103
|
|
|
{ |
104
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
105
|
|
|
|
106
|
|
|
$this->view->item = $manager->find( 'CNC', array( 'price' ) ); |
107
|
|
|
$result = $this->object->get(); |
108
|
|
|
|
109
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
110
|
|
|
$this->assertStringContainsString( '"price.type":"default"', $result ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
public function testSave() |
115
|
|
|
{ |
116
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
117
|
|
|
$item = $manager->create(); |
118
|
|
|
|
119
|
|
|
$param = array( |
120
|
|
|
'site' => 'unittest', |
121
|
|
|
'pricecustom' => 1, |
122
|
|
|
'price' => [[ |
123
|
|
|
'price.id' => '', |
124
|
|
|
'price.value' => '10.00', |
125
|
|
|
'price.costs' => '1.00', |
126
|
|
|
'price.rebate' => '5.00', |
127
|
|
|
'price.taxrate' => '20.00', |
128
|
|
|
'price.quantity' => '2', |
129
|
|
|
'price.currencyid' => 'EUR', |
130
|
|
|
'price.type' => 'default', |
131
|
|
|
'product.lists.type' => 'default', |
132
|
|
|
]], |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
136
|
|
|
$this->view->addHelper( 'param', $helper ); |
137
|
|
|
$this->view->item = $item; |
138
|
|
|
|
139
|
|
|
$result = $this->object->save(); |
140
|
|
|
|
141
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
142
|
|
|
$this->assertEmpty( $result ); |
143
|
|
|
$this->assertEquals( 1, count( $item->getListItems( 'price' ) ) ); |
144
|
|
|
$this->assertEquals( 1, count( $item->getListItems( 'attribute', 'custom', 'price' ) ) ); |
145
|
|
|
|
146
|
|
|
foreach( $item->getListItems( 'price' ) as $listItem ) |
147
|
|
|
{ |
148
|
|
|
$this->assertEquals( 'price', $listItem->getDomain() ); |
149
|
|
|
|
150
|
|
|
$refItem = $listItem->getRefItem(); |
151
|
|
|
$this->assertEquals( 'EUR', $refItem->getCurrencyId() ); |
152
|
|
|
$this->assertEquals( '2', $refItem->getQuantity() ); |
153
|
|
|
$this->assertEquals( '10.00', $refItem->getValue() ); |
154
|
|
|
$this->assertEquals( '1.00', $refItem->getCosts() ); |
155
|
|
|
$this->assertEquals( '5.00', $refItem->getRebate() ); |
156
|
|
|
$this->assertEquals( '20.00', $refItem->getTaxRate() ); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
public function testSaveException() |
162
|
|
|
{ |
163
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Price\Standard::class ) |
164
|
|
|
->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) ) |
165
|
|
|
->setMethods( array( 'fromArray' ) ) |
166
|
|
|
->getMock(); |
167
|
|
|
|
168
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
169
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
170
|
|
|
|
171
|
|
|
$view = \TestHelper::view(); |
172
|
|
|
$view->item = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
173
|
|
|
|
174
|
|
|
$object->setView( $view ); |
175
|
|
|
|
176
|
|
|
$this->expectException( \RuntimeException::class ); |
177
|
|
|
$object->save(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
public function testSaveMShopException() |
182
|
|
|
{ |
183
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Price\Standard::class ) |
184
|
|
|
->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) ) |
185
|
|
|
->setMethods( array( 'fromArray' ) ) |
186
|
|
|
->getMock(); |
187
|
|
|
|
188
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
189
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
190
|
|
|
|
191
|
|
|
$this->view = \TestHelper::view(); |
192
|
|
|
$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
193
|
|
|
|
194
|
|
|
$object->setView( $this->view ); |
195
|
|
|
|
196
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
197
|
|
|
$object->save(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
public function testSearch() |
202
|
|
|
{ |
203
|
|
|
$this->assertEmpty( $this->object->search() ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testGetSubClient() |
208
|
|
|
{ |
209
|
|
|
$this->expectException( \Aimeos\Admin\JQAdm\Exception::class ); |
210
|
|
|
$this->object->getSubClient( 'unknown' ); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|