14
14
*/
15
15
class HelperTest extends \PHPUnit_Framework_TestCase
16
16
{
17
+ /**
18
+ * @var \Magento\Framework\View\Layout\ScheduledStructure|\PHPUnit_Framework_MockObject_MockObject
19
+ */
20
+ protected $ scheduledStructure ;
21
+
22
+ /**
23
+ * @var \Magento\Framework\View\Layout\Data\Structure|\PHPUnit_Framework_MockObject_MockObject
24
+ */
25
+ protected $ dataStructure ;
26
+
27
+ /**
28
+ * @var Helper
29
+ */
30
+ protected $ helper ;
31
+
32
+ public function setUp ()
33
+ {
34
+ $ this ->scheduledStructure = $ this ->getMockBuilder ('Magento\Framework\View\Layout\ScheduledStructure ' )
35
+ ->disableOriginalConstructor ()
36
+ ->getMock ();
37
+
38
+ $ this ->dataStructure = $ this ->getMockBuilder ('Magento\Framework\View\Layout\Data\Structure ' )
39
+ ->disableOriginalConstructor ()
40
+ ->getMock ();
41
+
42
+ $ helperObjectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
43
+ $ this ->helper = $ helperObjectManager ->getObject ('Magento\Framework\View\Layout\ScheduledStructure\Helper ' );
44
+ }
45
+
17
46
/**
18
47
* @param string $currentNodeName
19
48
* @param string $actualNodeName
20
- * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $unsetPathElementCount
21
- * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $unsetStructureElementCount
22
- * @dataProvider providerScheduleStructure
49
+ * @param int $unsetPathElementCount
50
+ * @param int $unsetStructureElementCount
51
+ *
52
+ * @dataProvider scheduleStructureDataProvider
23
53
*/
24
54
public function testScheduleStructure (
25
55
$ currentNodeName ,
@@ -34,73 +64,67 @@ public function testScheduleStructure(
34
64
$ testPath = 'test_path ' ;
35
65
$ potentialChild = 'potential_child ' ;
36
66
37
- /** @var Layout\ScheduledStructure|\PHPUnit_Framework_MockObject_MockObject $scheduledStructure */
38
- $ scheduledStructure = $ this ->getMock ('Magento\Framework\View\Layout\ScheduledStructure ' , [], [], '' , false );
39
- $ scheduledStructure ->expects ($ this ->once ())->method ('hasPath ' )
67
+ $ this ->scheduledStructure ->expects ($ this ->once ())->method ('hasPath ' )
40
68
->with ($ parentNodeName )
41
69
->will ($ this ->returnValue (true ));
42
- $ scheduledStructure ->expects ($ this ->any ())->method ('hasStructureElement ' )
70
+ $ this -> scheduledStructure ->expects ($ this ->any ())->method ('hasStructureElement ' )
43
71
->with ($ actualNodeName )
44
72
->will ($ this ->returnValue (true ));
45
- $ scheduledStructure ->expects ($ this ->once ())->method ('setPathElement ' )
73
+ $ this -> scheduledStructure ->expects ($ this ->once ())->method ('setPathElement ' )
46
74
->with ($ actualNodeName , $ testPath . '/ ' . $ actualNodeName )
47
75
->will ($ this ->returnValue (true ));
48
- $ scheduledStructure ->expects ($ this ->once ())->method ('setStructureElement ' )
76
+ $ this -> scheduledStructure ->expects ($ this ->once ())->method ('setStructureElement ' )
49
77
->with ($ actualNodeName , [$ block , $ currentNodeAs , $ parentNodeName , $ after , true ]);
50
- $ scheduledStructure ->expects ($ this ->once ())->method ('getPath ' )
78
+ $ this -> scheduledStructure ->expects ($ this ->once ())->method ('getPath ' )
51
79
->with ($ parentNodeName )
52
80
->will ($ this ->returnValue ('test_path ' ));
53
- $ scheduledStructure ->expects ($ this ->once ())->method ('getPaths ' )
81
+ $ this -> scheduledStructure ->expects ($ this ->once ())->method ('getPaths ' )
54
82
->will ($ this ->returnValue ([$ potentialChild => $ testPath . '/ ' . $ currentNodeName . '/ ' ]));
55
- $ scheduledStructure ->expects ($ unsetPathElementCount )->method ('unsetPathElement ' )
83
+ $ this -> scheduledStructure ->expects ($ this -> exactly ( $ unsetPathElementCount) )->method ('unsetPathElement ' )
56
84
->with ($ potentialChild );
57
- $ scheduledStructure ->expects ($ unsetStructureElementCount )->method ('unsetStructureElement ' )
85
+ $ this -> scheduledStructure ->expects ($ this -> exactly ( $ unsetStructureElementCount) )->method ('unsetStructureElement ' )
58
86
->with ($ potentialChild );
59
87
60
88
$ currentNode = new \Magento \Framework \View \Layout \Element (
61
89
'< ' . $ block . ' name=" ' . $ currentNodeName . '" as=" ' . $ currentNodeAs . '" after=" ' . $ after . '"/> '
62
90
);
63
91
$ parentNode = new \Magento \Framework \View \Layout \Element ('< ' . $ block . ' name=" ' . $ parentNodeName . '"/> ' );
64
92
65
- /** @var Layout\ScheduledStructure\Helper $helper */
66
- $ helper = (new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this ))
67
- ->getObject ('Magento\Framework\View\Layout\ScheduledStructure\Helper ' );
68
- $ result = $ helper ->scheduleStructure ($ scheduledStructure , $ currentNode , $ parentNode );
93
+ $ result = $ this ->helper ->scheduleStructure ($ this ->scheduledStructure , $ currentNode , $ parentNode );
69
94
$ this ->assertEquals ($ actualNodeName , $ result );
70
95
}
71
96
72
97
/**
73
98
* @return array
74
99
*/
75
- public function providerScheduleStructure ()
100
+ public function scheduleStructureDataProvider ()
76
101
{
77
102
return [
78
- ['current_node ' , 'current_node ' , $ this -> once (), $ this -> once () ],
79
- ['' , 'parent_node_schedule_block0 ' , $ this -> never (), $ this -> never () ]
103
+ ['current_node ' , 'current_node ' , 1 , 1 ],
104
+ ['' , 'parent_node_schedule_block0 ' , 0 , 0 ]
80
105
];
81
106
}
82
107
83
108
public function testScheduleNonExistentElement ()
84
109
{
85
110
$ key = 'key ' ;
86
111
87
- /** @var Layout\ScheduledStructure|\PHPUnit_Framework_MockObject_MockObject $scheduledStructure */
88
- $ scheduledStructure = $ this ->getMock ('Magento\Framework\View\Layout\ScheduledStructure ' , [], [], '' , false );
89
- $ scheduledStructure ->expects ($ this ->once ())->method ('getStructureElement ' )->with ($ key )
112
+ $ this ->scheduledStructure ->expects ($ this ->once ())->method ('getStructureElement ' )->with ($ key )
90
113
->willReturn ([]);
91
- $ scheduledStructure ->expects ($ this ->once ())->method ('unsetPathElement ' )->with ($ key );
92
- $ scheduledStructure ->expects ($ this ->once ())->method ('unsetStructureElement ' )->with ($ key );
114
+ $ this -> scheduledStructure ->expects ($ this ->once ())->method ('unsetPathElement ' )->with ($ key );
115
+ $ this -> scheduledStructure ->expects ($ this ->once ())->method ('unsetStructureElement ' )->with ($ key );
93
116
94
- /** @var Layout\Data\Structure|\PHPUnit_Framework_MockObject_MockObject $scheduledStructure */
95
- $ dataStructure = $ this ->getMock ('Magento\Framework\View\Layout\Data\Structure ' , [], [], '' , false );
96
-
97
- /** @var Layout\ScheduledStructure\Helper $helper */
98
- $ helper = (new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this ))
99
- ->getObject ('Magento\Framework\View\Layout\ScheduledStructure\Helper ' );
100
- $ helper ->scheduleElement ($ scheduledStructure , $ dataStructure , $ key );
117
+ $ this ->helper ->scheduleElement ($ this ->scheduledStructure , $ this ->dataStructure , $ key );
101
118
}
102
119
103
- public function testScheduleElement ()
120
+ /**
121
+ * @param bool $hasParent
122
+ * @param int $setAsChild
123
+ * @param int $toRemoveList
124
+ *
125
+ * @dataProvider scheduleElementDataProvider
126
+ */
127
+ public function testScheduleElement ($ hasParent , $ setAsChild , $ toRemoveList )
104
128
{
105
129
$ key = 'key ' ;
106
130
$ parentName = 'parent ' ;
@@ -109,10 +133,9 @@ public function testScheduleElement()
109
133
$ block = 'block ' ;
110
134
$ data = ['data ' ];
111
135
112
- /** @var Layout\ScheduledStructure|\PHPUnit_Framework_MockObject_MockObject $scheduledStructure */
113
- $ scheduledStructure = $ this ->getMock ('Magento\Framework\View\Layout\ScheduledStructure ' , [], [], '' , false );
114
- $ scheduledStructure ->expects ($ this ->any ())->method ('getStructureElement ' )->will (
115
- $ this ->returnValueMap (
136
+ $ this ->scheduledStructure ->expects ($ this ->any ())
137
+ ->method ('getStructureElement ' )
138
+ ->willReturnMap (
116
139
[
117
140
[
118
141
$ key ,
@@ -127,27 +150,40 @@ public function testScheduleElement()
127
150
],
128
151
[$ parentName , null , []],
129
152
]
130
- )
131
- );
132
- $ scheduledStructure ->expects ($ this ->any ())->method ('getStructureElementData ' )->will (
133
- $ this ->returnValueMap ([
134
- [$ key , null , $ data ],
135
- [$ parentName , null , $ data ],
136
- ])
137
- );
138
- $ scheduledStructure ->expects ($ this ->any ())->method ('hasStructureElement ' )->will ($ this ->returnValue (true ));
139
- $ scheduledStructure ->expects ($ this ->once ())->method ('setElement ' )->with ($ key , [$ block , $ data ]);
140
-
141
- /** @var Layout\Data\Structure|\PHPUnit_Framework_MockObject_MockObject $scheduledStructure */
142
- $ dataStructure = $ this ->getMock ('Magento\Framework\View\Layout\Data\Structure ' , [], [], '' , false );
143
- $ dataStructure ->expects ($ this ->once ())->method ('createElement ' )->with ($ key , ['type ' => $ block ]);
144
- $ dataStructure ->expects ($ this ->once ())->method ('hasElement ' )->with ($ parentName )->will ($ this ->returnValue (true ));
145
- $ dataStructure ->expects ($ this ->once ())->method ('setAsChild ' )->with ($ key , $ parentName , $ alias )
146
- ->will ($ this ->returnValue (true ));
153
+ );
154
+ $ this ->scheduledStructure ->expects ($ this ->any ())
155
+ ->method ('getStructureElementData ' )
156
+ ->willReturnMap (
157
+ [
158
+ [$ key , null , $ data ],
159
+ [$ parentName , null , $ data ],
160
+ ]
161
+ );
162
+ $ this ->scheduledStructure ->expects ($ this ->any ())->method ('hasStructureElement ' )->willReturn (true );
163
+ $ this ->scheduledStructure ->expects ($ this ->once ())->method ('setElement ' )->with ($ key , [$ block , $ data ]);
164
+
165
+ $ this ->dataStructure ->expects ($ this ->once ())->method ('createElement ' )->with ($ key , ['type ' => $ block ]);
166
+ $ this ->dataStructure ->expects ($ this ->once ())->method ('hasElement ' )->with ($ parentName )->willReturn ($ hasParent );
167
+ $ this ->dataStructure ->expects ($ this ->exactly ($ setAsChild ))
168
+ ->method ('setAsChild ' )
169
+ ->with ($ key , $ parentName , $ alias )
170
+ ->willReturn (true );
171
+
172
+ $ this ->scheduledStructure ->expects ($ this ->exactly ($ toRemoveList ))
173
+ ->method ('setElementToBrokenParentList ' )
174
+ ->with ($ key );
147
175
148
- /** @var Layout\ScheduledStructure\Helper $helper */
149
- $ helper = (new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this ))
150
- ->getObject ('Magento\Framework\View\Layout\ScheduledStructure\Helper ' );
151
- $ helper ->scheduleElement ($ scheduledStructure , $ dataStructure , $ key );
176
+ $ this ->helper ->scheduleElement ($ this ->scheduledStructure , $ this ->dataStructure , $ key );
177
+ }
178
+
179
+ /**
180
+ * @return array
181
+ */
182
+ public function scheduleElementDataProvider ()
183
+ {
184
+ return [
185
+ ['hasParent ' => true , 'setAsChild ' => 1 , 'toRemoveList ' => 0 ],
186
+ ['hasParent ' => false , 'setAsChild ' => 0 , 'toRemoveList ' => 1 ],
187
+ ];
152
188
}
153
189
}
0 commit comments