1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Deploy\Test\Unit\Model\Deploy;
use Magento\Deploy\Model\Deploy\LocaleDeploy;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\App\View\Asset\Publisher;
use Magento\Framework\Translate\Js\Config;
use Magento\Framework\View\Asset\Minification;
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\View\Asset\RepositoryFactory;
use Magento\RequireJs\Model\FileManagerFactory;
use Magento\Framework\RequireJs\ConfigFactory;
use Magento\Framework\View\Asset\Bundle\Manager;
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
use Magento\Framework\View\DesignInterfaceFactory;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\View\Design\Theme\ListInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Test class which allows deploy by locales
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class LocaleDeployTest extends \PHPUnit_Framework_TestCase
{
/**
* @var string
*/
private $area;
/**
* @var string
*/
private $locale;
/**
* @var string
*/
private $themePath;
/**
* @var \Magento\Deploy\Model\Deploy\LocaleDeploy
*/
private $model;
protected function setUp()
{
$this->area = 'adminhtml';
$this->themePath = '/theme/path';
$this->locale = 'en_US';
$outputMock = $this->getMock(OutputInterface::class, [], [], '', false);
$jsTranslationMock = $this->getMock(Config::class, [], [], '', false);
$jsTranslationMock->expects($this->once())->method('dictionaryEnabled')->willReturn(false);
$minificationMock = $this->getMock(Minification::class, [], [], '', false);
$minificationMock->expects($this->once())->method('isEnabled')->with('js')->willReturn(true);
$themeMock = $this->getMockBuilder(\Magento\Framework\View\Design\ThemeInterface::class)
->disableOriginalConstructor()
->getMock();
$designMock = $this->getMock(\Magento\Framework\View\DesignInterface::class, [], [], '', false);
$designMock->expects($this->once())->method('setDesignTheme')->with($themeMock, $this->area)->willReturnSelf();
$assetRepoMock = $this->getMock(Repository::class, [], [], '', false);
$assetRepoFactoryMock = $this->getMock(RepositoryFactory::class, ['create'], [], '', false);
$assetRepoFactoryMock->expects($this->once())
->method('create')
->with(['design' => $designMock])
->willReturn($assetRepoMock);
$fileManagerMock = $this->getMock(\Magento\RequireJs\Model\FileManager::class, [], [], '', false);
$fileManagerMock->expects($this->once())->method('createRequireJsConfigAsset')->willReturnSelf();
$fileManagerMock->expects($this->once())->method('createMinResolverAsset')->willReturnSelf();
$fileManagerFactoryMock = $this->getMock(FileManagerFactory::class, ['create'], [], '', false);
$fileManagerFactoryMock->expects($this->once())->method('create')->willReturn($fileManagerMock);
$requireJsConfigMock = $this->getMock(\Magento\Framework\RequireJs\Config::class, [], [], '', false);
$configFactoryMock = $this->getMock(ConfigFactory::class, ['create'], [], '', false);
$configFactoryMock->expects($this->once())->method('create')->willReturn($requireJsConfigMock);
$assetPublisherMock = $this->getMock(Publisher::class, [], [], '', false);
$bundleManagerMock = $this->getMock(Manager::class, [], [], '', false);
$bundleManagerMock->expects($this->once())->method('flush');
$themeProviderMock = $this->getMock(ThemeProviderInterface::class, [], [], '', false);
$loggerMock = $this->getMock(LoggerInterface::class, [], [], '', false);
$filesUtilMock = $this->getMock(Files::class, [], [], '', false);
$filesUtilMock->expects($this->once())->method('getStaticPreProcessingFiles')->willReturn([]);
$filesUtilMock->expects($this->once())->method('getStaticLibraryFiles')->willReturn([]);
$designFactoryMock = $this->getMock(DesignInterfaceFactory::class, ['create'], [], '', false);
$designFactoryMock->expects($this->once())->method('create')->willReturn($designMock);
$localeResolverMock = $this->getMock(ResolverInterface::class, [], [], '', false);
$localeResolverMock->expects($this->once())->method('setLocale')->with($this->locale);
$themeList = $this->getMock(ListInterface::class, [], [], '', false);
$themeList->expects($this->once())->method('getThemeByFullPath')
->with($this->area . '/' . $this->themePath)
->willReturn($themeMock);
$this->model = new LocaleDeploy(
$outputMock,
$jsTranslationMock,
$minificationMock,
$assetRepoMock,
$assetRepoFactoryMock,
$fileManagerFactoryMock,
$configFactoryMock,
$assetPublisherMock,
$bundleManagerMock,
$themeProviderMock,
$loggerMock,
$filesUtilMock,
$designFactoryMock,
$localeResolverMock,
[],
[\Magento\Deploy\Console\Command\DeployStaticOptionsInterface::NO_JAVASCRIPT => 0]
);
$property = new \ReflectionProperty(get_class($this->model), 'themeList');
$property->setAccessible(true);
$property->setValue($this->model, $themeList);
}
public function testDeploy()
{
$this->assertEquals(
\Magento\Framework\Console\Cli::RETURN_SUCCESS,
$this->model->deploy($this->area, $this->themePath, $this->locale)
);
}
}