88namespace Magento \Catalog \Model \Product \Attribute \Backend ;
99
1010use 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 ;
1124
1225/**
1326 * Test class for \Magento\Catalog\Model\Product\Attribute\Backend\Tierprice.
1427 *
1528 * @magentoDataFixture Magento/Catalog/_files/product_simple.php
1629 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1730 */
18- class TierpriceTest extends \ PHPUnit \ Framework \ TestCase
31+ class TierpriceTest extends TestCase
1932{
2033 /**
21- * @var \Magento\Framework\EntityManager\ MetadataPool
34+ * @var MetadataPool
2235 */
2336 protected $ metadataPool ;
2437
2538 /**
26- * @var \Magento\Catalog\Model\ ProductRepository
39+ * @var ProductRepository
2740 */
2841 protected $ productRepository ;
2942
3043 /**
31- * @var \Magento\Catalog\Api\Data\ ProductTierPriceInterfaceFactory
44+ * @var ProductTierPriceInterfaceFactory
3245 */
3346 private $ tierPriceFactory ;
3447
3548 /**
36- * @var \Magento\Catalog\Model\Product\Attribute\Backend\ Tierprice
49+ * @var Tierprice
3750 */
3851 protected $ _model ;
3952
4053 protected function setUp (): void
4154 {
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
4457 );
45- $ this ->productRepository = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
46- \ Magento \ Catalog \ Model \ ProductRepository::class
58+ $ this ->productRepository = Bootstrap::getObjectManager ()->create (
59+ ProductRepository::class
4760 );
48- $ this ->metadataPool = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
49- \ Magento \ Framework \ EntityManager \ MetadataPool::class
61+ $ this ->metadataPool = Bootstrap::getObjectManager ()->create (
62+ MetadataPool::class
5063 );
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);
5366
5467 $ this ->_model ->setAttribute (
55- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
68+ Bootstrap::getObjectManager ()->get (
5669 \Magento \Eav \Model \Config::class
5770 )->getAttribute (
5871 'catalog_product ' ,
@@ -63,7 +76,7 @@ protected function setUp(): void
6376
6477 public function testValidate ()
6578 {
66- $ product = new \ Magento \ Framework \ DataObject ();
79+ $ product = new DataObject ();
6780 $ product ->setTierPrice (
6881 [
6982 ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 ],
@@ -81,9 +94,9 @@ public function testValidate()
8194 */
8295 public function testValidateDuplicate (array $ tierPricesData )
8396 {
84- $ this ->expectException (\ Magento \ Framework \ Exception \ LocalizedException::class);
97+ $ this ->expectException (LocalizedException::class);
8598
86- $ product = new \ Magento \ Framework \ DataObject ();
99+ $ product = new DataObject ();
87100 $ product ->setTierPrice ($ tierPricesData );
88101
89102 $ this ->_model ->validate ($ product );
@@ -116,9 +129,9 @@ public function validateDuplicateDataProvider(): array
116129 */
117130 public function testValidateDuplicateWebsite ()
118131 {
119- $ this ->expectException (\ Magento \ Framework \ Exception \ LocalizedException::class);
132+ $ this ->expectException (LocalizedException::class);
120133
121- $ product = new \ Magento \ Framework \ DataObject ();
134+ $ product = new DataObject ();
122135 $ product ->setTierPrice (
123136 [
124137 ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2.2 , 'price ' => 8 ],
@@ -134,9 +147,9 @@ public function testValidateDuplicateWebsite()
134147 */
135148 public function testValidatePercentage ()
136149 {
137- $ this ->expectException (\ Magento \ Framework \ Exception \ LocalizedException::class);
150+ $ this ->expectException (LocalizedException::class);
138151
139- $ product = new \ Magento \ Framework \ DataObject ();
152+ $ product = new DataObject ();
140153 $ product ->setTierPrice (
141154 [
142155 ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'percentage_value ' => 101 ],
@@ -149,15 +162,15 @@ public function testValidatePercentage()
149162 public function testPreparePriceData ()
150163 {
151164 $ 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 ],
158171 ];
159172
160- $ newData = $ this ->_model ->preparePriceData ($ data , \ Magento \ Catalog \ Model \ Product \ Type::TYPE_SIMPLE , 1 );
173+ $ newData = $ this ->_model ->preparePriceData ($ data , Type::TYPE_SIMPLE , 1 );
161174 $ this ->assertCount (4 , $ newData );
162175 $ this ->assertArrayHasKey ('1-2 ' , $ newData );
163176 $ this ->assertArrayHasKey ('1-5 ' , $ newData );
@@ -167,9 +180,9 @@ public function testPreparePriceData()
167180
168181 public function testAfterLoad ()
169182 {
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
173186 );
174187 $ fixtureProduct = $ this ->productRepository ->get ('simple ' );
175188 $ product ->setId ($ fixtureProduct ->getId ());
@@ -185,14 +198,14 @@ public function testAfterLoad()
185198 * @dataProvider saveExistingProductDataProvider
186199 * @param array $tierPricesData
187200 * @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
192205 */
193206 public function testSaveExistingProduct (array $ tierPricesData , int $ tierPriceCount ): void
194207 {
195- /** @var $product \Magento\Catalog\Model\ Product */
208+ /** @var $product Product */
196209 $ product = $ this ->productRepository ->get ('simple ' , true );
197210 $ tierPrices = [];
198211 foreach ($ tierPricesData as $ tierPrice ) {
@@ -222,7 +235,7 @@ public function saveExistingProductDataProvider(): array
222235 'website_id ' => 0 ,
223236 'customer_group_id ' => 0 ,
224237 'qty ' => 10 ,
225- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 50 ])
238+ 'extension_attributes ' => new DataObject (['percentage_value ' => 50 ])
226239 ],
227240 ],
228241 5 ,
@@ -237,7 +250,7 @@ public function saveExistingProductDataProvider(): array
237250 'website_id ' => 0 ,
238251 'customer_group_id ' => 0 ,
239252 'qty ' => 10 ,
240- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 10 ])
253+ 'extension_attributes ' => new DataObject (['percentage_value ' => 10 ])
241254 ],
242255 ],
243256 5 ,
@@ -251,7 +264,7 @@ public function saveExistingProductDataProvider(): array
251264 'website_id ' => 0 ,
252265 'customer_group_id ' => 0 ,
253266 'qty ' => 10 ,
254- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 50 ])
267+ 'extension_attributes ' => new DataObject (['percentage_value ' => 50 ])
255268 ],
256269 ],
257270 4 ,
@@ -266,13 +279,13 @@ public function saveExistingProductDataProvider(): array
266279 'website_id ' => 0 ,
267280 'customer_group_id ' => 32000 ,
268281 'qty ' => 20 ,
269- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 90 ])
282+ 'extension_attributes ' => new DataObject (['percentage_value ' => 90 ])
270283 ],
271284 [
272285 'website_id ' => 0 ,
273286 'customer_group_id ' => 0 ,
274287 'qty ' => 10 ,
275- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 50 ])
288+ 'extension_attributes ' => new DataObject (['percentage_value ' => 50 ])
276289 ],
277290 ],
278291 6 ,
@@ -285,18 +298,18 @@ public function saveExistingProductDataProvider(): array
285298 * @dataProvider saveNewProductDataProvider
286299 * @param array $tierPricesData
287300 * @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
292305 */
293306 public function testSaveNewProduct (array $ tierPricesData , int $ tierPriceCount ): void
294307 {
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);
298311 $ product ->isObjectNew (true );
299- $ product ->setTypeId (\ Magento \ Catalog \ Model \ Product \ Type::TYPE_SIMPLE )
312+ $ product ->setTypeId (Type::TYPE_SIMPLE )
300313 ->setAttributeSetId (4 )
301314 ->setName ('Simple Product New ' )
302315 ->setSku ('simple product new ' )
@@ -330,7 +343,7 @@ public function saveNewProductDataProvider(): array
330343 'website_id ' => 0 ,
331344 'customer_group_id ' => 0 ,
332345 'qty ' => 10 ,
333- 'extension_attributes ' => new \ Magento \ Framework \ DataObject (['percentage_value ' => 50 ])
346+ 'extension_attributes ' => new DataObject (['percentage_value ' => 50 ])
334347 ],
335348 ],
336349 6 ,
0 commit comments