Skip to content

Commit e6c60d1

Browse files
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-53094' into MAGETWO-55668
2 parents a06481c + 9ce4ea8 commit e6c60d1

File tree

6 files changed

+265
-78
lines changed

6 files changed

+265
-78
lines changed

app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Developer\Model\Css\PreProcessor\FileGenerator;
77

8+
use Magento\Framework\App\DeploymentConfig;
9+
use Magento\Framework\App\State;
10+
use Magento\Framework\App\ObjectManager;
811
use Magento\Framework\Filesystem;
912
use Magento\Framework\View\Asset\Repository;
1013
use Magento\Framework\App\View\Asset\Publisher;
@@ -36,6 +39,11 @@ class PublicationDecorator extends RelatedGenerator
3639
*/
3740
private $hasRelatedPublishing;
3841

42+
/**
43+
* @var State
44+
*/
45+
private $state;
46+
3947
/**
4048
* Constructor
4149
*
@@ -66,12 +74,27 @@ public function __construct(
6674
protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
6775
{
6876
$relatedAsset = parent::generateRelatedFile($relatedFileId, $asset);
69-
if ($this->hasRelatedPublishing
70-
|| WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)
71-
) {
77+
$isClientSideCompilation =
78+
$this->getState()->getMode() !== State::MODE_PRODUCTION
79+
&& WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH);
80+
81+
if ($this->hasRelatedPublishing || $isClientSideCompilation) {
7282
$this->assetPublisher->publish($relatedAsset);
7383
}
7484

7585
return $relatedAsset;
7686
}
87+
88+
/**
89+
* @return State
90+
* @deprecated
91+
*/
92+
private function getState()
93+
{
94+
if (null === $this->state) {
95+
$this->state = ObjectManager::getInstance()->get(State::class);
96+
}
97+
98+
return $this->state;
99+
}
77100
}

app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Developer\Model\View\Asset\PreProcessor;
77

8+
use Magento\Framework\App\DeploymentConfig;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\App\State;
811
use Magento\Framework\View\Asset\PreProcessor;
912
use Magento\Framework\App\Config\ScopeConfigInterface;
1013
use Magento\Developer\Model\Config\Source\WorkflowType;
@@ -31,6 +34,11 @@ class PreprocessorStrategy implements PreProcessorInterface
3134
*/
3235
private $scopeConfig;
3336

37+
/**
38+
* @var State
39+
*/
40+
private $state;
41+
3442
/**
3543
* Constructor
3644
*
@@ -56,10 +64,26 @@ public function __construct(
5664
*/
5765
public function process(PreProcessor\Chain $chain)
5866
{
59-
if (WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) {
67+
$isClientSideCompilation =
68+
$this->getState()->getMode() !== State::MODE_PRODUCTION
69+
&& WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH);
70+
71+
if ($isClientSideCompilation) {
6072
$this->frontendCompilation->process($chain);
6173
} else {
6274
$this->alternativeSource->process($chain);
6375
}
6476
}
77+
78+
/**
79+
* @return State
80+
* @deprecated
81+
*/
82+
private function getState()
83+
{
84+
if (null === $this->state) {
85+
$this->state = ObjectManager::getInstance()->get(State::class);
86+
}
87+
return $this->state;
88+
}
6589
}

app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Developer\Model\View\Page\Config;
77

88
use Magento\Developer\Model\Config\Source\WorkflowType;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\App\State;
911
use Magento\Store\Model\ScopeInterface;
1012

1113
/**
@@ -58,7 +60,9 @@ public function __construct(
5860
*/
5961
public function create(array $data = [])
6062
{
61-
$renderer = $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH, ScopeInterface::SCOPE_STORE);
63+
$renderer = $this->objectManager->get(State::class)->getMode() === State::MODE_PRODUCTION ?
64+
WorkflowType::SERVER_SIDE_COMPILATION :
65+
$this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH, ScopeInterface::SCOPE_STORE);
6266

