@@ -12,6 +12,26 @@ class NavigationTest extends \PHPUnit_Framework_TestCase
12
12
*/
13
13
protected $ block ;
14
14
15
+ /**
16
+ * @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
17
+ */
18
+ protected $ registry ;
19
+
20
+ /**
21
+ * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
22
+ */
23
+ protected $ storeManager ;
24
+
25
+ /**
26
+ * @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
27
+ */
28
+ protected $ design ;
29
+
30
+ /**
31
+ * @var \Magento\Framework\App\Http\Context|\PHPUnit_Framework_MockObject_MockObject
32
+ */
33
+ protected $ httpContext ;
34
+
15
35
protected function setUp ()
16
36
{
17
37
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
@@ -22,22 +42,85 @@ protected function setUp()
22
42
'' ,
23
43
false
24
44
);
45
+ $ this ->registry = $ this ->getMock ('Magento\Framework\Registry ' );
46
+ $ this ->storeManager = $ this ->getMock ('Magento\Store\Model\StoreManagerInterface ' );
47
+ $ this ->design = $ this ->getMock ('Magento\Framework\View\DesignInterface ' );
48
+ $ this ->httpContext = $ this ->getMock ('Magento\Framework\App\Http\Context ' , [], [], '' , false );
25
49
$ this ->block = $ objectManager ->getObject (
26
50
'Magento\Catalog\Block\Navigation ' ,
27
- ['categoryFactory ' => $ categoryFactory ]
51
+ [
52
+ 'categoryFactory ' => $ categoryFactory ,
53
+ 'registry ' => $ this ->registry ,
54
+ 'storeManager ' => $ this ->storeManager ,
55
+ 'design ' => $ this ->design ,
56
+ 'httpContext ' => $ this ->httpContext
57
+ ]
28
58
);
29
59
}
30
60
31
- protected function tearDown ()
32
- {
33
- $ this ->block = null ;
34
- }
35
-
36
61
public function testGetIdentities ()
37
62
{
38
63
$ this ->assertEquals (
39
64
[\Magento \Catalog \Model \Category::CACHE_TAG , \Magento \Store \Model \Group::CACHE_TAG ],
40
65
$ this ->block ->getIdentities ()
41
66
);
42
67
}
68
+
69
+ public function testGetCurrentCategoryKey ()
70
+ {
71
+ $ categoryKey = 101 ;
72
+ $ category = $ this ->getMock ('Magento\Catalog\Model\Category ' , [], [], '' , false );
73
+ $ category ->expects ($ this ->any ())->method ('getPath ' )->willReturn ($ categoryKey );
74
+
75
+ $ this ->registry ->expects ($ this ->any ())->method ('registry ' )->with ('current_category ' )->willReturn ($ category );
76
+
77
+ $ this ->assertEquals ($ categoryKey , $ this ->block ->getCurrentCategoryKey ());
78
+ }
79
+
80
+ public function testGetCurrentCategoryKeyFromRootCategory ()
81
+ {
82
+ $ categoryKey = 102 ;
83
+ $ store = $ this ->getMock ('Magento\Store\Model\Store ' , [], [], '' , false );
84
+ $ store ->expects ($ this ->any ())->method ('getRootCategoryId ' )->willReturn ($ categoryKey );
85
+
86
+ $ this ->storeManager ->expects ($ this ->any ())->method ('getStore ' )->willReturn ($ store );
87
+
88
+ $ this ->assertEquals ($ categoryKey , $ this ->block ->getCurrentCategoryKey ());
89
+ }
90
+
91
+ public function testGetCacheKeyInfo ()
92
+ {
93
+ $ store = $ this ->getMock ('Magento\Store\Model\Store ' , [], [], '' , false );
94
+ $ store ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn (55 );
95
+ $ store ->expects ($ this ->atLeastOnce ())->method ('getRootCategoryId ' )->willReturn (60 );
96
+
97
+ $ this ->storeManager ->expects ($ this ->atLeastOnce ())->method ('getStore ' )->willReturn ($ store );
98
+
99
+ $ theme = $ this ->getMock ('\Magento\Framework\View\Design\ThemeInterface ' );
100
+ $ theme ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn (65 );
101
+
102
+ $ this ->design ->expects ($ this ->atLeastOnce ())->method ('getDesignTheme ' )->willReturn ($ theme );
103
+
104
+ $ this ->httpContext ->expects ($ this ->atLeastOnce ())
105
+ ->method ('getValue ' )
106
+ ->with (\Magento \Customer \Model \Context::CONTEXT_GROUP )
107
+ ->willReturn (70 );
108
+
109
+ $ this ->block ->setTemplate ('block_template ' );
110
+ $ this ->block ->setNameInLayout ('block_name ' );
111
+
112
+ $ expectedResult = [
113
+ 'CATALOG_NAVIGATION ' ,
114
+ 55 ,
115
+ 65 ,
116
+ 70 ,
117
+ 'template ' => 'block_template ' ,
118
+ 'name ' => 'block_name ' ,
119
+ 60 ,
120
+ 'category_path ' => 60 ,
121
+ 'short_cache_id ' => 'c3de6d1160d1e7730b04d6cad409a2b4 '
122
+ ];
123
+
124
+ $ this ->assertEquals ($ expectedResult , $ this ->block ->getCacheKeyInfo ());
125
+ }
43
126
}
0 commit comments