66
77namespace Magento \Framework \View \Test \Unit \Page \Config \Generator ;
88
9- use \Magento \Framework \View \Page \Config \Generator \Head ;
10-
9+ use Magento \Framework \View \Page \Config \Generator \Head ;
1110use Magento \Framework \View \Page \Config as PageConfig ;
1211use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
12+ use Magento \Framework \View \Layout \Generator \Context ;
13+ use Magento \Framework \View \Page \Config \Structure ;
14+ use Magento \Framework \View \Layout \Reader \Context as ReaderContext ;
1315
1416/**
1517 * Test for page config generator model
@@ -26,6 +28,11 @@ class HeadTest extends \PHPUnit_Framework_TestCase
2628 */
2729 protected $ pageConfigMock ;
2830
31+ /**
32+ * @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
33+ */
34+ protected $ urlMock ;
35+
2936 /**
3037 * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject
3138 */
@@ -39,47 +46,70 @@ protected function setUp()
3946 $ this ->title = $ this ->getMockBuilder (\Magento \Framework \View \Page \Title::class)
4047 ->disableOriginalConstructor ()
4148 ->getMock ();
49+ $ this ->urlMock = $ this ->getMockBuilder (\Magento \Framework \UrlInterface::class)
50+ ->disableOriginalConstructor ()
51+ ->getMock ();
4252
4353 $ objectManagerHelper = new ObjectManagerHelper ($ this );
4454 $ this ->headGenerator = $ objectManagerHelper ->getObject (
4555 \Magento \Framework \View \Page \Config \Generator \Head::class,
4656 [
4757 'pageConfig ' => $ this ->pageConfigMock ,
58+ 'url ' => $ this ->urlMock ,
4859 ]
4960 );
5061 }
5162
5263 public function testProcess ()
5364 {
54- $ generatorContextMock = $ this ->getMockBuilder (\Magento \Framework \View \Layout \Generator \Context::class)
55- ->disableOriginalConstructor ()
56- ->getMock ();
65+ $ generatorContextMock = $ this ->getMock (Context::class, [], [], '' , false );
5766 $ this ->title ->expects ($ this ->any ())->method ('set ' )->with ()->will ($ this ->returnSelf ());
58- $ structureMock = $ this ->getMockBuilder (\Magento \Framework \View \Page \Config \Structure::class)
59- ->disableOriginalConstructor ()
60- ->getMock ();
61-
62- $ readerContextMock = $ this ->getMockBuilder (\Magento \Framework \View \Layout \Reader \Context::class)
63- ->disableOriginalConstructor ()
64- ->getMock ();
65- $ readerContextMock ->expects ($ this ->any ())
66- ->method ('getPageConfigStructure ' )
67- ->willReturn ($ structureMock );
67+ $ structureMock = $ this ->getMock (Structure::class, [], [], '' , false );
68+ $ readerContextMock = $ this ->getMock (ReaderContext::class, [], [], '' , false );
69+ $ readerContextMock ->expects ($ this ->any ())->method ('getPageConfigStructure ' )->willReturn ($ structureMock );
6870
6971 $ structureMock ->expects ($ this ->once ())->method ('processRemoveAssets ' );
7072 $ structureMock ->expects ($ this ->once ())->method ('processRemoveElementAttributes ' );
73+ $ this ->urlMock ->expects ($ this ->once ())
74+ ->method ('getUrl ' )
75+ ->with ('customcss/render/css ' )
76+ ->willReturn ('http://magento.dev/customcss/render/css ' );
7177
7278 $ assets = [
73- 'remoteCss ' => ['src ' => 'file-url ' , 'src_type ' => 'url ' , 'media ' => "all " , 'content_type ' => 'css ' ],
74- 'remoteLink ' => ['src ' => 'file-url ' , 'src_type ' => 'url ' , 'media ' => "all " ],
75- 'name ' => ['src ' => 'file-path ' , 'ie_condition ' => 'lt IE 7 ' , 'media ' => "print " , 'content_type ' => 'css ' ],
79+ 'remoteCss ' => [
80+ 'src ' => 'file-url-css ' ,
81+ 'src_type ' => 'url ' ,
82+ 'content_type ' => 'css ' ,
83+ 'media ' => 'all ' ,
84+ ],
85+ 'remoteLink ' => [
86+ 'src ' => 'file-url-link ' ,
87+ 'src_type ' => 'url ' ,
88+ 'media ' => 'all ' ,
89+ ],
90+ 'controllerCss ' => [
91+ 'src ' => 'customcss/render/css ' ,
92+ 'src_type ' => 'controller ' ,
93+ 'content_type ' => 'css ' ,
94+ 'media ' => 'all ' ,
95+ ],
96+ 'name ' => [
97+ 'src ' => 'file-path ' ,
98+ 'ie_condition ' => 'lt IE 7 ' ,
99+ 'content_type ' => 'css ' ,
100+ 'media ' => 'print ' ,
101+ ],
76102 ];
103+
77104 $ this ->pageConfigMock ->expects ($ this ->at (0 ))
78105 ->method ('addRemotePageAsset ' )
79- ->with ('remoteCss ' , 'css ' , ['attributes ' => ['media ' => 'all ' ]]);
106+ ->with ('file-url-css ' , 'css ' , ['attributes ' => ['media ' => 'all ' ]]);
80107 $ this ->pageConfigMock ->expects ($ this ->at (1 ))
81108 ->method ('addRemotePageAsset ' )
82- ->with ('remoteLink ' , Head::VIRTUAL_CONTENT_TYPE_LINK , ['attributes ' => ['media ' => 'all ' ]]);
109+ ->with ('file-url-link ' , Head::VIRTUAL_CONTENT_TYPE_LINK , ['attributes ' => ['media ' => 'all ' ]]);
110+ $ this ->pageConfigMock ->expects ($ this ->at (2 ))
111+ ->method ('addRemotePageAsset ' )
112+ ->with ('http://magento.dev/customcss/render/css ' , 'css ' , ['attributes ' => ['media ' => 'all ' ]]);
83113 $ this ->pageConfigMock ->expects ($ this ->once ())
84114 ->method ('addPageAsset ' )
85115 ->with ('name ' , ['attributes ' => ['media ' => 'print ' ], 'ie_condition ' => 'lt IE 7 ' ]);
@@ -121,9 +151,7 @@ public function testProcess()
121151 [PageConfig::ELEMENT_TYPE_HTML , 'html_attr_1 ' , 'html_attr_1 ' ]
122152 );
123153
124- $ this ->assertEquals (
125- $ this ->headGenerator ,
126- $ this ->headGenerator ->process ($ readerContextMock , $ generatorContextMock )
127- );
154+ $ result = $ this ->headGenerator ->process ($ readerContextMock , $ generatorContextMock );
155+ $ this ->assertEquals ($ this ->headGenerator , $ result );
128156 }
129157}
0 commit comments