11
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
12
use Symfony \Component \Console \Output \OutputInterface ;
13
13
use Magento \Deploy \Console \Command \DeployStaticOptionsInterface as Options ;
14
- use \Magento \Framework \RequireJs \Config as RequireJsConfig ;
14
+ use Magento \Framework \RequireJs \Config as RequireJsConfig ;
15
+ use Magento \Translation \Model \Js \Config as TranslationJsConfig ;
16
+ use Magento \Framework \TranslateInterface ;
17
+ use Magento \Framework \View \Asset \Repository ;
18
+ use Magento \Framework \View \Asset \LocalInterface as Asset ;
19
+ use Magento \Framework \App \View \Asset \Publisher ;
15
20
16
21
class LocaleQuickDeployTest extends \PHPUnit_Framework_TestCase
17
22
{
@@ -25,15 +30,46 @@ class LocaleQuickDeployTest extends \PHPUnit_Framework_TestCase
25
30
*/
26
31
private $ staticDirectoryMock ;
27
32
33
+ /**
34
+ * @var TranslationJsConfig|\PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ private $ translationJsConfig ;
37
+
38
+ /**
39
+ * @var TranslateInterface|\PHPUnit_Framework_MockObject_MockObject
40
+ */
41
+ private $ translator ;
42
+
43
+ /**
44
+ * @var Repository|\PHPUnit_Framework_MockObject_MockObject
45
+ */
46
+ private $ assetRepo ;
47
+
48
+ /**
49
+ * @var Asset|\PHPUnit_Framework_MockObject_MockObject
50
+ */
51
+ private $ asset ;
52
+
53
+ /**
54
+ * @var Publisher|\PHPUnit_Framework_MockObject_MockObject
55
+ */
56
+ private $ assetPublisher ;
57
+
28
58
protected function setUp ()
29
59
{
30
60
$ this ->outputMock = $ this ->getMockBuilder (OutputInterface::class)
31
- ->setMethods (['writeln ' ])
61
+ ->setMethods (['writeln ' , ' isVeryVerbose ' ])
32
62
->getMockForAbstractClass ();
33
63
34
64
$ this ->staticDirectoryMock = $ this ->getMockBuilder (WriteInterface::class)
35
65
->setMethods (['createSymlink ' , 'getAbsolutePath ' , 'getRelativePath ' , 'copyFile ' , 'readRecursively ' ])
36
66
->getMockForAbstractClass ();
67
+
68
+ $ this ->translationJsConfig = $ this ->getMock (TranslationJsConfig::class, [], [], '' , false );
69
+ $ this ->translator = $ this ->getMockForAbstractClass (TranslateInterface::class, [], '' , false , false , true );
70
+ $ this ->assetRepo = $ this ->getMock (Repository::class, [], [], '' , false );
71
+ $ this ->asset = $ this ->getMockForAbstractClass (Asset::class, [], '' , false , false , true );;
72
+ $ this ->assetPublisher = $ this ->getMock (Publisher::class, [], [], '' , false );
37
73
}
38
74
39
75
/**
@@ -68,29 +104,57 @@ public function testDeployWithSymlinkStrategy()
68
104
69
105
public function testDeployWithCopyStrategy ()
70
106
{
71
-
72
107
$ area = 'adminhtml ' ;
73
108
$ themePath = 'Magento/backend ' ;
74
109
$ locale = 'uk_UA ' ;
75
- $ baseLocal = 'en_US ' ;
110
+ $ baseLocale = 'en_US ' ;
111
+ $ baseDir = $ baseLocale . 'dir ' ;
112
+ $ file1 = 'file1 ' ;
113
+ $ file2 = 'file2 ' ;
114
+ $ baseFile1 = $ baseLocale . $ file1 ;
115
+ $ baseFile2 = $ baseLocale . $ file2 ;
116
+
117
+ $ dictionary = TranslationJsConfig::DICTIONARY_FILE_NAME ;
118
+ $ baseDictionary = $ baseLocale . $ dictionary ;
119
+
76
120
77
121
$ this ->staticDirectoryMock ->expects (self ::never ())->method ('createSymlink ' );
78
- $ this ->staticDirectoryMock ->expects (self ::exactly (2 ))->method ('readRecursively ' )->willReturnMap ([
79
- ['adminhtml/Magento/backend/en_US ' , [$ baseLocal . 'file1 ' , $ baseLocal . 'dir ' ]],
80
- [RequireJsConfig::DIR_NAME . '/adminhtml/Magento/backend/en_US ' , [$ baseLocal . 'file2 ' ]]
81
- ]);
82
- $ this ->staticDirectoryMock ->expects (self ::exactly (3 ))->method ('isFile ' )->willReturnMap ([
83
- [$ baseLocal . 'file1 ' , true ],
84
- [$ baseLocal . 'dir ' , false ],
85
- [$ baseLocal . 'file2 ' , true ],
122
+ $ this ->staticDirectoryMock ->expects (self ::exactly (2 ))->method ('readRecursively ' )->willReturnMap (
123
+ [
124
+ ['adminhtml/Magento/backend/en_US ' , [$ baseFile1 , $ baseDir ]],
125
+ [RequireJsConfig::DIR_NAME . '/adminhtml/Magento/backend/en_US ' , [$ baseFile2 , $ baseDictionary ]]
126
+ ]
127
+ );
128
+ $ this ->staticDirectoryMock ->expects (self ::exactly (4 ))->method ('isFile ' )->willReturnMap ([
129
+ [$ baseFile1 , true ],
130
+ [$ baseDir , false ],
131
+ [$ baseFile2 , true ],
132
+ [$ baseDictionary , true ]
86
133
]);
87
134
$ this ->staticDirectoryMock ->expects (self ::exactly (2 ))->method ('copyFile ' )->withConsecutive (
88
- [$ baseLocal . ' file1 ' , $ locale . ' file1 ' , null ],
89
- [$ baseLocal . ' file2 ' , $ locale . ' file2 ' , null ]
135
+ [$ baseFile1 , $ locale . $ file1 , null ],
136
+ [$ baseFile2 , $ locale . $ file2 , null ]
90
137
);
91
138
139
+ $ this ->translationJsConfig ->expects (self ::exactly (4 ))->method ('getDictionaryFileName ' )
140
+ ->willReturn ($ dictionary );
141
+
142
+ $ this ->translationJsConfig ->expects ($ this ->once ())->method ('dictionaryEnabled ' )->willReturn (true );
143
+
144
+ $ this ->translator ->expects ($ this ->once ())->method ('setLocale ' )->with ($ locale );
145
+ $ this ->translator ->expects ($ this ->once ())->method ('loadData ' )->with ($ area , true );
146
+
147
+ $ this ->assetRepo ->expects ($ this ->once ())->method ('createAsset ' )
148
+ ->with (
149
+ $ dictionary ,
150
+ ['area ' => $ area , 'theme ' => $ themePath , 'locale ' => $ locale ]
151
+ )
152
+ ->willReturn ($ this ->asset );
153
+
154
+ $ this ->assetPublisher ->expects ($ this ->once ())->method ('publish ' );
155
+
92
156
$ model = $ this ->getModel ([
93
- DeployInterface::DEPLOY_BASE_LOCALE => $ baseLocal ,
157
+ DeployInterface::DEPLOY_BASE_LOCALE => $ baseLocale ,
94
158
Options::SYMLINK_LOCALE => 0 ,
95
159
]);
96
160
$ model ->deploy ($ area , $ themePath , $ locale );
@@ -107,7 +171,11 @@ private function getModel($options = [])
107
171
[
108
172
'output ' => $ this ->outputMock ,
109
173
'staticDirectory ' => $ this ->staticDirectoryMock ,
110
- 'options ' => $ options
174
+ 'options ' => $ options ,
175
+ 'translationJsConfig ' => $ this ->translationJsConfig ,
176
+ 'translator ' => $ this ->translator ,
177
+ 'assetRepo ' => $ this ->assetRepo ,
178
+ 'assetPublisher ' => $ this ->assetPublisher
111
179
]
112
180
);
113
181
}
0 commit comments