3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magento \Translation \Test \Unit \Model \Js ;
8
9
9
10
use Magento \Framework \App \State ;
10
11
use Magento \Framework \App \Utility \Files ;
11
- use Magento \Framework \Filesystem ;
12
+ use Magento \Framework \Component \ComponentRegistrar ;
13
+ use Magento \Framework \Component \DirSearch ;
14
+ use Magento \Framework \Filesystem \File \Read ;
15
+ use Magento \Framework \Filesystem \File \ReadFactory ;
12
16
use Magento \Framework \Filesystem \File \ReadInterface ;
13
- use Magento \Translation \Model \Js \DataProvider ;
14
- use Magento \Translation \Model \Js \Config ;
15
17
use Magento \Framework \Phrase \Renderer \Translate ;
18
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
19
+ use Magento \Translation \Model \Js \Config ;
20
+ use Magento \Translation \Model \Js \DataProvider as ModelDataProvider ;
21
+ use PHPUnit \Framework \TestCase ;
22
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
16
23
17
24
/**
18
25
* Verify data provider translation
19
26
*
20
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21
28
*/
22
- class DataProviderTest extends \ PHPUnit \ Framework \ TestCase
29
+ class DataProviderTest extends TestCase
23
30
{
24
31
/**
25
- * @var DataProvider
32
+ * @var ModelDataProvider
26
33
*/
27
- protected $ model ;
34
+ private $ model ;
28
35
29
36
/**
30
- * @var State|\PHPUnit_Framework_MockObject_MockObject
37
+ * @var State|MockObject
31
38
*/
32
- protected $ appStateMock ;
39
+ private $ appStateMock ;
33
40
34
41
/**
35
- * @var Config|\PHPUnit_Framework_MockObject_MockObject
42
+ * @var Config|MockObject
36
43
*/
37
- protected $ configMock ;
44
+ private $ configMock ;
38
45
39
46
/**
40
- * @var Files|\PHPUnit_Framework_MockObject_MockObject
47
+ * @var Files|MockObject
41
48
*/
42
- protected $ filesUtilityMock ;
49
+ private $ filesUtilityMock ;
43
50
44
51
/**
45
- * @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
52
+ * @var ReadInterface|MockObject
46
53
*/
47
- protected $ fileReadMock ;
54
+ private $ fileReadMock ;
48
55
49
56
/**
50
- * @var Translate|\PHPUnit_Framework_MockObject_MockObject
57
+ * @var Translate|MockObject
51
58
*/
52
- protected $ translateMock ;
59
+ private $ translateMock ;
53
60
54
61
/**
55
62
* @inheritDoc
56
63
*/
57
64
protected function setUp ()
58
65
{
59
- $ this ->appStateMock = $ this ->createMock (\ Magento \ Framework \ App \ State::class);
60
- $ this ->configMock = $ this ->createMock (\ Magento \ Translation \ Model \ Js \ Config::class);
61
- $ this ->filesUtilityMock = $ this ->createMock (\ Magento \ Framework \ App \ Utility \ Files::class);
62
- $ fileReadFactory = $ this ->createMock (\ Magento \ Framework \ Filesystem \ File \ ReadFactory::class);
63
- $ this ->fileReadMock = $ this ->createMock (\ Magento \ Framework \ Filesystem \ File \ Read::class);
64
- $ this ->translateMock = $ this ->createMock (\ Magento \ Framework \ Phrase \ Renderer \ Translate::class);
66
+ $ this ->appStateMock = $ this ->createMock (State::class);
67
+ $ this ->configMock = $ this ->createMock (Config::class);
68
+ $ this ->filesUtilityMock = $ this ->createMock (Files::class);
69
+ $ fileReadFactory = $ this ->createMock (ReadFactory::class);
70
+ $ this ->fileReadMock = $ this ->createMock (Read::class);
71
+ $ this ->translateMock = $ this ->createMock (Translate::class);
65
72
$ fileReadFactory ->expects ($ this ->atLeastOnce ())
66
73
->method ('create ' )
67
74
->willReturn ($ this ->fileReadMock );
68
- $ dirSearch = $ this ->createMock (\ Magento \ Framework \ Component \ DirSearch::class);
69
- $ objectManager = new \ Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager ($ this );
75
+ $ dirSearch = $ this ->createMock (DirSearch::class);
76
+ $ objectManager = new ObjectManager ($ this );
70
77
$ this ->model = $ objectManager ->getObject (
71
- \ Magento \ Translation \ Model \ Js \DataProvider ::class,
78
+ ModelDataProvider ::class,
72
79
[
73
80
'appState ' => $ this ->appStateMock ,
74
81
'config ' => $ this ->configMock ,
75
82
'fileReadFactory ' => $ fileReadFactory ,
76
83
'translate ' => $ this ->translateMock ,
77
84
'dirSearch ' => $ dirSearch ,
78
85
'filesUtility ' => $ this ->filesUtilityMock ,
79
- 'componentRegistrar ' =>
80
- $ this ->createMock (\Magento \Framework \Component \ComponentRegistrar::class)
86
+ 'componentRegistrar ' => $ this ->createMock (ComponentRegistrar::class)
81
87
]
82
88
);
83
89
}
84
90
85
91
/**
86
- * Verify data translate
92
+ * Verify data translate.
87
93
*
88
94
* @param array $config
89
95
* @return void
90
96
* @dataProvider configDataProvider
91
- *
92
- * @throws \Magento\Framework\Exception\LocalizedException
93
97
*/
94
- public function testGetData (array $ config )
98
+ public function testGetData (array $ config ): void
95
99
{
96
100
$ themePath = 'blank ' ;
97
101
$ areaCode = 'adminhtml ' ;
@@ -140,14 +144,14 @@ public function testGetData(array $config)
140
144
}
141
145
142
146
/**
143
- * Verify Get Data Throwing Exception
147
+ * Verify get data throwing exception.
144
148
*
145
149
* @param array $config
146
- * @expectedException \Magento\Framework\Exception\LocalizedException
147
- *
150
+ * @return void
148
151
* @dataProvider configDataProvider
152
+ * @expectedException \Magento\Framework\Exception\LocalizedException
149
153
*/
150
- public function testGetDataThrowingException (array $ config )
154
+ public function testGetDataThrowingException (array $ config ): void
151
155
{
152
156
$ themePath = 'blank ' ;
153
157
$ areaCode = 'adminhtml ' ;
@@ -156,7 +160,6 @@ public function testGetDataThrowingException(array $config)
156
160
$ this ->fileReadMock ->expects ($ this ->once ())
157
161
->method ('readAll ' )
158
162
->willReturn ('content1$.mage.__("hello1")content1 ' );
159
-
160
163
$ this ->appStateMock ->expects ($ this ->once ())
161
164
->method ('getAreaCode ' )
162
165
->willReturn ($ areaCode );
@@ -166,11 +169,9 @@ public function testGetDataThrowingException(array $config)
166
169
$ this ->filesUtilityMock ->expects ($ this ->any ())
167
170
->method ('getStaticHtmlFiles ' )
168
171
->willReturn (['test ' ]);
169
-
170
172
$ this ->configMock ->expects ($ this ->any ())
171
173
->method ('getPatterns ' )
172
174
->willReturn ($ patterns );
173
-
174
175
$ this ->translateMock ->expects ($ this ->once ())
175
176
->method ('render ' )
176
177
->willThrowException (new \Exception ('Test exception ' ));
@@ -179,47 +180,42 @@ public function testGetDataThrowingException(array $config)
179
180
}
180
181
181
182
/**
182
- * Config Data Provider
183
+ * Config data provider.
183
184
*
184
185
* @return array
185
186
*/
186
187
public function configDataProvider (): array
187
188
{
188
189
return [
189
- [
190
- [
191
- 'patterns ' => [
192
- '~\$\.mage\.__\(([ \'"])(.+?)\1\)~ ' ,
193
- '~i18n\:\s*([" \'])(.*?)(?<! \\\)\1~ ' ,
194
- '~translate\=(" \')([^ \'].*?) \'\"~ ' ,
195
- '~(?s)\$t\(\s*([ \'"])(\?\<translate\>.+?)(?<! \\\)\1\s*(*SKIP)\)(?s)~ ' ,
196
- '~translate args\=("| \'|" \'| \\\" \')([^ \'].*?)( \'\\\"| \'"| \'|")~ ' ,
197
- ],
198
-
199
- 'expectedResult ' => [
200
- 'hello1 ' => 'hello1translated ' ,
201
- 'hello2 ' => 'hello2translated ' ,
202
- 'hello3 ' => 'hello3translated ' ,
203
- 'hello4 ' => 'hello4translated '
204
- ],
205
-
206
- 'contentsMap ' =>
207
- [
208
- 'content1$.mage.__("hello1")content1 ' ,
209
- 'content2$.mage.__("hello2")content2 ' ,
210
- 'content2$.mage.__("hello4")content4 ' ,
211
- 'content2$.mage.__("hello3")content3 ' ,
212
- ],
213
-
214
- 'translateMap ' => [
215
- [['hello1 ' ], [], 'hello1translated ' ],
216
- [['hello2 ' ], [], 'hello2translated ' ],
217
- [['hello3 ' ], [], 'hello3translated ' ],
218
- [['hello4 ' ], [], 'hello4translated ' ]
219
- ]
190
+ [
191
+ [
192
+ 'patterns ' => [
193
+ '~\$\.mage\.__\(([ \'"])(.+?)\1\)~ ' ,
194
+ '~i18n\:\s*([" \'])(.*?)(?<! \\\)\1~ ' ,
195
+ '~translate\=(" \')([^ \'].*?) \'\"~ ' ,
196
+ '~(?s)\$t\(\s*([ \'"])(\?\<translate\>.+?)(?<! \\\)\1\s*(*SKIP)\)(?s)~ ' ,
197
+ '~translate args\=("| \'|" \'| \\\" \')([^ \'].*?)( \'\\\"| \'"| \'|")~ ' ,
220
198
],
221
-
222
- ]
199
+ 'expectedResult ' => [
200
+ 'hello1 ' => 'hello1translated ' ,
201
+ 'hello2 ' => 'hello2translated ' ,
202
+ 'hello3 ' => 'hello3translated ' ,
203
+ 'hello4 ' => 'hello4translated ' ,
204
+ ],
205
+ 'contentsMap ' => [
206
+ 'content1$.mage.__("hello1")content1 ' ,
207
+ 'content2$.mage.__("hello2")content2 ' ,
208
+ 'content2$.mage.__("hello4")content4 ' ,
209
+ 'content2$.mage.__("hello3")content3 ' ,
210
+ ],
211
+ 'translateMap ' => [
212
+ [['hello1 ' ], [], 'hello1translated ' ],
213
+ [['hello2 ' ], [], 'hello2translated ' ],
214
+ [['hello3 ' ], [], 'hello3translated ' ],
215
+ [['hello4 ' ], [], 'hello4translated ' ],
216
+ ]
217
+ ],
218
+ ]
223
219
];
224
220
}
225
221
}
0 commit comments