6
6
7
7
namespace Magento \Framework \View \Test \Unit \Page \Config \Generator ;
8
8
9
- use \Magento \Framework \View \Page \Config \Generator \Head ;
10
-
9
+ use Magento \Framework \View \Page \Config \Generator \Head ;
11
10
use Magento \Framework \View \Page \Config as PageConfig ;
12
11
use 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 ;
13
15
14
16
/**
15
17
* Test for page config generator model
@@ -26,6 +28,11 @@ class HeadTest extends \PHPUnit_Framework_TestCase
26
28
*/
27
29
protected $ pageConfigMock ;
28
30
31
+ /**
32
+ * @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
33
+ */
34
+ protected $ urlMock ;
35
+
29
36
/**
30
37
* @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject
31
38
*/
@@ -39,47 +46,70 @@ protected function setUp()
39
46
$ this ->title = $ this ->getMockBuilder (\Magento \Framework \View \Page \Title::class)
40
47
->disableOriginalConstructor ()
41
48
->getMock ();
49
+ $ this ->urlMock = $ this ->getMockBuilder (\Magento \Framework \UrlInterface::class)
50
+ ->disableOriginalConstructor ()
51
+ ->getMock ();
42
52
43
53
$ objectManagerHelper = new ObjectManagerHelper ($ this );
44
54
$ this ->headGenerator = $ objectManagerHelper ->getObject (
45
55
\Magento \Framework \View \Page \Config \Generator \Head::class,
46
56
[
47
57
'pageConfig ' => $ this ->pageConfigMock ,
58
+ 'url ' => $ this ->urlMock ,
48
59
]
49
60
);
50
61
}
51
62
52
63
public function testProcess ()
53
64
{
54
- $ generatorContextMock = $ this ->getMockBuilder (\Magento \Framework \View \Layout \Generator \Context::class)
55
- ->disableOriginalConstructor ()
56
- ->getMock ();
65
+ $ generatorContextMock = $ this ->getMock (Context::class, [], [], '' , false );
57
66
$ 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 );
68
70
69
71
$ structureMock ->expects ($ this ->once ())->method ('processRemoveAssets ' );
70
72
$ 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 ' );
71
77
72
78
$ 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
+ ],
76
102
];
103
+
77
104
$ this ->pageConfigMock ->expects ($ this ->at (0 ))
78
105
->method ('addRemotePageAsset ' )
79
- ->with ('remoteCss ' , 'css ' , ['attributes ' => ['media ' => 'all ' ]]);
106
+ ->with ('file-url-css ' , 'css ' , ['attributes ' => ['media ' => 'all ' ]]);
80
107
$ this ->pageConfigMock ->expects ($ this ->at (1 ))
81
108
->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 ' ]]);
83
113
$ this ->pageConfigMock ->expects ($ this ->once ())
84
114
->method ('addPageAsset ' )
85
115
->with ('name ' , ['attributes ' => ['media ' => 'print ' ], 'ie_condition ' => 'lt IE 7 ' ]);
@@ -121,9 +151,7 @@ public function testProcess()
121
151
[PageConfig::ELEMENT_TYPE_HTML , 'html_attr_1 ' , 'html_attr_1 ' ]
122
152
);
123
153
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 );
128
156
}
129
157
}
0 commit comments