8
8
use Magento \Translation \Model \Js \Config ;
9
9
use Magento \Translation \Model \Js \DataProvider ;
10
10
use Magento \Translation \Model \Json \PreProcessor ;
11
+ use Magento \Backend \App \Area \FrontNameResolver ;
11
12
12
13
class PreProcessorTest extends \PHPUnit \Framework \TestCase
13
14
{
14
15
/**
15
16
* @var PreProcessor
16
17
*/
17
- protected $ model ;
18
+ private $ model ;
18
19
19
20
/**
20
21
* @var Config|\PHPUnit_Framework_MockObject_MockObject
21
22
*/
22
- protected $ configMock ;
23
+ private $ configMock ;
23
24
24
25
/**
25
26
* @var DataProvider|\PHPUnit_Framework_MockObject_MockObject
26
27
*/
27
- protected $ dataProviderMock ;
28
+ private $ dataProviderMock ;
28
29
29
30
/**
30
31
* @var \Magento\Framework\App\AreaList|\PHPUnit_Framework_MockObject_MockObject
31
32
*/
32
- protected $ areaListMock ;
33
+ private $ areaListMock ;
33
34
34
35
/**
35
36
* @var \Magento\Framework\TranslateInterface|\PHPUnit_Framework_MockObject_MockObject
36
37
*/
37
- protected $ translateMock ;
38
+ private $ translateMock ;
38
39
39
40
/**
40
41
* @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
41
42
*/
42
43
private $ designMock ;
43
44
45
+ /**
46
+ * @inheritdoc
47
+ */
44
48
protected function setUp ()
45
49
{
46
50
$ this ->configMock = $ this ->createMock (\Magento \Translation \Model \Js \Config::class);
@@ -57,7 +61,14 @@ protected function setUp()
57
61
);
58
62
}
59
63
60
- public function testGetData ()
64
+ /**
65
+ * Test 'process' method.
66
+ *
67
+ * @param array $data
68
+ * @param array $expects
69
+ * @dataProvider processDataProvider
70
+ */
71
+ public function testProcess (array $ data , array $ expects )
61
72
{
62
73
$ chain = $ this ->createMock (\Magento \Framework \View \Asset \PreProcessor \Chain::class);
63
74
$ asset = $ this ->createMock (\Magento \Framework \View \Asset \File::class);
@@ -66,8 +77,10 @@ public function testGetData()
66
77
$ targetPath = 'path/js-translation.json ' ;
67
78
$ themePath = '*/* ' ;
68
79
$ dictionary = ['hello ' => 'bonjour ' ];
69
- $ areaCode = 'adminhtml ' ;
80
+ $ areaCode = $ data ['area_code ' ];
81
+
70
82
$ area = $ this ->createMock (\Magento \Framework \App \Area::class);
83
+ $ area ->expects ($ expects ['area_load ' ])->method ('load ' )->willReturnSelf ();
71
84
72
85
$ chain ->expects ($ this ->once ())
73
86
->method ('getTargetAssetPath ' )
@@ -93,7 +106,7 @@ public function testGetData()
93
106
94
107
$ this ->designMock ->expects ($ this ->once ())->method ('setDesignTheme ' )->with ($ themePath , $ areaCode );
95
108
96
- $ this ->areaListMock ->expects ($ this -> once () )
109
+ $ this ->areaListMock ->expects ($ expects [ ' areaList_getArea ' ] )
97
110
->method ('getArea ' )
98
111
->with ($ areaCode )
99
112
->willReturn ($ area );
@@ -114,4 +127,33 @@ public function testGetData()
114
127
115
128
$ this ->model ->process ($ chain );
116
129
}
130
+
131
+ /**
132
+ * Data provider for 'process' method test.
133
+ *
134
+ * @return array
135
+ */
136
+ public function processDataProvider ()
137
+ {
138
+ return [
139
+ [
140
+ [
141
+ 'area_code ' => FrontNameResolver::AREA_CODE
142
+ ],
143
+ [
144
+ 'areaList_getArea ' => $ this ->never (),
145
+ 'area_load ' => $ this ->never (),
146
+ ]
147
+ ],
148
+ [
149
+ [
150
+ 'area_code ' => 'frontend '
151
+ ],
152
+ [
153
+ 'areaList_getArea ' => $ this ->once (),
154
+ 'area_load ' => $ this ->once (),
155
+ ]
156
+ ],
157
+ ];
158
+ }
117
159
}
0 commit comments