6367
return $this->objectManager->create(
6468
$this->rendererTypes[$renderer],

app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php

Lines changed: 93 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,131 @@
55
*/
66
namespace Magento\Developer\Test\Unit\Model\Css\PreProcessor\FileGenerator;
77

8+
use Magento\Framework\App\State;
9+
use Magento\Framework\App\View\Asset\Publisher;
10+
use Magento\Framework\Css\PreProcessor\Instruction\Import;
811
use Magento\Framework\Filesystem;
912
use Magento\Framework\App\Config\ScopeConfigInterface;
1013
use Magento\Framework\Css\PreProcessor\File\Temporary;
1114
use Magento\Developer\Model\Css\PreProcessor\FileGenerator\PublicationDecorator;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16+
use Magento\Framework\View\Asset\File;
17+
use Magento\Framework\View\Asset\LocalInterface;
18+
use Magento\Framework\View\Asset\Repository;
1219

1320
/**
14-
* Class PublicationDecoratorTest
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1522
*/
1623
class PublicationDecoratorTest extends \PHPUnit_Framework_TestCase
1724
{
1825
/**
19-
* Calls generate method to access protected method generateRelatedFile
26+
* @var PublicationDecorator
2027
*/
21-
public function testGenerateRelatedFile()
28+
private $model;
29+
30+
/**
31+
* @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $filesystemMock;
34+
35+
/**
36+
* @var Temporary|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $temporaryFileMock;
39+
40+
/**
41+
* @var Publisher|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $publisherMock;
44+
45+
/**
46+
* @var Repository|\PHPUnit_Framework_MockObject_MockObject
47+
*/
48+
private $assetRepositoryMock;
49+
50+
/**
51+
* @var File|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $relatedAssetMock;
54+
55+
/**
56+
* @var Import|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $importGeneratorMock;
59+
60+
/**
61+
* @var LocalInterface|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $localAssetMock;
64+
65+
/**
66+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
67+
*/
68+
private $scopeConfigMock;
69+
70+
/**
71+
* @var State|\PHPUnit_Framework_MockObject_MockObject
72+
*/
73+
private $stateMock;
74+
75+
protected function setUp()
2276
{
23-
$filesystemMock = $this->getMockBuilder(Filesystem::class)
77+
$this->filesystemMock = $this->getMockBuilder(Filesystem::class)
2478
->disableOriginalConstructor()
2579
->getMock();
26-
$fileTemporaryMock = $this->getMockBuilder(Temporary::class)
80+
$this->temporaryFileMock = $this->getMockBuilder(Temporary::class)
2781
->disableOriginalConstructor()
2882
->getMock();
29-
30-
$publisherMock = $this->getMockBuilder(\Magento\Framework\App\View\Asset\Publisher::class)
83+
$this->publisherMock = $this->getMockBuilder(Publisher::class)
3184
->disableOriginalConstructor()
3285
->getMock();
33-
$assetRepoMock = $this->getMockBuilder(\Magento\Framework\View\Asset\Repository::class)
86+
$this->assetRepositoryMock = $this->getMockBuilder(Repository::class)
3487
->disableOriginalConstructor()
3588
->getMock();
36-
$relatedAssetMock = $this->getMockBuilder(\Magento\Framework\View\Asset\File::class)
89+
$this->relatedAssetMock = $this->getMockBuilder(File::class)
3790
->disableOriginalConstructor()
3891
->getMock();
39-
$importGeneratorMock = $this->getMockBuilder(\Magento\Framework\Css\PreProcessor\Instruction\Import::class)
92+
$this->importGeneratorMock = $this->getMockBuilder(Import::class)
4093
->disableOriginalConstructor()
4194
->getMock();
42-
$localAssetMock = $this->getMockBuilder(\Magento\Framework\View\Asset\LocalInterface::class)
95+
$this->localAssetMock = $this->getMockBuilder(LocalInterface::class)
4396
->disableOriginalConstructor()
4497
->getMock();
45-
$scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
98+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
4699
->getMockForAbstractClass();
100+
$this->stateMock = $this->getMockBuilder(State::class)
101+
->disableOriginalConstructor()
102+
->getMock();
47103

48-
$relatedFileId = 'file_id';
104+
$this->model = (new ObjectManager($this))->getObject(PublicationDecorator::class, [
105+
'filesystem' => $this->filesystemMock,
106+
'assetRepository' => $this->assetRepositoryMock,
107+
'temporaryFile' => $this->temporaryFileMock,
108+
'assetPublisher' => $this->publisherMock,
109+
'scopeConfig' => $this->scopeConfigMock,
110+
'state' => $this->stateMock,
111+
'hasRelatedPublishing' => true
112+
]);
113+
}
49114

50-
$relatedFiles = [[$relatedFileId, $localAssetMock]];
115+
/**
116+
* Calls generate method to access protected method generateRelatedFile
117+
*/
118+
public function testGenerateRelatedFile()
119+
{
120+
$relatedFileId = 'file_id';
121+
$relatedFiles = [[$relatedFileId, $this->localAssetMock]];
51122

52-
$importGeneratorMock->expects(self::any())
123+
$this->importGeneratorMock->expects($this->any())
53124
->method('getRelatedFiles')
54-
->will(self::onConsecutiveCalls($relatedFiles, []));
55-
56-
$assetRepoMock->expects(self::any())
125+
->willReturnOnConsecutiveCalls($relatedFiles, []);
126+
$this->assetRepositoryMock->expects($this->any())
57127
->method('createRelated')
58-
->willReturn($relatedAssetMock);
59-
60-
$publisherMock->expects(self::once())
128+
->willReturn($this->relatedAssetMock);
129+
$this->publisherMock->expects($this->once())
61130
->method('publish')
62-
->with($relatedAssetMock);
63-
64-
$model = new PublicationDecorator(
65-
$filesystemMock,
66-
$assetRepoMock,
67-
$fileTemporaryMock,
68-
$publisherMock,
69-
$scopeConfigMock,
70-
true
71-
);
72-
73-
$model->generate($importGeneratorMock);
131+
->with($this->relatedAssetMock);
132+
133+
$this->model->generate($this->importGeneratorMock);
74134
}
75135
}

0 commit comments

Comments
 (0)