4
4
* See COPYING.txt for license details.
5
5
*/
6
6
namespace Magento \Framework \View \Test \Unit ;
7
+ use Magento \Framework \Serialize \SerializerInterface ;
7
8
8
9
/**
9
10
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -81,6 +82,16 @@ class LayoutTest extends \PHPUnit_Framework_TestCase
81
82
*/
82
83
protected $ readerContextMock ;
83
84
85
+ /**
86
+ * @var \Magento\Framework\View\Page\Config\Structure|\PHPUnit_Framework_MockObject_MockObject
87
+ */
88
+ private $ pageConfigStructure ;
89
+
90
+ /**
91
+ * @var \Magento\Framework\View\Layout\ScheduledStructure|\PHPUnit_Framework_MockObject_MockObject
92
+ */
93
+ private $ layoutScheduledSructure ;
94
+
84
95
/**
85
96
* @var \Magento\Framework\View\Layout\Generator\ContextFactory|\PHPUnit_Framework_MockObject_MockObject
86
97
*/
@@ -96,6 +107,11 @@ class LayoutTest extends \PHPUnit_Framework_TestCase
96
107
*/
97
108
protected $ loggerMock ;
98
109
110
+ /**
111
+ * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
112
+ */
113
+ private $ serializer ;
114
+
99
115
protected function setUp ()
100
116
{
101
117
$ this ->structureMock = $ this ->getMockBuilder (\Magento \Framework \View \Layout \Data \Structure::class)
@@ -141,9 +157,22 @@ protected function setUp()
141
157
$ this ->readerContextFactoryMock = $ this ->getMockBuilder (
142
158
\Magento \Framework \View \Layout \Reader \ContextFactory::class
143
159
)->disableOriginalConstructor ()->getMock ();
160
+
161
+ $ this ->pageConfigStructure = $ this ->getMockBuilder (\Magento \Framework \View \Page \Config \Structure::class)
162
+ ->setMethods (['__toArray ' , 'populateWithArray ' ])
163
+ ->getMock ();
164
+ $ this ->layoutScheduledSructure = $ this ->getMockBuilder (\Magento \Framework \View \Layout \ScheduledStructure::class)
165
+ ->setMethods (['__toArray ' , 'populateWithArray ' ])
166
+ ->getMock ();
144
167
$ this ->readerContextMock = $ this ->getMockBuilder (\Magento \Framework \View \Layout \Reader \Context::class)
168
+ ->setMethods (['getPageConfigStructure ' , 'getScheduledStructure ' ])
145
169
->disableOriginalConstructor ()
146
170
->getMock ();
171
+ $ this ->readerContextMock ->expects ($ this ->any ())->method ('getPageConfigStructure ' )
172
+ ->willReturn ($ this ->pageConfigStructure );
173
+ $ this ->readerContextMock ->expects ($ this ->any ())->method ('getScheduledStructure ' )
174
+ ->willReturn ($ this ->layoutScheduledSructure );
175
+
147
176
$ this ->generatorContextFactoryMock = $ this ->getMockBuilder (
148
177
\Magento \Framework \View \Layout \Generator \ContextFactory::class
149
178
)
@@ -154,6 +183,16 @@ protected function setUp()
154
183
->getMock ();
155
184
$ this ->loggerMock = $ this ->getMockBuilder (\Psr \Log \LoggerInterface::class)
156
185
->getMock ();
186
+ $ this ->serializer = $ this ->getMock (\Magento \Framework \Serialize \SerializerInterface::class);
187
+ $ this ->serializer ->expects ($ this ->any ())->method ('serialize ' )
188
+ ->willReturnCallback (function ($ value ) {
189
+ return json_encode ($ value );
190
+ });
191
+ $ this ->serializer ->expects ($ this ->any ())->method ('unserialize ' )
192
+ ->willReturnCallback (function ($ value ) {
193
+ return json_decode ($ value , true );
194
+ });
195
+
157
196
158
197
$ this ->model = new \Magento \Framework \View \Layout (
159
198
$ this ->processorFactoryMock ,
@@ -168,7 +207,8 @@ protected function setUp()
168
207
$ this ->generatorContextFactoryMock ,
169
208
$ this ->appStateMock ,
170
209
$ this ->loggerMock ,
171
- true
210
+ true ,
211
+ $ this ->serializer
172
212
);
173
213
}
174
214
@@ -735,9 +775,32 @@ public function testGenerateElementsWithoutCache()
735
775
->with ($ this ->readerContextMock , $ xml )
736
776
->willReturnSelf ();
737
777
778
+ $ pageConfigStructureData = [
779
+ 'field_1 ' => 123 ,
780
+ 'field_2 ' => 'text ' ,
781
+ 'field_3 ' => [
782
+ 'field_3_1 ' => '1244 ' ,
783
+ 'field_3_2 ' => null ,
784
+ 'field_3_3 ' => false ,
785
+ ]
786
+ ];
787
+ $ this ->pageConfigStructure ->expects ($ this ->any ())->method ('__toArray ' )
788
+ ->willReturn ($ pageConfigStructureData );
789
+
790
+ $ layoutScheduledStructureData = [
791
+ 'field_1 ' => 1283 ,
792
+ 'field_2 ' => 'text_qwertyuiop[]asdfghjkl; '
793
+ ];
794
+ $ this ->layoutScheduledSructure ->expects ($ this ->any ())->method ('__toArray ' )
795
+ ->willReturn ($ layoutScheduledStructureData );
796
+ $ data = [
797
+ 'pageConfigStructure ' => $ pageConfigStructureData ,
798
+ 'scheduledStructure ' => $ layoutScheduledStructureData
799
+ ];
800
+
738
801
$ this ->cacheMock ->expects ($ this ->once ())
739
802
->method ('save ' )
740
- ->with (serialize ( $ this -> readerContextMock ), 'structure_ ' . $ layoutCacheId , $ handles )
803
+ ->with (json_encode ( $ data ), 'structure_ ' . $ layoutCacheId , $ handles )
741
804
->willReturn (true );
742
805
743
806
$ generatorContextMock = $ this ->getMockBuilder (\Magento \Framework \View \Layout \Generator \Context::class)
@@ -774,6 +837,9 @@ public function testGenerateElementsWithCache()
774
837
$ xml = simplexml_load_string ('<layout/> ' , \Magento \Framework \View \Layout \Element::class);
775
838
$ this ->model ->setXml ($ xml );
776
839
840
+ $ this ->readerContextFactoryMock ->expects ($ this ->once ())
841
+ ->method ('create ' )
842
+ ->willReturn ($ this ->readerContextMock );
777
843
$ themeMock = $ this ->getMockForAbstractClass (\Magento \Framework \View \Design \ThemeInterface::class);
778
844
$ this ->themeResolverMock ->expects ($ this ->once ())
779
845
->method ('get ' )
@@ -787,14 +853,33 @@ public function testGenerateElementsWithCache()
787
853
->method ('getCacheId ' )
788
854
->willReturn ($ layoutCacheId );
789
855
790
- $ readerContextMock = $ this ->getMockBuilder (\Magento \Framework \View \Layout \Reader \Context::class)
791
- ->disableOriginalConstructor ()
792
- ->getMock ();
856
+ $ pageConfigStructureData = [
857
+ 'field_1 ' => 123 ,
858
+ 'field_2 ' => 'text ' ,
859
+ 'field_3 ' => [
860
+ 'field_3_1 ' => '1244 ' ,
861
+ 'field_3_2 ' => null ,
862
+ 'field_3_3 ' => false ,
863
+ ]
864
+ ];
865
+ $ this ->pageConfigStructure ->expects ($ this ->once ())->method ('populateWithArray ' )
866
+ ->with ($ pageConfigStructureData );
867
+
868
+ $ layoutScheduledStructureData = [
869
+ 'field_1 ' => 1283 ,
870
+ 'field_2 ' => 'text_qwertyuiop[]asdfghjkl; '
871
+ ];
872
+ $ this ->layoutScheduledSructure ->expects ($ this ->once ())->method ('populateWithArray ' )
873
+ ->with ($ layoutScheduledStructureData );
874
+ $ data = [
875
+ 'pageConfigStructure ' => $ pageConfigStructureData ,
876
+ 'scheduledStructure ' => $ layoutScheduledStructureData
877
+ ];
793
878
794
879
$ this ->cacheMock ->expects ($ this ->once ())
795
880
->method ('load ' )
796
881
->with ('structure_ ' . $ layoutCacheId )
797
- ->willReturn (serialize ( $ readerContextMock ));
882
+ ->willReturn (json_encode ( $ data ));
798
883
799
884
$ this ->readerPoolMock ->expects ($ this ->never ())
800
885
->method ('interpret ' );
@@ -811,7 +896,7 @@ public function testGenerateElementsWithCache()
811
896
812
897
$ this ->generatorPoolMock ->expects ($ this ->once ())
813
898
->method ('process ' )
814
- ->with ($ readerContextMock , $ generatorContextMock )
899
+ ->with ($ this -> readerContextMock , $ generatorContextMock )
815
900
->willReturn (true );
816
901
817
902
$ elements = [
0 commit comments