17
17
use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
18
18
use Magento \Eav \Model \Config ;
19
19
use Magento \Framework \App \Request \Http as HttpRequest ;
20
+ use Magento \Framework \Exception \NoSuchEntityException ;
20
21
use Magento \Framework \Message \MessageInterface ;
21
22
use Magento \Framework \Registry ;
22
- use Magento \Framework \Serialize \Serializer \ Json ;
23
+ use Magento \Framework \Serialize \SerializerInterface ;
23
24
use Magento \TestFramework \TestCase \AbstractBackendController ;
24
25
25
26
/**
26
27
* Tests for configurable product admin save.
27
28
*
28
29
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
29
30
* @magentoAppArea adminhtml
30
- * @magentoDbIsolation disabled
31
+ * @magentoDbIsolation enabled
31
32
*/
32
33
class ProductTest extends AbstractBackendController
33
34
{
@@ -39,15 +40,15 @@ class ProductTest extends AbstractBackendController
39
40
/**
40
41
* @var ProductAttributeRepositoryInterface
41
42
*/
42
- private $ attributeRepository ;
43
+ private $ productAttributeRepository ;
43
44
44
45
/**
45
46
* @var Registry
46
47
*/
47
48
private $ registry ;
48
49
49
50
/**
50
- * @var Json
51
+ * @var SerializerInterface
51
52
*/
52
53
private $ jsonSerializer ;
53
54
@@ -63,9 +64,9 @@ protected function setUp()
63
64
{
64
65
parent ::setUp ();
65
66
$ this ->productRepository = $ this ->_objectManager ->create (ProductRepositoryInterface::class);
66
- $ this ->attributeRepository = $ this ->_objectManager ->create (ProductAttributeRepositoryInterface::class);
67
+ $ this ->productAttributeRepository = $ this ->_objectManager ->create (ProductAttributeRepositoryInterface::class);
67
68
$ this ->registry = $ this ->_objectManager ->get (Registry::class);
68
- $ this ->jsonSerializer = $ this ->_objectManager ->get (Json ::class);
69
+ $ this ->jsonSerializer = $ this ->_objectManager ->get (SerializerInterface ::class);
69
70
$ this ->eavConfig = $ this ->_objectManager ->get (Config::class);
70
71
}
71
72
@@ -86,7 +87,7 @@ public function testSaveActionAssociatedProductIds(): void
86
87
]
87
88
);
88
89
$ this ->dispatch ('backend/catalog/product/save ' );
89
- $ this ->assertSessionMessages ($ this ->equalTo (['You saved the product. ' ]), MessageInterface::TYPE_SUCCESS );
90
+ $ this ->assertSessionMessages ($ this ->equalTo ([__ ( 'You saved the product. ' ) ]), MessageInterface::TYPE_SUCCESS );
90
91
$ this ->assertRegistryConfigurableLinks ($ associatedProductIds );
91
92
$ this ->assertConfigurableLinks ('configurable ' , $ associatedProductIds );
92
93
}
@@ -101,10 +102,11 @@ public function testSaveNewProduct(array $childProducts): void
101
102
{
102
103
$ this ->serRequestParams ($ childProducts );
103
104
$ this ->dispatch ('backend/catalog/product/save ' );
104
- $ this ->assertSessionMessages ($ this ->equalTo (['You saved the product. ' ]), MessageInterface::TYPE_SUCCESS );
105
+ $ this ->assertSessionMessages ($ this ->equalTo ([__ ( 'You saved the product. ' ) ]), MessageInterface::TYPE_SUCCESS );
105
106
$ this ->assertChildProducts ($ childProducts );
106
107
$ this ->assertConfigurableOptions ('configurable ' , $ childProducts );
107
108
$ this ->assertConfigurableLinks ('configurable ' , $ this ->getProductIds (array_keys ($ childProducts )));
109
+ $ this ->deleteProducts (array_merge (array_keys ($ childProducts ), ['configurable ' ]));
108
110
}
109
111
110
112
/**
@@ -174,6 +176,7 @@ public function testSaveExistProduct(array $childProducts, array $associatedProd
174
176
'configurable ' ,
175
177
$ this ->getProductIds (array_merge ($ associatedProducts , array_keys ($ childProducts )))
176
178
);
179
+ $ this ->deleteProducts (array_merge ($ associatedProducts , array_keys ($ childProducts )));
177
180
}
178
181
179
182
/**
@@ -483,11 +486,11 @@ private function getDefaultAttributeSetId(): int
483
486
*/
484
487
private function getAttribute (string $ attributeCode ): ProductAttributeInterface
485
488
{
486
- return $ this ->attributeRepository ->get ($ attributeCode );
489
+ return $ this ->productAttributeRepository ->get ($ attributeCode );
487
490
}
488
491
489
492
/**
490
- * Returns product ids by sku list.
493
+ * Returns products by sku list.
491
494
*
492
495
* @param array $skuList
493
496
* @return ProductInterface[]
@@ -517,4 +520,25 @@ private function getProductIds(array $skuList): array
517
520
518
521
return $ associatedProductIds ;
519
522
}
523
+
524
+ /**
525
+ * @param array $skuList
526
+ * @return void
527
+ */
528
+ private function deleteProducts (array $ skuList ): void
529
+ {
530
+ $ this ->registry ->unregister ('isSecureArea ' );
531
+ $ this ->registry ->register ('isSecureArea ' , true );
532
+
533
+ foreach ($ skuList as $ sku ) {
534
+ try {
535
+ $ product = $ this ->productRepository ->get ($ sku , false , null , true );
536
+ $ this ->productRepository ->delete ($ product );
537
+ } catch (NoSuchEntityException $ e ) {
538
+ //Product already removed
539
+ }
540
+ }
541
+ $ this ->registry ->unregister ('isSecureArea ' );
542
+ $ this ->registry ->register ('isSecureArea ' , false );
543
+ }
520
544
}
0 commit comments