Skip to content

Commit 73b2b8f

Browse files
author
Pavlo Cherniavskyi
committed
Merge branch 'MAGETWO-21072' into MAGETWO-33622
2 parents f05e6ab + f77fc45 commit 73b2b8f

File tree

17 files changed

+611
-42
lines changed

17 files changed

+611
-42
lines changed

app/etc/di.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,26 @@
540540
<argument name="stateCollection" xsi:type="object" shared="false">Magento\Framework\Mview\View\State\CollectionInterface</argument>
541541
</arguments>
542542
</type>
543+
<type name="Magento\Framework\App\View\Asset\Publisher" shared="false" />
543544
<type name="Magento\Framework\App\StaticResource">
544545
<arguments>
545546
<argument name="response" xsi:type="object" shared="false">Magento\Core\Model\File\Storage\Response</argument>
547+
<argument name="publisher" xsi:type="object">developerPublisher</argument>
546548
</arguments>
547549
</type>
550+
<virtualType name="developerPublisher" type="Magento\Framework\App\View\Asset\Publisher">
551+
<arguments>
552+
<argument name="materializationStrategyFactory" xsi:type="object">developerMaterialization</argument>
553+
</arguments>
554+
</virtualType>
555+
<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
556+
<arguments>
557+
<argument name="strategiesList" xsi:type="array">
558+
<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
559+
<item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
560+
</argument>
561+
</arguments>
562+
</virtualType>
548563
<virtualType name="fallbackResolverSimpleWithGroupedCache" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple">
549564
<arguments>
550565
<argument name="cache" xsi:type="object">Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Grouped</argument>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
8+
9+
class CopyTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var Copy
13+
*/
14+
private $copyPublisher;
15+
16+
public function setUp()
17+
{
18+
$this->copyPublisher = new Copy;
19+
}
20+
21+
public function testPublishFile()
22+
{
23+
$rootDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
24+
->getMock();
25+
$targetDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
26+
->getMock();
27+
$sourcePath = 'source/path/file';
28+
$destinationPath = 'destination/path/file';
29+
30+
$rootDir->expects($this->once())
31+
->method('copyFile')
32+
->with(
33+
$sourcePath,
34+
$destinationPath,
35+
$targetDir
36+
)->willReturn(true);
37+
38+
$this->assertTrue($this->copyPublisher->publishFile($rootDir, $targetDir, $sourcePath, $destinationPath));
39+
}
40+
41+
public function testIsSupported()
42+
{
43+
$asset = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
44+
->getMock();
45+
$this->assertTrue($this->copyPublisher->isSupported($asset));
46+
}
47+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
8+
9+
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\Framework\View\Asset;
11+
12+
class FactoryTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
private $objectManager;
18+
19+
public function setUp()
20+
{
21+
$this->objectManager = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
22+
->setMethods([])
23+
->getMock();
24+
}
25+
26+
public function testCreateEmptyStrategies()
27+
{
28+
$asset = $this->getAsset();
29+
$copyStrategy = $this->getMockBuilder('Magento\Framework\App\View\Asset\MaterializationStrategy\Copy')
30+
->setMethods([])
31+
->getMock();
32+
$copyStrategy->expects($this->once())
33+
->method('isSupported')
34+
->with($asset)
35+
->willReturn(true);
36+
37+
$this->objectManager->expects($this->once())
38+
->method('get')
39+
->with(Factory::DEFAULT_STRATEGY)
40+
->willReturn($copyStrategy);
41+
42+
$factory = new Factory($this->objectManager, []);
43+
$this->assertSame($copyStrategy, $factory->create($asset));
44+
}
45+
46+
public function testCreateSupported()
47+
{
48+
$asset = $this->getAsset();
49+
$copyStrategy = $this->getMockBuilder('Magento\Framework\App\View\Asset\MaterializationStrategy\Copy')
50+
->setMethods([])
51+
->getMock();
52+
$copyStrategy->expects($this->once())
53+
->method('isSupported')
54+
->with($asset)
55+
->willReturn(false);
56+
57+
$supportedStrategy = $this->getMockBuilder('Magento\Framework\App\View\Asset\MaterializationStrategy\StrategyInterface')
58+
->setMethods([])
59+
->getMock();
60+
$supportedStrategy->expects($this->once())
61+
->method('isSupported')
62+
->with($asset)
63+
->willReturn(true);
64+
65+
$factory = new Factory($this->objectManager, [$copyStrategy, $supportedStrategy]);
66+
$this->assertSame($supportedStrategy, $factory->create($asset));
67+
}
68+
69+
public function testCreateException()
70+
{
71+
$asset = $this->getAsset();
72+
$copyStrategy = $this->getMockBuilder('Magento\Framework\App\View\Asset\MaterializationStrategy\Copy')
73+
->setMethods([])
74+
->getMock();
75+
$copyStrategy->expects($this->once())
76+
->method('isSupported')
77+
->with($asset)
78+
->willReturn(false);
79+
80+
$this->objectManager->expects($this->once())
81+
->method('get')
82+
->with(Factory::DEFAULT_STRATEGY)
83+
->willReturn($copyStrategy);
84+
85+
$factory = new Factory($this->objectManager, []);
86+
87+
$this->setExpectedException('LogicException', __('No materialization strategy is supported'));
88+
$factory->create($asset);
89+
}
90+
91+
/**
92+
* @return Asset\LocalInterface|\PHPUnit_Framework_MockObject_MockObject
93+
*/
94+
private function getAsset()
95+
{
96+
return $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
97+
->setMethods([])
98+
->getMock();
99+
}
100+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
8+
9+
use Magento\Framework\View\Asset;
10+
11+
class SymlinkTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var Symlink
15+
*/
16+
private $symlinkPublisher;
17+
18+
public function setUp()
19+
{
20+
$this->symlinkPublisher = new Symlink;
21+
}
22+
23+
public function testPublishFile()
24+
{
25+
$rootDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
26+
->getMock();
27+
$targetDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
28+
->getMock();
29+
$sourcePath = 'source/path/file';
30+
$destinationPath = 'destination/path/file';
31+
32+
$rootDir->expects($this->once())
33+
->method('createSymlink')
34+
->with(
35+
$sourcePath,
36+
$destinationPath,
37+
$targetDir
38+
)->willReturn(true);
39+
40+
$this->assertTrue($this->symlinkPublisher->publishFile($rootDir, $targetDir, $sourcePath, $destinationPath));
41+
}
42+
43+
/**
44+
* @dataProvider sourceFileDataProvider
45+
*/
46+
public function testIsSupported($path, $expectation)
47+
{
48+
$asset = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
49+
->setMethods([])
50+
->getMock();
51+
$asset->expects($this->once())
52+
->method('getSourceFile')
53+
->willReturn($path);
54+
$this->assertEquals($expectation, $this->symlinkPublisher->isSupported($asset));
55+
}
56+
57+
/**
58+
* @return array
59+
*/
60+
public function sourceFileDataProvider()
61+
{
62+
return [
63+
['path/to/file', true],
64+
[Asset\Source::TMP_MATERIALIZATION_DIR . '/path/to/file', false]
65+
];
66+
}
67+
}

