1313use Magento \Catalog \Model \Product ;
1414use Magento \Catalog \Model \Product \Visibility ;
1515use Magento \Eav \Model \Entity \Type ;
16+ use Magento \Framework \App \ActionInterface ;
1617use Magento \Framework \App \Cache \Manager ;
18+ use Magento \Framework \App \Config \ScopeConfigInterface ;
1719use Magento \Framework \App \Http ;
20+ use Magento \Framework \App \Request \Http as HttpRequest ;
1821use Magento \Framework \Registry ;
22+ use Magento \Framework \Url \EncoderInterface ;
23+ use Magento \Store \Model \Store ;
1924use Magento \Store \Model \StoreManagerInterface ;
2025use Magento \TestFramework \Eav \Model \GetAttributeSetByName ;
2126use Magento \TestFramework \Request ;
2227use PHPUnit \Framework \MockObject \MockObject ;
2328use Psr \Log \LoggerInterface ;
2429use Magento \Catalog \Api \Data \ProductAttributeInterface ;
2530use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
26- use Magento \Framework \Logger \Monolog as MagentoMonologLogger ;
2731use Magento \TestFramework \Response ;
2832use Magento \TestFramework \TestCase \AbstractController ;
2933
@@ -66,6 +70,12 @@ class ViewTest extends AbstractController
6670 /** @var GetAttributeSetByName */
6771 private $ getAttributeSetByName ;
6872
73+ /** @var EncoderInterface */
74+ private $ urlEncoder ;
75+
76+ /** @var ScopeConfigInterface */
77+ private $ config ;
78+
6979 /**
7080 * @inheritdoc
7181 */
@@ -81,6 +91,8 @@ protected function setUp(): void
8191 $ this ->registry = $ this ->_objectManager ->get (Registry::class);
8292 $ this ->storeManager = $ this ->_objectManager ->get (StoreManagerInterface::class);
8393 $ this ->getAttributeSetByName = $ this ->_objectManager ->get (GetAttributeSetByName::class);
94+ $ this ->urlEncoder = $ this ->_objectManager ->get (EncoderInterface::class);
95+ $ this ->config = $ this ->_objectManager ->get (ScopeConfigInterface::class);
8496 }
8597
8698 /**
@@ -294,6 +306,37 @@ public function test404NotFoundPageCacheTags(): void
294306 );
295307 }
296308
309+ /**
310+ * @return void
311+ */
312+ public function testViewUnexistedProduct (): void
313+ {
314+ $ url = '/catalog/product/view/id/999/ ' ;
315+ $ this ->getRequest ()->setParams ([
316+ ActionInterface::PARAM_NAME_URL_ENCODED => $ this ->urlEncoder ->encode ($ url ),
317+ ])->setMethod (HttpRequest::METHOD_POST );
318+ $ this ->dispatch ($ url );
319+ $ this ->assert404NotFound ();
320+ }
321+
322+ /**
323+ * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
324+ *
325+ * @return void
326+ */
327+ public function testViewWithRedirect (): void
328+ {
329+ $ product = $ this ->productRepository ->get ('simple2 ' );
330+ $ url = $ this ->config ->getValue (Store::XML_PATH_UNSECURE_BASE_LINK_URL );
331+ $ this ->getRequest ()
332+ ->setParams ([
333+ ActionInterface::PARAM_NAME_URL_ENCODED => $ this ->urlEncoder ->encode ($ url ),
334+ ])
335+ ->setMethod (HttpRequest::METHOD_POST );
336+ $ this ->dispatch (sprintf ('catalog/product/view/id/%s/ ' , $ product ->getId ()));
337+ $ this ->assertRedirect ($ this ->stringContains ($ url ));
338+ }
339+
297340 /**
298341 * @param string|ProductInterface $product
299342 * @param array $data
0 commit comments