22
22
use Magento \TestFramework \TestCase \AbstractBackendController ;
23
23
use Magento \Catalog \Model \Product \Attribute \LayoutUpdateManager ;
24
24
use Magento \Catalog \Model \Product \Type ;
25
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
26
+ use Magento \Catalog \Model \Category ;
25
27
26
28
/**
27
29
* Test class for Product adminhtml actions
@@ -46,6 +48,11 @@ class ProductTest extends AbstractBackendController
46
48
*/
47
49
private $ resourceModel ;
48
50
51
+ /**
52
+ * @var ProductRepositoryInterface
53
+ */
54
+ private $ productRepository ;
55
+
49
56
/**
50
57
* @inheritDoc
51
58
*/
@@ -62,6 +69,7 @@ protected function setUp(): void
62
69
$ this ->aclBuilder = Bootstrap::getObjectManager ()->get (Builder::class);
63
70
$ this ->repositoryFactory = Bootstrap::getObjectManager ()->get (ProductRepositoryFactory::class);
64
71
$ this ->resourceModel = Bootstrap::getObjectManager ()->get (ProductResource::class);
72
+ $ this ->productRepository = $ this ->_objectManager ->get (ProductRepositoryInterface::class);
65
73
}
66
74
67
75
/**
@@ -677,4 +685,24 @@ public function testSaveActionWithInvalidUrlKey(array $postData)
677
685
);
678
686
$ this ->assertRedirect ($ this ->stringContains ('/backend/catalog/product/new ' ));
679
687
}
688
+
689
+ /**
690
+ * @magentoDataFixture Magento/Catalog/_files/category_product.php
691
+ * @magentoDbIsolation disabled
692
+ * @magentoAppArea adminhtml
693
+ */
694
+ public function testSaveProductWithDeletedCategory (): void
695
+ {
696
+ $ category = $ this ->_objectManager ->get (Category::class);
697
+ $ category ->load (333 );
698
+ $ category ->delete ();
699
+ $ product = $ this ->productRepository ->get ('simple333 ' );
700
+ $ this ->productRepository ->save ($ product );
701
+ $ this ->getRequest ()->setMethod (HttpRequest::METHOD_POST );
702
+ $ this ->dispatch ('backend/catalog/product/save/id/ ' . $ product ->getEntityId ());
703
+ $ this ->assertSessionMessages (
704
+ $ this ->equalTo ([(string )__ ('You saved the product. ' )]),
705
+ MessageInterface::TYPE_SUCCESS
706
+ );
707
+ }
680
708
}
0 commit comments