dev/tests/unit/testsuite/Magento/Framework/App/View/Asset/PublisherTest.php

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111

1212
class PublisherTest extends \PHPUnit_Framework_TestCase
1313
{
14-
/**
15-
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
16-
*/
17-
private $appState;
18-
1914
/**
2015
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
2116
*/
@@ -41,11 +36,22 @@ class PublisherTest extends \PHPUnit_Framework_TestCase
4136
*/
4237
private $object;
4338

39+
/**
40+
* @var MaterializationStrategy\Factory |\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $materializationStrategyFactory;
43+
4444
protected function setUp()
4545
{
46-
$this->appState = $this->getMock('Magento\Framework\App\State', [], [], '', false);
4746
$this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
48-
$this->object = new Publisher($this->appState, $this->filesystem);
47+
$this->materializationStrategyFactory = $this->getMock(
48+
'Magento\Framework\App\View\Asset\MaterializationStrategy\Factory',
49+
[],
50+
[],
51+
'',
52+
false
53+
);
54+
$this->object = new Publisher($this->filesystem, $this->materializationStrategyFactory);
4955

5056
$this->rootDirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface');
5157
$this->staticDirRead = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface');
@@ -62,19 +68,8 @@ protected function setUp()
6268
]));
6369
}
6470

65-
public function testPublishNotAllowed()
66-
{
67-
$this->appState->expects($this->once())
68-
->method('getMode')
69-
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
70-
$this->assertFalse($this->object->publish($this->getAsset()));
71-
}
72-
7371
public function testPublishExistsBefore()
7472
{
75-
$this->appState->expects($this->once())
76-
->method('getMode')
77-
->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
7873
$this->staticDirRead->expects($this->once())
7974
->method('isExist')
8075
->with('some/file.ext')
@@ -84,21 +79,29 @@ public function testPublishExistsBefore()
8479

8580
public function testPublish()
8681
{
87-
$this->appState->expects($this->once())
88-
->method('getMode')
89-
->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
9082
$this->staticDirRead->expects($this->once())
9183
->method('isExist')
9284
->with('some/file.ext')
9385
->will($this->returnValue(false));
86+
$materializationStrategy = $this->getMock(
87+
'Magento\Framework\App\View\Asset\MaterializationStrategy\StrategyInterface',
88+
[],
89+
[],
90+
'',
91+
false
92+
);
9493

9594
$this->rootDirWrite->expects($this->once())
9695
->method('getRelativePath')
9796
->with('/root/some/file.ext')
9897
->will($this->returnValue('some/file.ext'));
99-
$this->rootDirWrite->expects($this->once())
100-
->method('copyFile')
101-
->with('some/file.ext', 'some/file.ext', $this->staticDirWrite)
98+
$this->materializationStrategyFactory->expects($this->once())
99+
->method('create')
100+
->with($this->getAsset())
101+
->will($this->returnValue($materializationStrategy));
102+
$materializationStrategy->expects($this->once())
103+
->method('publishFile')
104+
->with($this->rootDirWrite, $this->staticDirWrite, 'some/file.ext', 'some/file.ext')
102105
->will($this->returnValue(true));
103106

104107
$this->assertTrue($this->object->publish($this->getAsset()));

0 commit comments

Comments
 (0)