31 private $errorHandler;
46 private $themeProvider;
55 $this->design = $this->getMockForAbstractClass(\
Magento\Framework\View\DesignInterface::class);
56 $this->fileSource = $this->getMockForAbstractClass(\
Magento\Framework\View\
File\CollectorInterface::class);
57 $this->errorHandler = $this->getMockForAbstractClass(
58 \
Magento\Framework\Css\PreProcessor\ErrorHandlerInterface::class
60 $this->asset = $this->createMock(\
Magento\Framework\View\Asset\File::class);
61 $this->asset->expects($this->any())->method(
'getContentType')->will($this->returnValue(
'css'));
62 $this->assetRepo = $this->createMock(\
Magento\Framework\View\Asset\Repository::class);
63 $this->themeProvider = $this->createMock(ThemeProviderInterface::class);
64 $this->
object = (
new ObjectManager($this))->getObject(MagentoImport::class, [
65 'design' => $this->design,
66 'fileSource' => $this->fileSource,
67 'errorHandler' => $this->errorHandler,
68 'assetRepo' => $this->assetRepo,
69 'themeProvider' => $this->themeProvider
82 public function testProcess($originalContent, $foundPath, $resolvedPath, $foundFiles, $expectedContent)
84 $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, $originalContent,
'css',
'path');
85 $relatedAsset = $this->createMock(\
Magento\Framework\View\Asset\File::class);
86 $relatedAsset->expects($this->once())
87 ->method(
'getFilePath')
88 ->will($this->returnValue($resolvedPath));
89 $context = $this->createMock(\
Magento\Framework\View\Asset\
File\FallbackContext::class);
90 $this->assetRepo->expects($this->once())
91 ->method(
'createRelated')
92 ->with($foundPath, $this->asset)
93 ->will($this->returnValue($relatedAsset));
94 $relatedAsset->expects($this->once())->method(
'getContext')->will($this->returnValue($context));
95 $theme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
96 $this->themeProvider->expects($this->once())->method(
'getThemeByFullPath')->will($this->returnValue(
$theme));
98 foreach ($foundFiles as $file) {
99 $fileObject = $this->createMock(\
Magento\Framework\View\File::class);
100 $fileObject->expects($this->any())
101 ->method(
'getModule')
102 ->will($this->returnValue($file[
'module']));
103 $fileObject->expects($this->any())
104 ->method(
'getFilename')
105 ->will($this->returnValue($file[
'filename']));
108 $this->fileSource->expects($this->once())
110 ->with(
$theme, $resolvedPath)
111 ->will($this->returnValue(
$files));
112 $this->
object->process($chain);
113 $this->assertEquals($expectedContent, $chain->getContent());
114 $this->assertEquals(
'css', $chain->getContentType());
123 'non-modular notation' => [
124 '//@magento_import "some/file.css";',
128 [
'module' =>
null,
'filename' =>
'some/file.css'],
129 [
'module' =>
null,
'filename' =>
'theme/some/file.css'],
131 "@import 'some/file.css';\n@import 'some/file.css';\n",
134 '//@magento_import "Magento_Module::some/file.css";',
135 'Magento_Module::some/file.css',
138 [
'module' =>
'Magento_Module',
'filename' =>
'some/file.css'],
139 [
'module' =>
'Magento_Two',
'filename' =>
'some/file.css'],
141 "@import 'Magento_Module::some/file.css';\n@import 'Magento_Two::some/file.css';\n",
143 'non-modular reference notation' => [
144 '//@magento_import (reference) "some/file.css";',
148 [
'module' =>
null,
'filename' =>
'some/file.css'],
149 [
'module' =>
null,
'filename' =>
'theme/some/file.css'],
151 "@import (reference) 'some/file.css';\n@import (reference) 'some/file.css';\n",
153 'modular reference' => [
154 '//@magento_import (reference) "Magento_Module::some/file.css";',
155 'Magento_Module::some/file.css',
158 [
'module' =>
'Magento_Module',
'filename' =>
'some/file.css'],
159 [
'module' =>
'Magento_Two',
'filename' =>
'some/file.css'],
161 "@import (reference) 'Magento_Module::some/file.css';\n" .
162 "@import (reference) 'Magento_Two::some/file.css';\n",
169 $originalContent =
'color: #000000;';
170 $expectedContent =
'color: #000000;';
171 $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, $originalContent,
'css',
'orig');
172 $this->assetRepo->expects($this->never())
173 ->method(
'createRelated');
174 $this->
object->process($chain);
175 $this->assertEquals($expectedContent, $chain->getContent());
176 $this->assertEquals(
'css', $chain->getContentType());
181 $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain(
183 '//@magento_import "some/file.css";',
187 $exception = new \LogicException(
'Error happened');
188 $this->assetRepo->expects($this->once())
189 ->method(
'createRelated')
190 ->will($this->throwException($exception));
191 $this->errorHandler->expects($this->once())
192 ->method(
'processException')
194 $this->
object->process($chain);
195 $this->assertEquals(
'', $chain->getContent());
196 $this->assertEquals(
'css', $chain->getContentType());
testProcess($originalContent, $foundPath, $resolvedPath, $foundFiles, $expectedContent)
foreach($appDirs as $dir) $files