Skip to content

Commit

Permalink
MAGETWO-59579: [Github #6943] grunt exec:<theme> doesn't work with @i…
Browse files Browse the repository at this point in the history
  • Loading branch information
eug123 committed Oct 28, 2016
1 parent 76315a6 commit 4488d4c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\Css\PreProcessor\Instruction;

use Magento\Framework\View\Asset\LocalInterface;
Expand All @@ -22,7 +20,10 @@ class Import implements PreProcessorInterface
* Pattern of @import instruction
*/
const REPLACE_PATTERN =
'#@import\s+(\((?P<type>\w+)\)\s+)?[\'\"](?P<path>(?![/\\\]|\w:[/\\\])[^\"\']+)[\'\"]\s*?(?P<media>.*?);#';
'#@import(?!.*?\surl\(.*?)'
. '(?P<start>[\(\),\w\s]*?[\'\"])'
. '(?P<path>(?![/\\\]|\w*?:[/\\\])[^\"\']+)'
. '(?P<end>[\'\"][\s\w\(\)]*?);#';

/**
* @var \Magento\Framework\View\Asset\NotationResolver\Module
Expand Down Expand Up @@ -133,9 +134,9 @@ protected function replace(array $matchedContent, LocalInterface $asset, $conten
$matchedFileId = $this->fixFileExtension($matchedContent['path'], $contentType);
$this->recordRelatedFile($matchedFileId, $asset);
$resolvedPath = $this->notationResolver->convertModuleNotationToPath($asset, $matchedFileId);
$typeString = empty($matchedContent['type']) ? '' : '(' . $matchedContent['type'] . ') ';
$mediaString = empty($matchedContent['media']) ? '' : ' ' . trim($matchedContent['media']);
return "@import {$typeString}'{$resolvedPath}'{$mediaString};";
$start = $matchedContent['start'];
$end = $matchedContent['end'];
return "@import{$start}{$resolvedPath}{$end};";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ImportTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{

$this->notationResolver = $this->getMock(
$this->notationResolver = $this->getMock(
\Magento\Framework\View\Asset\NotationResolver\Module::class, [], [], '', false
);
$this->asset = $this->getMock(\Magento\Framework\View\Asset\File::class, [], [], '', false);
Expand All @@ -63,7 +63,11 @@ protected function setUp()
public function testProcess($originalContent, $foundPath, $resolvedPath, $expectedContent)
{
$chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, $originalContent, 'less', 'path');
$this->notationResolver->expects($this->once())
$invoke = $this->once();
if (preg_match('/^(http:|https:|\/+)/', $foundPath)) {
$invoke = $this->never();
}
$this->notationResolver->expects($invoke)
->method('convertModuleNotationToPath')
->with($this->asset, $foundPath)
->will($this->returnValue($resolvedPath));
Expand All @@ -78,50 +82,70 @@ public function testProcess($originalContent, $foundPath, $resolvedPath, $expect
public function processDataProvider()
{
return [
'non-modular notation' => [
'@import (type) "some/file.css" media;',
'some/file.css',
'some/file.css',
"@import (type) 'some/file.css' media;",
'non-modular notation, no extension' => [
'@import (type) \'some/file\' media;',
'some/file.less',
'some/file.less',
'@import (type) \'some/file.less\' media;',
],
'modular, with extension' => [
'@import (type) "Magento_Module::something.css" media;',
'Magento_Module::something.css',
'Magento_Module/something.css',
"@import (type) 'Magento_Module/something.css' media;",
'@import (type) "Magento_Module/something.css" media;',
],
'remote file import url()' => [
'@import (type) url("http://example.com/css/some.css") media;',
'http://example.com/css/some.css',
null,
'@import (type) url("http://example.com/css/some.css") media;',
],
'invalid path' => [
'@import (type) url("/example.com/css/some.css") media;',
'/example.com/css/some.css',
null,
'@import (type) url("/example.com/css/some.css") media;',
],
'modular, no extension' => [
'@import (type) "Magento_Module::something" media;',
'Magento_Module::something.less',
'Magento_Module/something.less',
"@import (type) 'Magento_Module/something.less' media;",
'@import (type) "Magento_Module/something.less" media;',
],
'no type' => [
'@import "Magento_Module::something.css" media;',
'Magento_Module::something.css',
'Magento_Module/something.css',
"@import 'Magento_Module/something.css' media;",
'@import "Magento_Module/something.css" media;',
],
'no media' => [
'@import (type) "Magento_Module::something.css";',
'Magento_Module::something.css',
'Magento_Module/something.css',
"@import (type) 'Magento_Module/something.css';",
'@import (type) "Magento_Module/something.css";',
],
'with single line comment, replace' => [
'@import (type) "some/file" media;' . PHP_EOL
. '// @import (type) "unnecessary/file.css" media;',
'some/file.less',
'some/file.less',
'@import (type) "some/file.less" media;' . PHP_EOL,
],
'with single line comment' => [
'@import (type) "some/file.css" media;' . PHP_EOL
. '// @import (type) "unnecessary/file.css" media;',
'some/file.css',
'some/file.css',
"@import (type) 'some/file.css' media;" . PHP_EOL,
'with single line comment, no replace' => [
'@import (type) "some/file.less" media;' . PHP_EOL
. '// @import (type) "unnecessary/file" media;',
'some/file.less',
'some/file.less',
'@import (type) "some/file.less" media;' . PHP_EOL
. '// @import (type) "unnecessary/file" media;',
],
'with multi line comment' => [
'@import (type) "some/file.css" media;' . PHP_EOL
'@import (type) "some/file" media;' . PHP_EOL
. '/* @import (type) "unnecessary/file.css" media;' . PHP_EOL
. '@import (type) "another/unnecessary/file.css" media; */',
'some/file.css',
'some/file.css',
"@import (type) 'some/file.css' media;" . PHP_EOL,
'some/file.less',
'some/file.less',
'@import (type) "some/file.less" media;' . PHP_EOL,
],
];
}
Expand Down

0 comments on commit 4488d4c

Please sign in to comment.