99use Magento \Framework \Data \Form \FormKey ;
1010use Magento \Framework \Message \Manager ;
1111use Magento \TestFramework \Helper \Bootstrap ;
12+ use Magento \Catalog \Api \ProductRepositoryInterface ;
13+ use Magento \Framework \Message \MessageInterface ;
1214
1315/**
1416 * @magentoAppArea adminhtml
@@ -21,7 +23,7 @@ public function testSaveActionWithDangerRequest()
2123 $ this ->dispatch ('backend/catalog/product/save ' );
2224 $ this ->assertSessionMessages (
2325 $ this ->equalTo (['Unable to save product ' ]),
24- \ Magento \ Framework \ Message \ MessageInterface::TYPE_ERROR
26+ MessageInterface::TYPE_ERROR
2527 );
2628 $ this ->assertRedirect ($ this ->stringContains ('/backend/catalog/product/new ' ));
2729 }
@@ -38,7 +40,7 @@ public function testSaveActionAndNew()
3840 $ this ->assertRedirect ($ this ->stringStartsWith ('http://localhost/index.php/backend/catalog/product/new/ ' ));
3941 $ this ->assertSessionMessages (
4042 $ this ->contains ('You saved the product. ' ),
41- \ Magento \ Framework \ Message \ MessageInterface::TYPE_SUCCESS
43+ MessageInterface::TYPE_SUCCESS
4244 );
4345 }
4446
@@ -61,11 +63,11 @@ public function testSaveActionAndDuplicate()
6163 );
6264 $ this ->assertSessionMessages (
6365 $ this ->contains ('You saved the product. ' ),
64- \ Magento \ Framework \ Message \ MessageInterface::TYPE_SUCCESS
66+ MessageInterface::TYPE_SUCCESS
6567 );
6668 $ this ->assertSessionMessages (
6769 $ this ->contains ('You duplicated the product. ' ),
68- \ Magento \ Framework \ Message \ MessageInterface::TYPE_SUCCESS
70+ MessageInterface::TYPE_SUCCESS
6971 );
7072 }
7173
@@ -236,4 +238,104 @@ public function saveActionWithAlreadyExistingUrlKeyDataProvider()
236238 ]
237239 ];
238240 }
241+
242+ /**
243+ * Test product save with selected tier price
244+ *
245+ * @dataProvider saveActionTierPriceDataProvider
246+ * @param array $postData
247+ * @param array $tierPrice
248+ * @magentoDataFixture Magento/Catalog/_files/product_has_tier_price_show_as_low_as.php
249+ * @magentoConfigFixture current_store catalog/price/scope 1
250+ */
251+ public function testSaveActionTierPrice (array $ postData , array $ tierPrice )
252+ {
253+ $ postData ['product ' ] = $ this ->getProductData ($ tierPrice );
254+ $ this ->getRequest ()->setPostValue ($ postData );
255+ $ this ->dispatch ('backend/catalog/product/save/id/ ' . $ postData ['id ' ]);
256+ $ this ->assertSessionMessages (
257+ $ this ->contains ('You saved the product. ' ),
258+ MessageInterface::TYPE_SUCCESS
259+ );
260+ }
261+
262+ /**
263+ * Provide test data for testSaveActionWithAlreadyExistingUrlKey().
264+ *
265+ * @return array
266+ */
267+ public function saveActionTierPriceDataProvider ()
268+ {
269+ return [
270+ [
271+ 'post_data ' => [
272+ 'id ' => '1 ' ,
273+ 'type ' => 'simple ' ,
274+ 'store ' => '0 ' ,
275+ 'set ' => '4 ' ,
276+ 'back ' => 'edit ' ,
277+ 'product ' => [],
278+ 'is_downloadable ' => '0 ' ,
279+ 'affect_configurable_product_attributes ' => '1 ' ,
280+ 'new_variation_attribute_set_id ' => '4 ' ,
281+ 'use_default ' => [
282+ 'gift_message_available ' => '0 ' ,
283+ 'gift_wrapping_available ' => '0 '
284+ ],
285+ 'configurable_matrix_serialized ' => '[] ' ,
286+ 'associated_product_ids_serialized ' => '[] '
287+ ],
288+ 'tier_price_for_request ' => [
289+ [
290+ 'price_id ' => '1 ' ,
291+ 'website_id ' => '0 ' ,
292+ 'cust_group ' => '32000 ' ,
293+ 'price ' => '111.00 ' ,
294+ 'price_qty ' => '100 ' ,
295+ 'website_price ' => '111.0000 ' ,
296+ 'initialize ' => 'true ' ,
297+ 'record_id ' => '1 ' ,
298+ 'value_type ' => 'fixed '
299+ ],
300+ [
301+ 'price_id ' => '2 ' ,
302+ 'website_id ' => '1 ' ,
303+ 'cust_group ' => '32000 ' ,
304+ 'price ' => '222.00 ' ,
305+ 'price_qty ' => '200 ' ,
306+ 'website_price ' => '111.0000 ' ,
307+ 'initialize ' => 'true ' ,
308+ 'record_id ' => '2 ' ,
309+ 'value_type ' => 'fixed '
310+ ],
311+ [
312+ 'price_id ' => '3 ' ,
313+ 'website_id ' => '1 ' ,
314+ 'cust_group ' => '32000 ' ,
315+ 'price ' => '333.00 ' ,
316+ 'price_qty ' => '300 ' ,
317+ 'website_price ' => '111.0000 ' ,
318+ 'initialize ' => 'true ' ,
319+ 'record_id ' => '3 ' ,
320+ 'value_type ' => 'fixed '
321+ ]
322+ ]
323+ ]
324+ ];
325+ }
326+
327+ /**
328+ * Return product data for test without entity_id for further save
329+ *
330+ * @param array $tierPrice
331+ * @return array
332+ */
333+ private function getProductData (array $ tierPrice )
334+ {
335+ $ productRepositoryInterface = $ this ->_objectManager ->get (ProductRepositoryInterface::class);
336+ $ product = $ productRepositoryInterface ->get ('tier_prices ' )->getData ();
337+ $ product ['tier_price ' ] = $ tierPrice ;
338+ unset($ product ['entity_id ' ]);
339+ return $ product ;
340+ }
239341}
0 commit comments