1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JQAdm\Product\Selection; |
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 = \TestHelperJqadm::getView(); |
22
|
|
|
$this->context = \TestHelperJqadm::getContext(); |
23
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Product\Selection\Standard( $this->context ); |
25
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context ); |
26
|
|
|
$this->object->setAimeos( \TestHelperJqadm::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 testCreate() |
38
|
|
|
{ |
39
|
|
|
$param = array( |
40
|
|
|
'site' => 'unittest', |
41
|
|
|
'selection' => array( |
42
|
|
|
array( |
43
|
|
|
'product.id' => '123', |
44
|
|
|
'product.siteid' => '1', |
45
|
|
|
'product.code' => 'testprod', |
46
|
|
|
'product.label' => 'test product', |
47
|
|
|
'stock.stocklevel' => 10, |
48
|
|
|
'attr' => array( |
49
|
|
|
array( |
50
|
|
|
'product.lists.id' => '456', |
51
|
|
|
'product.lists.siteid' => '2', |
52
|
|
|
'product.lists.refid' => '789', |
53
|
|
|
'attribute.label' => 'test attribute', |
54
|
|
|
) |
55
|
|
|
), |
56
|
|
|
) |
57
|
|
|
), |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
61
|
|
|
$this->view->addHelper( 'param', $helper ); |
62
|
|
|
|
63
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
64
|
|
|
|
65
|
|
|
$this->view->item = $manager->create(); |
66
|
|
|
$result = $this->object->create(); |
67
|
|
|
|
68
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
69
|
|
|
$this->assertStringContainsString( 'item-selection', $result ); |
70
|
|
|
$this->assertStringContainsString( '"product.code":"testprod"', $result ); |
71
|
|
|
$this->assertStringContainsString( '"attribute.label":"test attribute"', $result ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testCopy() |
76
|
|
|
{ |
77
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
78
|
|
|
|
79
|
|
|
$this->view->item = $manager->find( 'U:TEST', ['attribute', 'product'] ); |
80
|
|
|
$result = $this->object->copy(); |
81
|
|
|
|
82
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
83
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB01_', $result ); |
84
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB02_', $result ); |
85
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB03_', $result ); |
86
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB04_', $result ); |
87
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB05_', $result ); |
88
|
|
|
$this->assertStringContainsString( '"attribute.label":"product\/length\/30"', $result ); |
89
|
|
|
$this->assertStringContainsString( '"attribute.label":"product\/length\/32"', $result ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testGet() |
94
|
|
|
{ |
95
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
96
|
|
|
$this->view->item = $manager->find( 'U:TEST', ['attribute', 'product'] ); |
97
|
|
|
|
98
|
|
|
$result = $this->object->get(); |
99
|
|
|
|
100
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
101
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB01"', $result ); |
102
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB02"', $result ); |
103
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB03"', $result ); |
104
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB04"', $result ); |
105
|
|
|
$this->assertStringContainsString( '"product.code":"U:TESTSUB05"', $result ); |
106
|
|
|
$this->assertStringContainsString( '"attribute.label":"product\/length\/30"', $result ); |
107
|
|
|
$this->assertStringContainsString( '"attribute.label":"product\/length\/32"', $result ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testSave() |
112
|
|
|
{ |
113
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
114
|
|
|
$this->view->item = $manager->find( 'U:TEST' ); |
115
|
|
|
|
116
|
|
|
$param = array( |
117
|
|
|
'site' => 'unittest', |
118
|
|
|
'selection' => array( |
119
|
|
|
array( |
120
|
|
|
'product.lists.id' => '', |
121
|
|
|
'product.id' => '', |
122
|
|
|
'product.code' => 'testprod', |
123
|
|
|
'product.label' => 'test product', |
124
|
|
|
'product.status' => '1', |
125
|
|
|
'stock.stocklevel' => 20, |
126
|
|
|
'attr' => array( |
127
|
|
|
array( |
128
|
|
|
'product.lists.id' => '', |
129
|
|
|
'product.lists.refid' => '789', |
130
|
|
|
'attribute.label' => 'test attribute', |
131
|
|
|
) |
132
|
|
|
) |
133
|
|
|
), |
134
|
|
|
), |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
138
|
|
|
$this->view->addHelper( 'param', $helper ); |
139
|
|
|
|
140
|
|
|
$result = $this->object->save(); |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
144
|
|
|
$product = $manager->find( 'testprod', ['stock'] ); |
145
|
|
|
$manager->delete( $product ); |
146
|
|
|
|
147
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'stock' ); |
148
|
|
|
$stocks = $manager->search( $manager->filter()->add( ['stock.productid' => $product->getId()] ) ); |
149
|
|
|
$manager->delete( $stocks->toArray() ); |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
153
|
|
|
$this->assertEmpty( $result ); |
154
|
|
|
|
155
|
|
|
$variants = $this->view->item->getListItems( 'product' ); |
156
|
|
|
$this->assertEquals( 1, count( $variants ) ); |
157
|
|
|
|
158
|
|
|
$refItem = $variants->first()->getRefItem(); |
159
|
|
|
$this->assertEquals( 'testprod', $refItem->getCode() ); |
160
|
|
|
$this->assertEquals( 'test product', $refItem->getLabel() ); |
161
|
|
|
$this->assertEquals( 1, $refItem->getStatus() ); |
162
|
|
|
|
163
|
|
|
$attributes = $refItem->getListItems( 'attribute' ); |
164
|
|
|
$this->assertEquals( 1, count( $attributes ) ); |
165
|
|
|
$this->assertEquals( '789', $attributes->first()->getRefId() ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
public function testSaveException() |
170
|
|
|
{ |
171
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Selection\Standard::class ) |
172
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
173
|
|
|
->setMethods( array( 'fromArray' ) ) |
174
|
|
|
->getMock(); |
175
|
|
|
|
176
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
177
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
178
|
|
|
|
179
|
|
|
$this->view = \TestHelperJqadm::getView(); |
180
|
|
|
$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->find( 'U:TEST' ); |
181
|
|
|
|
182
|
|
|
$object->setView( $this->view ); |
183
|
|
|
|
184
|
|
|
$this->expectException( \RuntimeException::class ); |
185
|
|
|
$object->save(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
public function testSaveMShopException() |
190
|
|
|
{ |
191
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Selection\Standard::class ) |
192
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
193
|
|
|
->setMethods( array( 'fromArray' ) ) |
194
|
|
|
->getMock(); |
195
|
|
|
|
196
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
197
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
198
|
|
|
|
199
|
|
|
$this->view = \TestHelperJqadm::getView(); |
200
|
|
|
$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->find( 'U:TEST' ); |
201
|
|
|
|
202
|
|
|
$object->setView( $this->view ); |
203
|
|
|
|
204
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
205
|
|
|
$object->save(); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
public function testGetSubClient() |
210
|
|
|
{ |
211
|
|
|
$this->expectException( \Aimeos\Admin\JQAdm\Exception::class ); |
212
|
|
|
$this->object->getSubClient( 'unknown' ); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|