Skip to content

Commit 39b2558

Browse files
kalinichamkalinicham
authored andcommitted
Cover changes with Unit test
1 parent 00b2ff5 commit 39b2558

File tree

1 file changed

+64
-27
lines changed

1 file changed

+64
-27
lines changed

app/code/Magento/Translation/Test/Unit/Model/Js/DataProviderTest.php

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DataProviderTest extends \PHPUnit\Framework\TestCase
5252
protected $translateMock;
5353

5454
/**
55-
* @return void
55+
* @inheritDoc
5656
*/
5757
protected function setUp()
5858
{
@@ -83,9 +83,15 @@ protected function setUp()
8383
}
8484

8585
/**
86+
* Verify data translate
87+
*
88+
* @param array $config
8689
* @return void
90+
* @dataProvider configDataProvider
91+
*
92+
* @throws \Magento\Framework\Exception\LocalizedException
8793
*/
88-
public function testGetData()
94+
public function testGetData(array $config)
8995
{
9096
$themePath = 'blank';
9197
$areaCode = 'adminhtml';
@@ -101,28 +107,10 @@ public function testGetData()
101107
[$areaCode, $themePath, '*', '*', [$filePaths[3]]]
102108
];
103109

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'];
126114

127115
$this->appStateMock->expects($this->once())
128116
->method('getAreaCode')
@@ -157,14 +145,18 @@ public function testGetData()
157145
}
158146

159147
/**
148+
* Verify Get Data Throwing Exception
149+
*
150+
* @param array $config
160151
* @expectedException \Magento\Framework\Exception\LocalizedException
152+
*
153+
* @dataProvider configDataProvider
161154
*/
162-
public function testGetDataThrowingException()
155+
public function testGetDataThrowingException(array $config)
163156
{
164157
$themePath = 'blank';
165158
$areaCode = 'adminhtml';
166-
167-
$patterns = ['~\$\.mage\.__\(([\'"])(.+?)\1\)~'];
159+
$patterns = $config['patterns'];
168160

169161
$this->fileReadMock->expects($this->once())
170162
->method('readAll')
@@ -190,4 +182,49 @@ public function testGetDataThrowingException()
190182

191183
$this->model->getData($themePath);
192184
}
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+
}
193230
}

0 commit comments

Comments
 (0)