13
13
use Magento \Catalog \Model \Product ;
14
14
use Magento \Catalog \Model \Product \Visibility ;
15
15
use Magento \Eav \Model \Entity \Type ;
16
+ use Magento \Framework \App \ActionInterface ;
16
17
use Magento \Framework \App \Cache \Manager ;
18
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
17
19
use Magento \Framework \App \Http ;
20
+ use Magento \Framework \App \Request \Http as HttpRequest ;
18
21
use Magento \Framework \Registry ;
22
+ use Magento \Framework \Url \EncoderInterface ;
23
+ use Magento \Store \Model \Store ;
19
24
use Magento \Store \Model \StoreManagerInterface ;
20
25
use Magento \TestFramework \Eav \Model \GetAttributeSetByName ;
21
26
use Magento \TestFramework \Request ;
22
27
use PHPUnit \Framework \MockObject \MockObject ;
23
28
use Psr \Log \LoggerInterface ;
24
29
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
25
30
use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
26
- use Magento \Framework \Logger \Monolog as MagentoMonologLogger ;
27
31
use Magento \TestFramework \Response ;
28
32
use Magento \TestFramework \TestCase \AbstractController ;
29
33
@@ -66,6 +70,12 @@ class ViewTest extends AbstractController
66
70
/** @var GetAttributeSetByName */
67
71
private $ getAttributeSetByName ;
68
72
73
+ /** @var EncoderInterface */
74
+ private $ urlEncoder ;
75
+
76
+ /** @var ScopeConfigInterface */
77
+ private $ config ;
78
+
69
79
/**
70
80
* @inheritdoc
71
81
*/
@@ -81,6 +91,8 @@ protected function setUp(): void
81
91
$ this ->registry = $ this ->_objectManager ->get (Registry::class);
82
92
$ this ->storeManager = $ this ->_objectManager ->get (StoreManagerInterface::class);
83
93
$ this ->getAttributeSetByName = $ this ->_objectManager ->get (GetAttributeSetByName::class);
94
+ $ this ->urlEncoder = $ this ->_objectManager ->get (EncoderInterface::class);
95
+ $ this ->config = $ this ->_objectManager ->get (ScopeConfigInterface::class);
84
96
}
85
97
86
98
/**
@@ -294,6 +306,37 @@ public function test404NotFoundPageCacheTags(): void
294
306
);
295
307
}
296
308
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
+
297
340
/**
298
341
* @param string|ProductInterface $product
299
342
* @param array $data
0 commit comments