From 3b38352cf6807b5e4e76061541c98d5124bd0ee1 Mon Sep 17 00:00:00 2001
From: Dmytro Kvashnin <dkvashnin@ebay.com>
Date: Mon, 16 Mar 2015 13:28:20 +0200
Subject: [PATCH] MAGETWO-33631: Advanced Developer Workflow

- less compilation workflow placed to Developer module
- fixed unit tests
- fixed static code defects
---
 .../Asset/PreProcessor/DeveloperChain.php     | 39 +++++++++++
 .../PreProcessor/DeveloperChainFactory.php    | 64 +++++++++++++++++++
 .../ClientSideLessCompilation/Renderer.php    | 19 +++---
 .../View/Page/Config/RendererFactory.php      |  7 +-
 .../Asset/PreProcessor/DeveloperChainTest.php | 49 ++++++++++++++
 app/code/Magento/Developer/etc/config.xml     |  2 +-
 app/code/Magento/Developer/etc/di.xml         |  1 +
 .../Tools/Webdev/App/FileAssembler.php        |  2 +
 .../Magento/Tools/Webdev/file_assembler.php   |  3 +-
 .../Framework/App/Test/Unit/FactoryStub.php   | 37 -----------
 .../Environment/CompiledTest.php              |  4 +-
 .../Environment/CompiledTesting.php           |  4 +-
 .../Environment/ConfigTesting.php             |  2 +-
 .../Test/Unit/ObjectManager/FactoryStub.php   |  2 +-
 .../Test/Unit/ObjectManagerFactoryTest.php    |  2 +-
 .../App/Test/Unit/_files/app/etc/di.xml       |  2 +-
 .../View/Asset/PreProcessor/Chain.php         | 26 +++-----
 .../View/Asset/PreProcessor/ChainFactory.php  | 37 +++++++++++
 .../PreProcessor/ChainFactoryInterface.php    | 16 +++++
 .../Magento/Framework/View/Asset/Source.php   | 26 ++++----
 .../Unit/Asset/PreProcessor/ChainTest.php     | 32 +---------
 .../View/Test/Unit/Asset/SourceTest.php       | 55 +++++++++++++---
 .../Test/Unit/Page/Config/RendererTest.php    |  3 +-
 23 files changed, 304 insertions(+), 130 deletions(-)
 create mode 100644 app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChain.php
 create mode 100644 app/code/Magento/Developer/Model/View/Asset/PreProcessor/DeveloperChainFactory.php
 create mode 100644 app/code/Magento/Developer/Test/Unit/Model/VIew/Asset/PreProcessor/DeveloperChainTest.php
 delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/FactoryStub.php
 create mode 100644 lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactory.php
 create mode 100644 lib/internal/Magento/Framework/View/Asset/PreProcessor/ChainFactoryInterface.php

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 00000000000..80436bcd9ef
--- /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 00000000000..db849f8b825
--- /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 dfaa0d3d0b0..59e3441a782 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 7eaa10a2597..add6c6202d1 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 00000000000..dd4676153de
--- /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 59bed67e256..c57832ea23e 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 1f4d822d02d..12c27497098 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 3d17e50c364..daabe33c89d 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 9a962696032..72ec5b0458f 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 bc5d81c1b07..00000000000
--- 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 618c51fddfe..bc3cc380ffb 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 0a2fc3de5c0..4c9471b23c4 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 4eb2e737cd6..abe2a86ec9b 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 41e77424f1a..8f5bda81538 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 243f95be854..cf75953d4e1 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 4da988c58c2..77c37c59d03 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 756c8475e09..0735e5e9915 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 00000000000..47c97497bed
--- /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 00000000000..c094ee574d1
--- /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 8ebaeb7ff0d..8158572c823 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 32751b45c77..ca2ad5bc4b9 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 31e2596ad5d..cd102c0503e 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 9b6a159df46..773742f2eea 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',
             [
-- 
GitLab