Skip to content

Commit c037252

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-35025' into BUGS
2 parents b70f35d + 08a75f8 commit c037252

File tree

6 files changed

+109
-5
lines changed

6 files changed

+109
-5
lines changed

lib/internal/Magento/Framework/View/Layout/etc/head.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<xs:attribute name="sizes" type="xs:string"/>
1919
<xs:attribute name="target" type="xs:string"/>
2020
<xs:attribute name="type" type="xs:string"/>
21+
<xs:attribute name="src_type" type="xs:string"/>
2122
</xs:complexType>
2223

2324
<xs:complexType name="metaType">
@@ -35,6 +36,7 @@
3536
<xs:attribute name="async" type="xs:string"/>
3637
<xs:attribute name="charset" type="xs:string"/>
3738
<xs:attribute name="type" type="xs:string"/>
39+
<xs:attribute name="src_type" type="xs:string"/>
3840
</xs:complexType>
3941

4042
<xs:complexType name="headAttributeType">

lib/internal/Magento/Framework/View/Page/Config/Generator/Head.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Head implements Layout\GeneratorInterface
4949
protected $serviceAssetProperties = [
5050
'src',
5151
'src_type',
52+
'content_type',
5253
];
5354

5455
/**
@@ -108,7 +109,7 @@ protected function processAssets(Structure $pageStructure)
108109
if (isset($data['src_type']) && in_array($data['src_type'], $this->remoteAssetTypes)) {
109110
$this->pageConfig->addRemotePageAsset(
110111
$name,
111-
self::VIRTUAL_CONTENT_TYPE_LINK,
112+
isset($data['content_type']) ? $data['content_type'] : self::VIRTUAL_CONTENT_TYPE_LINK,
112113
$this->getAssetProperties($data)
113114
);
114115
} else {

lib/internal/Magento/Framework/View/Page/Config/Reader/Head.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ public function getSupportedNodes()
4141
return [self::TYPE_HEAD];
4242
}
4343

44+
/**
45+
* Add asset content type to node by name
46+
*
47+
* @param Layout\Element $node
48+
* @return void
49+
*/
50+
protected function addContentTypeByNodeName(Layout\Element $node)
51+
{
52+
switch ($node->getName()) {
53+
case self::HEAD_CSS:
54+
$node->addAttribute('content_type', 'css');
55+
break;
56+
case self::HEAD_SCRIPT:
57+
$node->addAttribute('content_type', 'js');
58+
break;
59+
}
60+
}
61+
4462
/**
4563
* {@inheritdoc}
4664
*
@@ -59,6 +77,7 @@ public function interpret(
5977
case self::HEAD_CSS:
6078
case self::HEAD_SCRIPT:
6179
case self::HEAD_LINK:
80+
$this->addContentTypeByNodeName($node);
6281
$pageConfigStructure->addAssets($node->getAttribute('src'), $this->getAttributes($node));
6382
break;
6483

lib/internal/Magento/Framework/View/Test/Unit/Page/Config/Generator/HeadTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,16 @@ public function testProcess()
7070
$structureMock->expects($this->once())->method('processRemoveElementAttributes');
7171

7272
$assets = [
73-
'remoteName' => ['src' => 'file-url', 'src_type' => 'url', 'media' => "all"],
74-
'name' => ['src' => 'file-path', 'ie_condition' => 'lt IE 7', 'media' => "print"],
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'],
7576
];
76-
$this->pageConfigMock->expects($this->once())
77+
$this->pageConfigMock->expects($this->at(0))
78+
->method('addRemotePageAsset')
79+
->with('remoteCss', 'css', ['attributes' => ['media' => 'all']]);
80+
$this->pageConfigMock->expects($this->at(1))
7781
->method('addRemotePageAsset')
78-
->with('remoteName', Head::VIRTUAL_CONTENT_TYPE_LINK, ['attributes' => ['media' => 'all']]);
82+
->with('remoteLink', Head::VIRTUAL_CONTENT_TYPE_LINK, ['attributes' => ['media' => 'all']]);
7983
$this->pageConfigMock->expects($this->once())
8084
->method('addPageAsset')
8185
->with('name', ['attributes' => ['media' => 'print'], 'ie_condition' => 'lt IE 7']);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\View\Test\Unit\Page\Config\Reader;
8+
9+
use Magento\Framework\View\Layout\Element;
10+
use Magento\Framework\View\Page\Config;
11+
use Magento\Framework\View\Page\Config\Reader\Head;
12+
13+
class HeadTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var Head
17+
*/
18+
protected $model;
19+
20+
protected function setUp()
21+
{
22+
$this->model = new Head();
23+
}
24+
25+
public function testInterpret()
26+
{
27+
$readerContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context')
28+
->disableOriginalConstructor()
29+
->getMock();
30+
$structureMock = $this->getMockBuilder('Magento\Framework\View\Page\Config\Structure')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
$readerContextMock->expects($this->once())
34+
->method('getPageConfigStructure')
35+
->willReturn($structureMock);
36+
37+
$xml = file_get_contents(__DIR__ . '/../_files/template_head.xml');
38+
$element = new Element($xml);
39+
40+
$structureMock->expects($this->at(0))
41+
->method('setTitle')
42+
->with('Test title')
43+
->willReturnSelf();
44+
45+
$structureMock->expects($this->at(1))
46+
->method('setMetaData')
47+
->with('meta_name', 'meta_content')
48+
->willReturnSelf();
49+
50+
$structureMock->expects($this->at(2))
51+
->method('addAssets')
52+
->with('path/file.css', ['src' => 'path/file.css', 'media' => 'all', 'content_type' => 'css'])
53+
->willReturnSelf();
54+
55+
$structureMock->expects($this->at(3))
56+
->method('addAssets')
57+
->with('path/file.js', ['src' => 'path/file.js', 'defer' => 'defer', 'content_type' => 'js'])
58+
->willReturnSelf();
59+
60+
$structureMock->expects($this->at(4))
61+
->method('addAssets')
62+
->with('http://url.com', ['src' => 'http://url.com', 'src_type' => 'url'])
63+
->willReturnSelf();
64+
65+
$structureMock->expects($this->at(5))
66+
->method('removeAssets')
67+
->with('path/remove/file.css')
68+
->willReturnSelf();
69+
70+
$structureMock->expects($this->at(6))
71+
->method('setElementAttribute')
72+
->with(Config::ELEMENT_TYPE_HEAD, 'head_attribute_name', 'head_attribute_value')
73+
->willReturnSelf();
74+
75+
$this->assertEquals($this->model, $this->model->interpret($readerContextMock, $element->children()[0]));
76+
}
77+
}

lib/internal/Magento/Framework/View/Test/Unit/Page/Config/_files/template_head.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<meta name="meta_name" content="meta_content"/>
1212
<css src="path/file.css" media="all" />
1313
<script src="path/file.js" defer="defer"/>
14+
<link src="http://url.com" src_type="url"/>
1415
<remove src="path/remove/file.css"/>
1516
<attribute name="head_attribute_name" value="head_attribute_value"/>
1617
</head>

0 commit comments

Comments
 (0)