diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChain.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChain.php new file mode 100644 index 0000000000000000000000000000000000000000..80436bcd9efafa475385a926015f798233c9a040 --- /dev/null +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChain.php @@ -0,0 +1,39 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Asset\PreProcessor; + +use Magento\Framework\View\Asset\PreProcessor\Chain; +use Magento\Developer\Model\Config\Source\WorkflowType; +use Magento\Framework\View\Asset\LocalInterface; + +class DeveloperChain extends Chain +{ + /** + * @param LocalInterface $asset + * @param string $origContent + * @param string $origContentType + * @param null $origAssetPath + * @param null $frontEndDevelopmentWorkflowType + */ + public function __construct( + LocalInterface $asset, + $origContent, + $origContentType, + $origAssetPath = null, + $frontEndDevelopmentWorkflowType = null + ) { + parent::__construct( + $asset, + $origContent, + $origContentType, + $origAssetPath, + $frontEndDevelopmentWorkflowType + ); + + $this->targetContentType = $this->origContentType; + $this->targetAssetPath = $origAssetPath; + } +} diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChainFactory.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChainFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..db849f8b825a987b0f265533c0c7e685ee6fef00 --- /dev/null +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChainFactory.php @@ -0,0 +1,64 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Asset\PreProcessor; + +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\View\Asset\PreProcessor\ChainFactory; +use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\View\Asset\PreProcessor\Chain; +use Magento\Developer\Model\Config\Source\WorkflowType; + +class DeveloperChainFactory implements ChainFactoryInterface +{ + /** + * Object manager + * + * @var ObjectManagerInterface + */ + private $_objectManager; + + /** + * @var ChainFactory + */ + private $chainFactory; + + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @param ObjectManagerInterface $objectManager + * @param ChainFactory $chainFactory + * @param ScopeConfigInterface $scopeConfig + */ + public function __construct( + ObjectManagerInterface $objectManager, + ChainFactory $chainFactory, + ScopeConfigInterface $scopeConfig + ) { + $this->_objectManager = $objectManager; + $this->chainFactory = $chainFactory; + $this->scopeConfig = $scopeConfig; + } + + /** + * Creates chain of pre-processors + * + * @return Chain + */ + public function create(array $arguments = []) + { + if (WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) { + return $this->_objectManager->create( + 'Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChain', + $arguments + ); + } + return $this->chainFactory->create($arguments); + } +} diff --git a/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php b/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php index dfaa0d3d0b059f079165fcd9e7d60b578b5ff599..59e3441a782e30214138e7bcc872c02e737961f3 100644 --- a/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php +++ b/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php @@ -18,13 +18,14 @@ class Renderer extends Config\Renderer private $assetRepo; /** - * @param \Magento\Framework\View\Page\Config $pageConfig + * @param Config $pageConfig * @param \Magento\Framework\View\Asset\MinifyService $assetMinifyService * @param \Magento\Framework\View\Asset\MergeService $assetMergeService * @param \Magento\Framework\UrlInterface $urlBuilder * @param \Magento\Framework\Escaper $escaper * @param \Magento\Framework\Stdlib\String $string * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\View\Asset\Repository $assetRepo */ public function __construct( Config $pageConfig, @@ -56,21 +57,19 @@ class Renderer extends Config\Renderer */ protected function addDefaultAttributes($contentType, $attributes) { - switch ($contentType) { - case 'js': - $attributes = ' type="text/javascript" ' . $attributes; - break; + $taggedAttributes = parent::addDefaultAttributes($contentType, $attributes); - case 'css': - $attributes = ' rel="stylesheet" type="text/css" ' . ($attributes ?: ' media="all"'); - break; + if ($taggedAttributes !== $attributes) { + return $taggedAttributes; + } + switch ($contentType) { case 'less': - $attributes = ' rel="stylesheet/less" type="text/css" ' . ($attributes ?: ' media="all"'); + $taggedAttributes = ' rel="stylesheet/less" type="text/css" ' . ($attributes ?: ' media="all"'); break; } - return $attributes; + return $taggedAttributes; } /** diff --git a/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php b/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php index 7eaa10a25971c35648872d8e5586110d9cadabde..add6c6202d1a00939e759432b5f4f41938bff066 100644 --- a/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php +++ b/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php @@ -58,12 +58,11 @@ class RendererFactory extends \Magento\Framework\View\Page\Config\RendererFactor * * @return \Magento\Framework\View\Page\Config\RendererInterface */ - public function create(array $data =[]) + public function create(array $data = []) { + $renderer = $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH, ScopeInterface::SCOPE_STORE); return $this->objectManager->create( - $this->rendererTypes[ - $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH, ScopeInterface::SCOPE_STORE) - ], + $renderer, $data ); } diff --git a/app/code/Magento/Developer/Test/Unit/Model/VIew/Asset/PreProcessor/DeveloperChainTest.php b/app/code/Magento/Developer/Test/Unit/Model/VIew/Asset/PreProcessor/DeveloperChainTest.php new file mode 100644 index 0000000000000000000000000000000000000000..dd4676153dedb819ca9c41312c10df61e93c31e6 --- /dev/null +++ b/app/code/Magento/Developer/Test/Unit/Model/VIew/Asset/PreProcessor/DeveloperChainTest.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Asset\PreProcessor; + +use Magento\Framework\View\Asset\LocalInterface; + +class DeveloperChainTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var LocalInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $asset; + + /** + * @var DeveloperChain + */ + private $object; + + protected function setUp() + { + $this->asset = $this->getMockForAbstractClass('\Magento\Framework\View\Asset\LocalInterface'); + } + + public function testChainTargetAssetPathDevMode() + { + $assetPath = 'assetPath'; + $origPath = 'origPath'; + + $this->asset = $this->getMockForAbstractClass('\Magento\Framework\View\Asset\LocalInterface'); + $this->asset->expects($this->once()) + ->method('getContentType') + ->will($this->returnValue('assetType')); + $this->asset->expects($this->once()) + ->method('getPath') + ->will($this->returnValue($assetPath)); + $this->object = new DeveloperChain( + $this->asset, + 'origContent', + 'origType', + $origPath + ); + + $this->assertSame($this->object->getTargetAssetPath(), $origPath); + $this->assertNotSame($this->object->getTargetAssetPath(), $assetPath); + } +} diff --git a/app/code/Magento/Developer/etc/config.xml b/app/code/Magento/Developer/etc/config.xml index 59bed67e2560fef1e376274934b4a9ed97580e89..c57832ea23ed5afba771bf70366c0703dd15c37a 100644 --- a/app/code/Magento/Developer/etc/config.xml +++ b/app/code/Magento/Developer/etc/config.xml @@ -12,7 +12,7 @@ <allow_ips /> </restrict> <front_end_development_workflow> - <type>client_side_compilation</type> + <type>server_side_compilation</type> </front_end_development_workflow> </dev> </default> diff --git a/app/code/Magento/Developer/etc/di.xml b/app/code/Magento/Developer/etc/di.xml index 1f4d822d02d0e1b94bfd20fcc6ed297f49d491fc..12c274970986224b6eae4d77aab342151c9d5dcc 100644 --- a/app/code/Magento/Developer/etc/di.xml +++ b/app/code/Magento/Developer/etc/di.xml @@ -6,6 +6,7 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> + <preference for="Magento\Framework\View\Asset\PreProcessor\ChainFactory" type="Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChainFactory"/> <type name="Magento\Framework\View\TemplateEngineFactory"> <plugin name="debug_hints" type="Magento\Developer\Model\TemplateEngine\Plugin\DebugHints" sortOrder="10"/> </type> diff --git a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php index 3d17e50c364b830c0d52bc9ed731ea7008a0105a..daabe33c89d2ea84007e0ad5a880ce3d0d614285 100644 --- a/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php +++ b/dev/tools/Magento/Tools/Webdev/App/FileAssembler.php @@ -88,6 +88,8 @@ class FileAssembler implements AppInterface * @param \Magento\Framework\View\Asset\SourceFileGeneratorPool $sourceFileGeneratorPoll * @param \Magento\Tools\View\Deployer\Log $logger * @param ChainFactory $chainFactory + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( ObjectManagerInterface $objectManager, diff --git a/dev/tools/Magento/Tools/Webdev/file_assembler.php b/dev/tools/Magento/Tools/Webdev/file_assembler.php index 9a962696032317ea5ae89ab830c0ab0340e5c29e..72ec5b0458fdf12637221079aca0457872a60bb4 100644 --- a/dev/tools/Magento/Tools/Webdev/file_assembler.php +++ b/dev/tools/Magento/Tools/Webdev/file_assembler.php @@ -16,7 +16,8 @@ try { 'locale=s' => 'locale, default: en_US', 'area=s' => 'area, one of (frontend|adminhtml|doc), default: frontend', 'theme=s' => 'theme in format Vendor/theme, default: Magento/blank', - 'files=s' => 'files to pre-process (accept more than one file type as comma-separate values), default: css/styles-m', + 'files=s' => 'files to pre-process (accept more than one file type as comma-separate values),' + . ' default: css/styles-m', 'ext=s' => 'dynamic stylesheet language: less|sass', 'verbose|v' => 'provide extra output', 'help|h' => 'show help', diff --git a/lib/internal/Magento/Framework/App/Test/Unit/FactoryStub.php b/lib/internal/Magento/Framework/App/Test/Unit/FactoryStub.php deleted file mode 100644 index bc5d81c1b07354ec108fe8f2def950e07c3ab365..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/FactoryStub.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\App\Test\Unit; - -/** - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ -class FactoryStub implements \Magento\Framework\ObjectManager\FactoryInterface -{ - /** - * @param \Magento\Framework\ObjectManager\ConfigInterface $config - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Framework\ObjectManager\DefinitionInterface $definitions - * @param array $globalArguments - * @throws \BadMethodCallException - */ - public function __construct($config, $objectManager = null, $definitions = null, $globalArguments = []) - { - throw new \BadMethodCallException(__METHOD__); - } - - /** - * Create instance with call time arguments - * - * @param string $requestedType - * @param array $arguments - * @return object - * @throws \BadMethodCallException - */ - public function create($requestedType, array $arguments = []) - { - throw new \BadMethodCallException(__METHOD__); - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTest.php index 618c51fddfe612635b52721fbc4a6482a35a5373..bc3cc380ffbb85a70f509d203975ad03bb068d82 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\App\ObjectManager\Environment; +use Magento\Framework\App\Test\Unit\ObjectManager\Environment\CompiledTesting; + class CompiledTest extends \PHPUnit_Framework_TestCase { /** @@ -15,7 +17,7 @@ class CompiledTest extends \PHPUnit_Framework_TestCase protected function setUp() { $envFactoryMock = $this->getMock('Magento\Framework\App\EnvironmentFactory', [], [], '', false); - $this->_compiled = new \Magento\Framework\App\ObjectManager\Environment\CompiledTesting($envFactoryMock); + $this->_compiled = new CompiledTesting($envFactoryMock); } public function testGetMode() diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTesting.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTesting.php index 0a2fc3de5c056ec84bcfac6c488754950b2d502a..4c9471b23c40610b3b168cf7c97f0fdfb781c3aa 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTesting.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/CompiledTesting.php @@ -4,9 +4,9 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\App\ObjectManager\Environment; +namespace Magento\Framework\App\Test\Unit\ObjectManager\Environment; -require 'ConfigTesting.php'; +use Magento\Framework\App\ObjectManager\Environment\Compiled; class CompiledTesting extends Compiled { diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/ConfigTesting.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/ConfigTesting.php index 4eb2e737cd6e31fb72f33a7fb8e9e067ce7ec325..abe2a86ec9b629c33af95ab76eb12992d061841b 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/ConfigTesting.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/Environment/ConfigTesting.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\App\ObjectManager\Environment; +namespace Magento\Framework\App\Test\Unit\ObjectManager\Environment; use Magento\Framework\Interception\ObjectManager\ConfigInterface; use Magento\Framework\ObjectManager\ConfigCacheInterface; diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/FactoryStub.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/FactoryStub.php index 41e77424f1ac82bd23c192a676052e597e8146ab..8f5bda81538ca62dc2e4974da54c450d6e0f7ea6 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/FactoryStub.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/FactoryStub.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\App; +namespace Magento\Framework\App\Test\Unit\ObjectManager; use Magento\Framework\ObjectManagerInterface; diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManagerFactoryTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManagerFactoryTest.php index 243f95be8544483bf940e33d740f9e6cf2a514d6..cf75953d4e19b00374317c73c5001089858a1b0f 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManagerFactoryTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManagerFactoryTest.php @@ -41,7 +41,7 @@ class ObjectManagerFactoryTest extends \PHPUnit_Framework_TestCase /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Magento\Framework\App\Test\Unit\FactoryStub::__construct + * @expectedExceptionMessage Magento\Framework\App\Test\Unit\ObjectManager\FactoryStub::__construct */ public function testCreateObjectManagerFactoryCouldBeOverridden() { diff --git a/lib/internal/Magento/Framework/App/Test/Unit/_files/app/etc/di.xml b/lib/internal/Magento/Framework/App/Test/Unit/_files/app/etc/di.xml index 4da988c58c28c8e9a1a9a2237d6401866a637108..77c37c59d030ad76e782509acbef89a2cd2a1ab3 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/_files/app/etc/di.xml +++ b/lib/internal/Magento/Framework/App/Test/Unit/_files/app/etc/di.xml @@ -6,5 +6,5 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> - <preference for="Magento\Framework\ObjectManager\Factory\Dynamic\Developer" type="Magento\Framework\App\Test\Unit\FactoryStub" /> + <preference for="Magento\Framework\ObjectManager\Factory\Dynamic\Developer" type="Magento\Framework\App\Test\Unit\ObjectManager\FactoryStub" /> </config> diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Chain.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Chain.php index 756c8475e0956a745a2d653f97984dbeb447dc2d..0735e5e9915cd83e71015b6dddf8f1444a5af241 100644 --- a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Chain.php +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Chain.php @@ -6,7 +6,7 @@ namespace Magento\Framework\View\Asset\PreProcessor; -use Magento\Developer\Model\Config\Source\WorkflowType; +use Magento\Framework\View\Asset\LocalInterface; /** * An object that's passed to preprocessors to carry current and original information for processing @@ -15,7 +15,7 @@ use Magento\Developer\Model\Config\Source\WorkflowType; class Chain { /** - * @var \Magento\Framework\View\Asset\LocalInterface + * @var LocalInterface */ private $asset; @@ -27,7 +27,7 @@ class Chain /** * @var string */ - private $origContentType; + protected $origContentType; /** * @var string @@ -42,26 +42,24 @@ class Chain /** * @var string */ - private $targetContentType; + protected $targetContentType; /** * @var null|string */ - private $targetAssetPath; + protected $targetAssetPath; /** - * @param \Magento\Framework\View\Asset\LocalInterface $asset + * @param LocalInterface $asset * @param string $origContent * @param string $origContentType * @param null $origAssetPath - * @param null $frontEndDevelopmentWorkflowType */ public function __construct( - \Magento\Framework\View\Asset\LocalInterface $asset, + LocalInterface $asset, $origContent, $origContentType, - $origAssetPath = null, - $frontEndDevelopmentWorkflowType = null + $origAssetPath = null ) { $this->asset = $asset; $this->origContent = $origContent; @@ -70,18 +68,12 @@ class Chain $this->contentType = $origContentType; $this->targetContentType = $asset->getContentType(); $this->targetAssetPath = $asset->getPath(); - - // todo will be fixed in MAGETWO-33631 - if (WorkflowType::CLIENT_SIDE_COMPILATION == $frontEndDevelopmentWorkflowType) { - $this->targetContentType = $this->origContentType; - $this->targetAssetPath = $origAssetPath; - } } /** * Get asset object * - * @return \Magento\Framework\View\Asset\LocalInterface + * @return LocalInterface */ public function getAsset() { diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactory.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..47c97497bed2f7ff687ea1930631399881082f05 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactory.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor; + +use Magento\Framework\ObjectManagerInterface; + +class ChainFactory implements ChainFactoryInterface +{ + /** + * Object manager + * + * @var ObjectManagerInterface + */ + private $_objectManager; + + /** + * @param ObjectManagerInterface $objectManager + */ + public function __construct( + ObjectManagerInterface $objectManager + ) { + $this->_objectManager = $objectManager; + } + + /** + * Creates chain of pre-processors + * + * @return Chain + */ + public function create(array $arguments = []) + { + return $this->_objectManager->create('Magento\Framework\View\Asset\PreProcessor\Chain', $arguments); + } +} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactoryInterface.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactoryInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..c094ee574d1259db97bf4d5c1bab306ea53c09f3 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactoryInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor; + +interface ChainFactoryInterface +{ + /** + * Creates chain of pre-processors + * + * @return Chain + */ + public function create(array $arguments = []); +} diff --git a/lib/internal/Magento/Framework/View/Asset/Source.php b/lib/internal/Magento/Framework/View/Asset/Source.php index 8ebaeb7ff0d931f786699fac2831abf0df2516b8..8158572c82339ee62494f376b6752ee4f89358fd 100644 --- a/lib/internal/Magento/Framework/View/Asset/Source.php +++ b/lib/internal/Magento/Framework/View/Asset/Source.php @@ -6,8 +6,8 @@ namespace Magento\Framework\View\Asset; -use Magento\Developer\Model\Config\Source\WorkflowType; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\View\Asset\PreProcessor\ChainFactory; use Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple; /** @@ -53,9 +53,9 @@ class Source private $themeList; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ChainFactory */ - protected $scopeConfig; + private $chainFactory; /** * @param PreProcessor\Cache $cache @@ -63,7 +63,7 @@ class Source * @param PreProcessor\Pool $preProcessorPool * @param \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $fallback * @param \Magento\Framework\View\Design\Theme\ListInterface $themeList - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param ChainFactory $chainFactory */ public function __construct( PreProcessor\Cache $cache, @@ -71,7 +71,7 @@ class Source PreProcessor\Pool $preProcessorPool, \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $fallback, \Magento\Framework\View\Design\Theme\ListInterface $themeList, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + ChainFactory $chainFactory ) { $this->cache = $cache; $this->filesystem = $filesystem; @@ -80,7 +80,7 @@ class Source $this->preProcessorPool = $preProcessorPool; $this->fallback = $fallback; $this->themeList = $themeList; - $this->scopeConfig = $scopeConfig; + $this->chainFactory = $chainFactory; } /** @@ -140,13 +140,15 @@ class Source if ($cached) { return unserialize($cached); } - $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain( - $asset, - $this->rootDir->readFile($path), - $this->getContentType($path), - $path, - $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH) + $chain = $this->chainFactory->create( + [ + 'asset' => $asset, + 'origContent' => $this->rootDir->readFile($path), + 'origContentType' => $this->getContentType($path), + 'origAssetPath' => $path + ] ); + $this->preProcessorPool->process($chain); $chain->assertValid(); if ($chain->isChanged()) { diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ChainTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ChainTest.php index 32751b45c77d6b6df6aa6e70abadcabfbff379c6..ca2ad5bc4b97abf5b4be235fa0853ad105cfe4ba 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ChainTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/ChainTest.php @@ -6,8 +6,6 @@ namespace Magento\Framework\View\Asset\PreProcessor; -use Magento\Developer\Model\Config\Source\WorkflowType; - /** * Class ChainTest * @@ -103,33 +101,9 @@ class ChainTest extends \PHPUnit_Framework_TestCase $this->asset->expects($this->once()) ->method('getPath') ->will($this->returnValue($assetPath)); - $this->object = new Chain($this->asset, 'origContent', 'origType', $origPath); - - $this->assertSame($this->object->getTargetAssetPath(), $assetPath); - $this->assertNotSame($this->object->getTargetAssetPath(), $origPath); - } - - public function testChainTargetAssetPathDevMode() - { - $assetPath = 'assetPath'; - $origPath = 'origPath'; - - $this->asset = $this->getMockForAbstractClass('\Magento\Framework\View\Asset\LocalInterface'); - $this->asset->expects($this->once()) - ->method('getContentType') - ->will($this->returnValue('assetType')); - $this->asset->expects($this->once()) - ->method('getPath') - ->will($this->returnValue($assetPath)); - $this->object = new Chain( - $this->asset, - 'origContent', - 'origType', - $origPath, - WorkflowType::CLIENT_SIDE_COMPILATION - ); + $chain = new Chain($this->asset, 'origContent', 'origType', $origPath); - $this->assertSame($this->object->getTargetAssetPath(), $origPath); - $this->assertNotSame($this->object->getTargetAssetPath(), $assetPath); + $this->assertSame($chain->getTargetAssetPath(), $assetPath); + $this->assertNotSame($chain->getTargetAssetPath(), $origPath); } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/SourceTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/SourceTest.php index 31e2596ad5d9607fbf73929ee3c3cb21e8704852..cd102c0503e22dd0fb91d3694f34bdcc300b9435 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/SourceTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/SourceTest.php @@ -10,6 +10,8 @@ namespace Magento\Framework\View\Asset; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; +use Magento\Framework\View\Asset\PreProcessor\ChainFactory; +use Magento\Framework\View\Asset\PreProcessor\Chain; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -61,6 +63,16 @@ class SourceTest extends \PHPUnit_Framework_TestCase */ private $object; + /** + * @var ChainFactory | \PHPUnit_Framework_MockObject_MockObject + */ + private $chainFactory; + + /** + * @var Chain | \PHPUnit_Framework_MockObject_MockObject + */ + private $chain; + protected function setUp() { $this->cache = $this->getMock( @@ -74,7 +86,18 @@ class SourceTest extends \PHPUnit_Framework_TestCase ); $this->theme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); /** @var \Magento\Framework\App\Config\ScopeConfigInterface $config */ - $config = $this->getMockForAbstractClass('Magento\Framework\App\Config\ScopeConfigInterface'); + + $this->chainFactory = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\ChainFactory') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->chain = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Chain') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->chainFactory->expects($this->any()) + ->method('create') + ->willReturn($this->chain); $themeList = $this->getMockForAbstractClass('Magento\Framework\View\Design\Theme\ListInterface'); $themeList->expects($this->any()) @@ -90,7 +113,7 @@ class SourceTest extends \PHPUnit_Framework_TestCase $this->preProcessorPool, $this->viewFileResolution, $themeList, - $config + $this->chainFactory ); } @@ -137,11 +160,11 @@ class SourceTest extends \PHPUnit_Framework_TestCase } /** - * @param string $origFile - * @param string $origPath - * @param string $origContentType - * @param string $origContent - * @param string $isMaterialization + * @param $origFile + * @param $origPath + * @param $origContent + * @param $isMaterialization + * * @dataProvider getFileDataProvider */ public function testGetFile($origFile, $origPath, $origContent, $isMaterialization) @@ -165,8 +188,20 @@ class SourceTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($origContent)); $this->preProcessorPool->expects($this->once()) ->method('process') - ->will($this->returnCallback([$this, 'chainTestCallback'])); + ->with($this->chain); if ($isMaterialization) { + $this->chain + ->expects($this->once()) + ->method('isChanged') + ->willReturn(true); + $this->chain + ->expects($this->once()) + ->method('getContent') + ->willReturn('processed'); + $this->chain + ->expects($this->once()) + ->method('getTargetAssetPath') + ->willReturn($filePath); $this->varDir->expects($this->once()) ->method('writeFile') ->with('view_preprocessed/source/some/file.ext', 'processed'); @@ -217,9 +252,9 @@ class SourceTest extends \PHPUnit_Framework_TestCase /** * A callback for affecting preprocessor chain in the test * - * @param \Magento\Framework\View\Asset\PreProcessor\Chain $chain + * @param Chain $chain */ - public function chainTestCallback(\Magento\Framework\View\Asset\PreProcessor\Chain $chain) + public function chainTestCallback(Chain $chain) { $chain->setContentType('ext'); $chain->setContent('processed'); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php index 9b6a159df46211334cee6479f1f35fdea4d8f8bf..773742f2eea28c5b5fba0507dde6802d0cf3d216 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php @@ -7,7 +7,6 @@ namespace Magento\Framework\View\Page\Config; use Magento\Framework\View\Asset\GroupedCollection; -use Magento\TestFramework\Helper\ObjectManager as ObjectManagerHelper; /** * Test for page config renderer model @@ -117,7 +116,7 @@ class RendererTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);; $this->renderer = $this->objectManagerHelper->getObject( 'Magento\Framework\View\Page\Config\Renderer', [