8
8
namespace Magento \Catalog \Model \Product \Attribute \Backend ;
9
9
10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
+ use Magento \Catalog \Api \Data \ProductTierPriceInterfaceFactory ;
12
+ use Magento \Catalog \Model \Product ;
13
+ use Magento \Catalog \Model \Product \Type ;
14
+ use Magento \Catalog \Model \ProductRepository ;
15
+ use Magento \Framework \DataObject ;
16
+ use Magento \Framework \EntityManager \MetadataPool ;
17
+ use Magento \Framework \Exception \CouldNotSaveException ;
18
+ use Magento \Framework \Exception \InputException ;
19
+ use Magento \Framework \Exception \LocalizedException ;
20
+ use Magento \Framework \Exception \NoSuchEntityException ;
21
+ use Magento \Framework \Exception \StateException ;
22
+ use Magento \TestFramework \Helper \Bootstrap ;
23
+ use PHPUnit \Framework \TestCase ;
11
24
12
25
/**
13
26
* Test class for \Magento\Catalog\Model\Product\Attribute\Backend\Tierprice.
14
27
*
15
28
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
16
29
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
30
*/
18
- class TierpriceTest extends \ PHPUnit \ Framework \ TestCase
31
+ class TierpriceTest extends TestCase
19
32
{
20
33
/**
21
- * @var \Magento\Framework\EntityManager\ MetadataPool
34
+ * @var MetadataPool
22
35
*/
23
36
protected $ metadataPool ;
24
37
25
38
/**
26
- * @var \Magento\Catalog\Model\ ProductRepository
39
+ * @var ProductRepository
27
40
*/
28
41
protected $ productRepository ;
29
42
30
43
/**
31
- * @var \Magento\Catalog\Api\Data\ ProductTierPriceInterfaceFactory
44
+ * @var ProductTierPriceInterfaceFactory
32
45
*/
33
46
private $ tierPriceFactory ;
34
47
35
48
/**
36
- * @var \Magento\Catalog\Model\Product\Attribute\Backend\ Tierprice
49
+ * @var Tierprice
37
50
*/
38
51
protected $ _model ;
39
52
40
53
protected function setUp (): void
41
54
{
42
- $ this ->_model = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
43
- \ Magento \ Catalog \ Model \ Product \ Attribute \ Backend \ Tierprice::class
55
+ $ this ->_model = Bootstrap::getObjectManager ()->create (
56
+ Tierprice::class
44
57
);
45
- $ this ->productRepository = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
46
- \ Magento \ Catalog \ Model \ ProductRepository::class
58
+ $ this ->productRepository = Bootstrap::getObjectManager ()->create (
59
+ ProductRepository::class
47
60
);
48
- $ this ->metadataPool = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
49
- \ Magento \ Framework \ EntityManager \ MetadataPool::class
61
+ $ this ->metadataPool = Bootstrap::getObjectManager ()->create (
62
+ MetadataPool::class
50
63
);
51
- $ this ->tierPriceFactory = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
52
- ->create (\ Magento \ Catalog \ Api \ Data \ ProductTierPriceInterfaceFactory::class);
64
+ $ this ->tierPriceFactory = Bootstrap::getObjectManager ()
65
+ ->create (ProductTierPriceInterfaceFactory::class);
53
66
54
67
$ this ->_model ->setAttribute (
55
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
68
+ Bootstrap::getObjectManager ()->get (
56
69
\Magento \Eav \Model \Config::class
57
70
)->getAttribute (
58
71
'catalog_product ' ,
@@ -63,7 +76,7 @@ protected function setUp(): void
63
76
64
77
public function testValidate ()
65
78
{
66
- $ product = new \ Magento \ Framework \ DataObject ();
79
+ $ product = new DataObject ();
67
80
$ product ->setTierPrice (
68
81
[
69
82
['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 ],
@@ -81,9 +94,9 @@ public function testValidate()
81
94
*/
82
95
public function testValidateDuplicate (array $ tierPricesData )
83
96
{
84
- $ this ->expectException (\ Magento \ Framework \ Exception \ LocalizedException::class);
97
+ $ this ->expectException (LocalizedException::class);
85
98
86
- $ product = new \ Magento \ Framework \ DataObject ();
99
+ $ product = new DataObject ();
87
100
$ product ->setTierPrice ($ tierPricesData );
88
101
89
102
$ this ->_model ->validate ($ product );
@@ -116,9 +129,9 @@ public function validateDuplicateDataProvider(): array
116
129
*/
117
130
public function testValidateDuplicateWebsite ()
118
131
{
119
- $ this ->expectException (\ Magento \ Framework \ Exception \ LocalizedException::class);
132
+ $ this ->expectException (LocalizedException::class);
120
133
121
- $ product = new \ Magento \ Framework \ DataObject ();
134
+ $ product = new DataObject ();
122
135
$ product ->setTierPrice (
123
136
[
124
137
['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2.2 , 'price ' => 8 ],
@@ -134,9 +147,9 @@ public function testValidateDuplicateWebsite()
134
147
*/
135
148
public function testValidatePercentage ()
136
149
{
137
- $ this ->expectException (\ Magento \ Framework \ Exception \ LocalizedException::class);
150
+ $ this ->expectException (LocalizedException::class);
138
151
139
- $ product = new \ Magento \ Framework \ DataObject ();
152
+ $ product = new DataObject ();
140
153
$ product ->setTierPrice (
141
154
[
142
155
['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'percentage_value ' => 101 ],
@@ -149,15 +162,15 @@ public function testValidatePercentage()
149
162
public function testPreparePriceData ()
150
163
{
151
164
$ data = [
152
- ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 ],
153
- ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 ],
154
- ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 ],
155
- ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => 5.3 , 'price ' => 4 ],
156
- ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => 5.4 , 'price ' => 3 ],
157
- ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => '5.40 ' , 'price ' => 2 ],
165
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 , ' percentage_value ' => 10 ],
166
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 , ' percentage_value ' => null ],
167
+ ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 , ' percentage_value ' => 40 ],
168
+ ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => 5.3 , 'price ' => 4 , ' percentage_value ' => 10 ],
169
+ ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => 5.4 , 'price ' => 3 , ' percentage_value ' => 50 ],
170
+ ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => '5.40 ' , 'price ' => 2 , ' percentage_value ' => null ],
158
171
];
159
172
160
- $ newData = $ this ->_model ->preparePriceData ($ data , \ Magento \ Catalog \ Model \ Product \ Type::TYPE_SIMPLE , 1 );
173
+ $ newData = $ this ->_model ->preparePriceData ($ data , Type::TYPE_SIMPLE , 1 );
161
174
$ this ->assertCount (4 , $ newData );
162
175
$ this ->assertArrayHasKey ('1-2 ' , $ newData );
163
176
$ this ->assertArrayHasKey ('1-5 ' , $ newData );
@@ -167,9 +180,9 @@ public function testPreparePriceData()
167
180
168
181
public function testAfterLoad ()
169
182
{
170
- /** @var $product \Magento\Catalog\Model\ Product */
171
- $ product = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
172
- \ Magento \ Catalog \ Model \ Product::class
183
+ /** @var $product Product */
184
+ $ product = Bootstrap::getObjectManager ()->create (
185
+ Product::class
173
186
);
174
187
$ fixtureProduct = $ this ->productRepository ->get ('simple ' );
175
188
$ product ->setId ($ fixtureProduct ->getId ());
@@ -185,14 +198,14 @@ public function testAfterLoad()
185
198
* @dataProvider saveExistingProductDataProvider
186
199
* @param array $tierPricesData
187
200
* @param int $tierPriceCount
188
- * @throws \Magento\Framework\Exception\ CouldNotSaveException
189
- * @throws \Magento\Framework\Exception\ InputException
190
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
191
- * @throws \Magento\Framework\Exception\ StateException
201
+ * @throws CouldNotSaveException
202
+ * @throws InputException
203
+ * @throws NoSuchEntityException
204
+ * @throws StateException
192
205
*/
193
206
public function testSaveExistingProduct (array $ tierPricesData , int $ tierPriceCount ): void
194
207
{
195
- /** @var $product \Magento\Catalog\Model\ Product */
208
+ /** @var $product Product */
196
209
$ product = $ this ->productRepository ->get ('simple ' , true );
197
210
$ tierPrices = [];
198
211
foreach ($ tierPricesData as $ tierPrice ) {
@@ -222,7 +235,7 @@ public function saveExistingProductDataProvider(): array
222
235
'website_id ' => 0 ,
223
236
'customer_group_id ' => 0 ,
224
237
'qty ' => 10 ,
225
- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 50 ])
238
+ 'extension_attributes ' => new DataObject (['percentage_value ' => 50 ])
226
239
],
227
240
],
228
241
5 ,
@@ -237,7 +250,7 @@ public function saveExistingProductDataProvider(): array
237
250
'website_id ' => 0 ,
238
251
'customer_group_id ' => 0 ,
239
252
'qty ' => 10 ,
240
- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 10 ])
253
+ 'extension_attributes ' => new DataObject (['percentage_value ' => 10 ])
241
254
],
242
255
],
243
256
5 ,
@@ -251,7 +264,7 @@ public function saveExistingProductDataProvider(): array
251
264
'website_id ' => 0 ,
252
265
'customer_group_id ' => 0 ,
253
266
'qty ' => 10 ,
254
- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 50 ])
267
+ 'extension_attributes ' => new DataObject (['percentage_value ' => 50 ])
255
268
],
256
269
],
257
270
4 ,
@@ -266,13 +279,13 @@ public function saveExistingProductDataProvider(): array
266
279
'website_id ' => 0 ,
267
280
'customer_group_id ' => 32000 ,
268
281
'qty ' => 20 ,
269
- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 90 ])
282
+ 'extension_attributes ' => new DataObject (['percentage_value ' => 90 ])
270
283
],
271
284
[
272
285
'website_id ' => 0 ,
273
286
'customer_group_id ' => 0 ,
274
287
'qty ' => 10 ,
275
- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 50 ])
288
+ 'extension_attributes ' => new DataObject (['percentage_value ' => 50 ])
276
289
],
277
290
],
278
291
6 ,
@@ -285,18 +298,18 @@ public function saveExistingProductDataProvider(): array
285
298
* @dataProvider saveNewProductDataProvider
286
299
* @param array $tierPricesData
287
300
* @param int $tierPriceCount
288
- * @throws \Magento\Framework\Exception\ CouldNotSaveException
289
- * @throws \Magento\Framework\Exception\ InputException
290
- * @throws \Magento\Framework\Exception\ LocalizedException
291
- * @throws \Magento\Framework\Exception\ StateException
301
+ * @throws CouldNotSaveException
302
+ * @throws InputException
303
+ * @throws LocalizedException
304
+ * @throws StateException
292
305
*/
293
306
public function testSaveNewProduct (array $ tierPricesData , int $ tierPriceCount ): void
294
307
{
295
- /** @var $product \Magento\Catalog\Model\ Product */
296
- $ product = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
297
- ->create (\ Magento \ Catalog \ Model \ Product::class);
308
+ /** @var $product Product */
309
+ $ product = Bootstrap::getObjectManager ()
310
+ ->create (Product::class);
298
311
$ product ->isObjectNew (true );
299
- $ product ->setTypeId (\ Magento \ Catalog \ Model \ Product \ Type::TYPE_SIMPLE )
312
+ $ product ->setTypeId (Type::TYPE_SIMPLE )
300
313
->setAttributeSetId (4 )
301
314
->setName ('Simple Product New ' )
302
315
->setSku ('simple product new ' )
@@ -330,7 +343,7 @@ public function saveNewProductDataProvider(): array
330
343
'website_id ' => 0 ,
331
344
'customer_group_id ' => 0 ,
332
345
'qty ' => 10 ,
333
- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 50 ])
346
+ 'extension_attributes ' => new DataObject (['percentage_value ' => 50 ])
334
347
],
335
348
],
336
349
6 ,
0 commit comments