2222use Magento \TestFramework \TestCase \AbstractBackendController ;
2323use Magento \Catalog \Model \Product \Attribute \LayoutUpdateManager ;
2424use Magento \Catalog \Model \Product \Type ;
25+ use Magento \Catalog \Api \ProductRepositoryInterface ;
26+ use Magento \Catalog \Model \Category ;
2527
2628/**
2729 * Test class for Product adminhtml actions
@@ -46,6 +48,11 @@ class ProductTest extends AbstractBackendController
4648 */
4749 private $ resourceModel ;
4850
51+ /**
52+ * @var ProductRepositoryInterface
53+ */
54+ private $ productRepository ;
55+
4956 /**
5057 * @inheritDoc
5158 */
@@ -62,6 +69,7 @@ protected function setUp(): void
6269 $ this ->aclBuilder = Bootstrap::getObjectManager ()->get (Builder::class);
6370 $ this ->repositoryFactory = Bootstrap::getObjectManager ()->get (ProductRepositoryFactory::class);
6471 $ this ->resourceModel = Bootstrap::getObjectManager ()->get (ProductResource::class);
72+ $ this ->productRepository = $ this ->_objectManager ->get (ProductRepositoryInterface::class);
6573 }
6674
6775 /**
@@ -677,4 +685,24 @@ public function testSaveActionWithInvalidUrlKey(array $postData)
677685 );
678686 $ this ->assertRedirect ($ this ->stringContains ('/backend/catalog/product/new ' ));
679687 }
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+ }
680708}
0 commit comments