8
8
9
9
namespace Magento \Framework \View \Test \Unit \Element ;
10
10
11
+ use Magento \Framework \View \Element \AbstractBlock ;
12
+ use Magento \Framework \View \Element \Context ;
13
+ use Magento \Framework \Config \View ;
14
+ use Magento \Framework \View \ConfigInterface ;
15
+
11
16
class AbstractBlockTest extends \PHPUnit_Framework_TestCase
12
17
{
18
+ /**
19
+ * @var AbstractBlock
20
+ */
21
+ protected $ block ;
22
+
23
+ /**
24
+ * @return void
25
+ */
26
+ protected function setUp ()
27
+ {
28
+ $ contextMock = $ this ->getMock (Context::class, [], [], '' , false );
29
+ $ this ->block = $ this ->getMockForAbstractClass (
30
+ AbstractBlock::class,
31
+ ['context ' => $ contextMock ]
32
+ );
33
+ }
34
+
13
35
/**
14
36
* @param string $expectedResult
15
37
* @param string $nameInLayout
@@ -18,11 +40,8 @@ class AbstractBlockTest extends \PHPUnit_Framework_TestCase
18
40
*/
19
41
public function testGetUiId ($ expectedResult , $ nameInLayout , $ methodArguments )
20
42
{
21
- /** @var $block \Magento\Framework\View\Element\AbstractBlock|\PHPUnit_Framework_MockObject_MockObject */
22
- $ block = $ this ->getMockForAbstractClass ('Magento\Framework\View\Element\AbstractBlock ' , [], '' , false );
23
- $ block ->setNameInLayout ($ nameInLayout );
24
-
25
- $ this ->assertEquals ($ expectedResult , call_user_func_array ([$ block , 'getUiId ' ], $ methodArguments ));
43
+ $ this ->block ->setNameInLayout ($ nameInLayout );
44
+ $ this ->assertEquals ($ expectedResult , call_user_func_array ([$ this ->block , 'getUiId ' ], $ methodArguments ));
26
45
}
27
46
28
47
/**
@@ -57,46 +76,63 @@ public function getUiIdDataProvider()
57
76
];
58
77
}
59
78
79
+ /**
80
+ * @return void
81
+ */
60
82
public function testGetVar ()
61
83
{
62
- $ this ->markTestIncomplete ('MAGETWO-11727 ' );
63
- $ config = $ this ->getMock ('Magento\Framework\Config\View ' , ['getVarValue ' ], [], '' , false );
84
+ $ config = $ this ->getMock (View::class, ['getVarValue ' ], [], '' , false );
64
85
$ module = uniqid ();
65
- $ config ->expects (
66
- $ this ->at (0 )
67
- )->method (
68
- 'getVarValue '
69
- )->with (
70
- 'Magento_Theme ' ,
71
- 'v1 '
72
- )->will (
73
- $ this ->returnValue ('one ' )
74
- );
75
- $ config ->expects ($ this ->at (1 ))->method ('getVarValue ' )->with ($ module , 'v2 ' )->will ($ this ->returnValue ('two ' ));
76
86
77
- $ configManager = $ this ->getMock ('Magento\Framework\View\ConfigInterface ' , [], [], '' , false );
78
- $ configManager ->expects ($ this ->exactly (2 ))->method ('getViewConfig ' )->will ($ this ->returnValue ($ config ));
87
+ $ config ->expects ($ this ->any ())
88
+ ->method ('getVarValue ' )
89
+ ->willReturnMap ([
90
+ ['Magento_Theme ' , 'v1 ' , 'one ' ],
91
+ [$ module , 'v2 ' , 'two ' ]
92
+ ]);
93
+
94
+ $ configManager = $ this ->getMock (ConfigInterface::class, [], [], '' , false );
95
+ $ configManager ->expects ($ this ->exactly (2 ))->method ('getViewConfig ' )->willReturn ($ config );
79
96
80
- /** @var $block \Magento\Framework\View\Element\ AbstractBlock|\PHPUnit_Framework_MockObject_MockObject */
97
+ /** @var $block AbstractBlock|\PHPUnit_Framework_MockObject_MockObject */
81
98
$ params = ['viewConfig ' => $ configManager ];
82
99
$ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
83
100
$ block = $ this ->getMockForAbstractClass (
84
- 'Magento\Framework\View\Element\AbstractBlock ' ,
85
- $ helper ->getConstructArguments ('Magento\Framework\View\Element\AbstractBlock ' , $ params ),
86
- uniqid ('Magento \\Theme \\Block \\AbstractBlock \\' )
101
+ AbstractBlock::class,
102
+ $ helper ->getConstructArguments (AbstractBlock::class, $ params )
87
103
);
104
+ $ block ->setData ('module_name ' , 'Magento_Theme ' );
88
105
89
106
$ this ->assertEquals ('one ' , $ block ->getVar ('v1 ' ));
90
107
$ this ->assertEquals ('two ' , $ block ->getVar ('v2 ' , $ module ));
91
108
}
92
109
110
+ /**
111
+ * @return void
112
+ */
93
113
public function testIsScopePrivate ()
94
114
{
95
- $ contextMock = $ this ->getMock ('Magento\Framework\View\Element\Context ' , [], [], '' , false );
96
- $ block = $ this ->getMockForAbstractClass (
97
- 'Magento\Framework\View\Element\AbstractBlock ' ,
98
- ['context ' => $ contextMock ]
99
- );
100
- $ this ->assertEquals (false , $ block ->isScopePrivate ());
115
+ $ this ->assertFalse ($ this ->block ->isScopePrivate ());
116
+ }
117
+
118
+ /**
119
+ * @return void
120
+ */
121
+ public function testGetCacheKey ()
122
+ {
123
+ $ cacheKey = 'testKey ' ;
124
+ $ this ->block ->setData ('cache_key ' , $ cacheKey );
125
+ $ this ->assertEquals (AbstractBlock::CACHE_KEY_PREFIX . $ cacheKey , $ this ->block ->getCacheKey ());
126
+ }
127
+
128
+ /**
129
+ * @return void
130
+ */
131
+ public function testGetCacheKeyByName ()
132
+ {
133
+ $ nameInLayout = 'testBlock ' ;
134
+ $ this ->block ->setNameInLayout ($ nameInLayout );
135
+ $ cacheKey = sha1 ($ nameInLayout );
136
+ $ this ->assertEquals (AbstractBlock::CACHE_KEY_PREFIX . $ cacheKey , $ this ->block ->getCacheKey ());
101
137
}
102
138
}
0 commit comments