12
12
*/
13
13
class RelatedTest extends \PHPUnit_Framework_TestCase
14
14
{
15
- public function testAll ()
15
+ /**
16
+ * @var \Magento\Catalog\Block\Product\ProductList\Related
17
+ */
18
+ protected $ block ;
19
+
20
+ /**
21
+ * @var \Magento\Catalog\Api\Data\ProductInterface
22
+ */
23
+ protected $ product ;
24
+
25
+ /**
26
+ * @var \Magento\Catalog\Api\Data\ProductInterface
27
+ */
28
+ protected $ relatedProduct ;
29
+
30
+ protected function setUp ()
16
31
{
17
32
/** @var $objectManager \Magento\TestFramework\ObjectManager */
18
33
$ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
@@ -21,35 +36,50 @@ public function testAll()
21
36
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
22
37
$ productRepository = $ objectManager ->create (\Magento \Catalog \Api \ProductRepositoryInterface::class);
23
38
24
- $ product = $ productRepository ->get ('simple ' );
25
- $ productWithCross = $ productRepository ->get ('simple_with_cross ' );
26
- $ objectManager ->get (\Magento \Framework \Registry::class)->register ('product ' , $ productWithCross );
39
+ $ this -> relatedProduct = $ productRepository ->get ('simple ' );
40
+ $ this -> product = $ productRepository ->get ('simple_with_cross ' );
41
+ $ objectManager ->get (\Magento \Framework \Registry::class)->register ('product ' , $ this -> product );
27
42
28
- /** @var $block \Magento\Catalog\Block\Product\ProductList\Related */
29
- $ block = $ objectManager ->get (\Magento \Framework \View \LayoutInterface::class)
43
+ $ this ->block = $ objectManager ->get (\Magento \Framework \View \LayoutInterface::class)
30
44
->createBlock (\Magento \Catalog \Block \Product \ProductList \Related::class);
31
45
32
- $ block ->setLayout ($ objectManager ->get (\Magento \Framework \View \LayoutInterface::class));
33
- $ block ->setTemplate ('Magento_Catalog::product/list/items.phtml ' );
34
- $ block ->setType ('related ' );
35
- $ block ->addChild ('addto ' , \Magento \Catalog \Block \Product \ProductList \Item \Container::class);
36
- $ block ->getChildBlock (
46
+ $ this -> block ->setLayout ($ objectManager ->get (\Magento \Framework \View \LayoutInterface::class));
47
+ $ this -> block ->setTemplate ('Magento_Catalog::product/list/items.phtml ' );
48
+ $ this -> block ->setType ('related ' );
49
+ $ this -> block ->addChild ('addto ' , \Magento \Catalog \Block \Product \ProductList \Item \Container::class);
50
+ $ this -> block ->getChildBlock (
37
51
'addto '
38
52
)->addChild (
39
53
'compare ' ,
40
54
\Magento \Catalog \Block \Product \ProductList \Item \AddTo \Compare::class,
41
55
['template ' => 'Magento_Catalog::product/list/addto/compare.phtml ' ]
42
56
);
57
+ }
43
58
44
- $ html = $ block ->toHtml ();
59
+ /**
60
+ * @magentoAppIsolation enabled
61
+ */
62
+ public function testAll ()
63
+ {
64
+ $ html = $ this ->block ->toHtml ();
45
65
$ this ->assertNotEmpty ($ html );
46
66
$ this ->assertContains ('Simple Related Product ' , $ html );
47
67
/* name */
48
- $ this ->assertContains ('"product":" ' . $ product -> getId () .'" ' , $ html );
68
+ $ this ->assertContains ('"product":" ' . $ this -> relatedProduct -> getId () . '" ' , $ html );
49
69
/* part of url */
50
70
$ this ->assertInstanceOf (
51
71
\Magento \Catalog \Model \ResourceModel \Product \Link \Product \Collection::class,
52
- $ block ->getItems ()
72
+ $ this -> block ->getItems ()
53
73
);
54
74
}
75
+
76
+ /**
77
+ * @magentoAppIsolation enabled
78
+ */
79
+ public function testGetIdentities ()
80
+ {
81
+ $ expectedTags = ['cat_p_ ' . $ this ->relatedProduct ->getId (), 'cat_p ' ];
82
+ $ tags = $ this ->block ->getIdentities ();
83
+ $ this ->assertEquals ($ expectedTags , $ tags );
84
+ }
55
85
}
0 commit comments