@@ -52,7 +52,7 @@ class DataProviderTest extends \PHPUnit\Framework\TestCase
52
52
protected $ translateMock ;
53
53
54
54
/**
55
- * @return void
55
+ * @inheritDoc
56
56
*/
57
57
protected function setUp ()
58
58
{
@@ -83,9 +83,15 @@ protected function setUp()
83
83
}
84
84
85
85
/**
86
+ * Verify data translate
87
+ *
88
+ * @param array $config
86
89
* @return void
90
+ * @dataProvider configDataProvider
91
+ *
92
+ * @throws \Magento\Framework\Exception\LocalizedException
87
93
*/
88
- public function testGetData ()
94
+ public function testGetData (array $ config )
89
95
{
90
96
$ themePath = 'blank ' ;
91
97
$ areaCode = 'adminhtml ' ;
@@ -101,28 +107,10 @@ public function testGetData()
101
107
[$ areaCode , $ themePath , '* ' , '* ' , [$ filePaths [3 ]]]
102
108
];
103
109
104
- $ expectedResult = [
105
- 'hello1 ' => 'hello1translated ' ,
106
- 'hello2 ' => 'hello2translated ' ,
107
- 'hello3 ' => 'hello3translated ' ,
108
- 'hello4 ' => 'hello4translated '
109
- ];
110
-
111
- $ contentsMap = [
112
- 'content1$.mage.__("hello1")content1 ' ,
113
- 'content2$.mage.__("hello2")content2 ' ,
114
- 'content2$.mage.__("hello4")content4 ' , // this value should be last after running data provider
115
- 'content2$.mage.__("hello3")content3 ' ,
116
- ];
117
-
118
- $ translateMap = [
119
- [['hello1 ' ], [], 'hello1translated ' ],
120
- [['hello2 ' ], [], 'hello2translated ' ],
121
- [['hello3 ' ], [], 'hello3translated ' ],
122
- [['hello4 ' ], [], 'hello4translated ' ]
123
- ];
124
-
125
- $ patterns = ['~\$\.mage\.__\(([ \'"])(.+?)\1\)~ ' ];
110
+ $ patterns = $ config ['patterns ' ];
111
+ $ expectedResult = $ config ['expectedResult ' ];
112
+ $ contentsMap = $ config ['contentsMap ' ];
113
+ $ translateMap = $ config ['translateMap ' ];
126
114
127
115
$ this ->appStateMock ->expects ($ this ->once ())
128
116
->method ('getAreaCode ' )
@@ -157,14 +145,18 @@ public function testGetData()
157
145
}
158
146
159
147
/**
148
+ * Verify Get Data Throwing Exception
149
+ *
150
+ * @param array $config
160
151
* @expectedException \Magento\Framework\Exception\LocalizedException
152
+ *
153
+ * @dataProvider configDataProvider
161
154
*/
162
- public function testGetDataThrowingException ()
155
+ public function testGetDataThrowingException (array $ config )
163
156
{
164
157
$ themePath = 'blank ' ;
165
158
$ areaCode = 'adminhtml ' ;
166
-
167
- $ patterns = ['~\$\.mage\.__\(([ \'"])(.+?)\1\)~ ' ];
159
+ $ patterns = $ config ['patterns ' ];
168
160
169
161
$ this ->fileReadMock ->expects ($ this ->once ())
170
162
->method ('readAll ' )
@@ -190,4 +182,49 @@ public function testGetDataThrowingException()
190
182
191
183
$ this ->model ->getData ($ themePath );
192
184
}
185
+
186
+ /**
187
+ * Config Data Provider
188
+ *
189
+ * @return array
190
+ */
191
+ public function configDataProvider (): array
192
+ {
193
+ return [
194
+ [
195
+ [
196
+ 'patterns ' => [
197
+ '~\$\.mage\.__\(([ \'"])(.+?)\1\)~ ' ,
198
+ '~i18n\:\s*([" \'])(.*?)(?<! \\\)\1~ ' ,
199
+ '~translate\=(" \')([^ \'].*?) \'\"~ ' ,
200
+ '~(?s)\$t\(\s*([ \'"])(\?\<translate\>.+?)(?<! \\\)\1\s*(*SKIP)\)(?s)~ ' ,
201
+ '~translate args\=("| \'|" \'| \\\" \')([^ \'].*?)( \'\\\"| \'"| \'|")~ ' ,
202
+ ],
203
+
204
+ 'expectedResult ' => [
205
+ 'hello1 ' => 'hello1translated ' ,
206
+ 'hello2 ' => 'hello2translated ' ,
207
+ 'hello3 ' => 'hello3translated ' ,
208
+ 'hello4 ' => 'hello4translated '
209
+ ],
210
+
211
+ 'contentsMap ' =>
212
+ [
213
+ 'content1$.mage.__("hello1")content1 ' ,
214
+ 'content2$.mage.__("hello2")content2 ' ,
215
+ 'content2$.mage.__("hello4")content4 ' ,
216
+ 'content2$.mage.__("hello3")content3 ' ,
217
+ ],
218
+
219
+ 'translateMap ' => [
220
+ [['hello1 ' ], [], 'hello1translated ' ],
221
+ [['hello2 ' ], [], 'hello2translated ' ],
222
+ [['hello3 ' ], [], 'hello3translated ' ],
223
+ [['hello4 ' ], [], 'hello4translated ' ]
224
+ ]
225
+ ],
226
+
227
+ ]
228
+ ];
229
+ }
193
230
}
0 commit comments