6
6
7
7
namespace Magento \Customer \Test \Unit \Model ;
8
8
9
+ use Magento \Customer \Api \Data \CustomerInterface ;
10
+ use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
11
+ use Magento \Customer \Api \Data \GroupInterface ;
12
+ use Magento \Customer \Api \GroupManagementInterface ;
9
13
use Magento \Customer \Model \CustomerExtractor ;
14
+ use Magento \Customer \Model \Metadata \Form ;
15
+ use Magento \Customer \Model \Metadata \FormFactory ;
16
+ use Magento \Framework \Api \DataObjectHelper ;
17
+ use Magento \Framework \App \RequestInterface ;
18
+ use Magento \Store \Api \Data \StoreInterface ;
19
+ use Magento \Store \Model \StoreManagerInterface ;
10
20
11
21
/**
12
22
* Unit test CustomerExtractorTest
@@ -16,40 +26,40 @@ class CustomerExtractorTest extends \PHPUnit\Framework\TestCase
16
26
/** @var CustomerExtractor */
17
27
protected $ customerExtractor ;
18
28
19
- /** @var \Magento\Customer\Model\Metadata\ FormFactory|\PHPUnit_Framework_MockObject_MockObject */
29
+ /** @var FormFactory|\PHPUnit_Framework_MockObject_MockObject */
20
30
protected $ formFactory ;
21
31
22
- /** @var \Magento\Customer\Api\Data\ CustomerInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */
32
+ /** @var CustomerInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */
23
33
protected $ customerFactory ;
24
34
25
- /** @var \Magento\Store\Model\ StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
35
+ /** @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
26
36
protected $ storeManager ;
27
37
28
- /** @var \Magento\Customer\Api\ GroupManagementInterface|\PHPUnit_Framework_MockObject_MockObject */
38
+ /** @var GroupManagementInterface|\PHPUnit_Framework_MockObject_MockObject */
29
39
protected $ customerGroupManagement ;
30
40
31
- /** @var \Magento\Framework\Api\ DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject */
41
+ /** @var DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject */
32
42
protected $ dataObjectHelper ;
33
43
34
- /** @var \Magento\Framework\App\ RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
44
+ /** @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
35
45
protected $ request ;
36
46
37
- /** @var \Magento\Customer\Model\Metadata\ Form|\PHPUnit_Framework_MockObject_MockObject */
47
+ /** @var Form|\PHPUnit_Framework_MockObject_MockObject */
38
48
protected $ customerForm ;
39
49
40
- /** @var \Magento\Customer\Api\Data\ CustomerInterface|\PHPUnit_Framework_MockObject_MockObject */
50
+ /** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject */
41
51
protected $ customerData ;
42
52
43
- /** @var \Magento\Store\Api\Data\ StoreInterface|\PHPUnit_Framework_MockObject_MockObject */
53
+ /** @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject */
44
54
protected $ store ;
45
55
46
- /** @var \Magento\Customer\Api\Data\ GroupInterface|\PHPUnit_Framework_MockObject_MockObject */
56
+ /** @var GroupInterface|\PHPUnit_Framework_MockObject_MockObject */
47
57
protected $ customerGroup ;
48
58
49
59
protected function setUp ()
50
60
{
51
61
$ this ->formFactory = $ this ->getMockForAbstractClass (
52
- \ Magento \ Customer \ Model \ Metadata \ FormFactory::class,
62
+ FormFactory::class,
53
63
[],
54
64
'' ,
55
65
false ,
@@ -58,7 +68,7 @@ protected function setUp()
58
68
['create ' ]
59
69
);
60
70
$ this ->customerFactory = $ this ->getMockForAbstractClass (
61
- \ Magento \ Customer \ Api \ Data \ CustomerInterfaceFactory::class,
71
+ CustomerInterfaceFactory::class,
62
72
[],
63
73
'' ,
64
74
false ,
@@ -67,34 +77,34 @@ protected function setUp()
67
77
['create ' ]
68
78
);
69
79
$ this ->storeManager = $ this ->getMockForAbstractClass (
70
- \ Magento \ Store \ Model \ StoreManagerInterface::class,
80
+ StoreManagerInterface::class,
71
81
[],
72
82
'' ,
73
83
false
74
84
);
75
85
$ this ->customerGroupManagement = $ this ->getMockForAbstractClass (
76
- \ Magento \ Customer \ Api \ GroupManagementInterface::class,
86
+ GroupManagementInterface::class,
77
87
[],
78
88
'' ,
79
89
false
80
90
);
81
- $ this ->dataObjectHelper = $ this ->createMock (\ Magento \ Framework \ Api \ DataObjectHelper::class);
82
- $ this ->request = $ this ->getMockForAbstractClass (\ Magento \ Framework \ App \ RequestInterface::class, [], '' , false );
83
- $ this ->customerForm = $ this ->createMock (\ Magento \ Customer \ Model \ Metadata \ Form::class);
91
+ $ this ->dataObjectHelper = $ this ->createMock (DataObjectHelper::class);
92
+ $ this ->request = $ this ->getMockForAbstractClass (RequestInterface::class, [], '' , false );
93
+ $ this ->customerForm = $ this ->createMock (Form::class);
84
94
$ this ->customerData = $ this ->getMockForAbstractClass (
85
- \ Magento \ Customer \ Api \ Data \ CustomerInterface::class,
95
+ CustomerInterface::class,
86
96
[],
87
97
'' ,
88
98
false
89
99
);
90
100
$ this ->store = $ this ->getMockForAbstractClass (
91
- \ Magento \ Store \ Api \ Data \ StoreInterface::class,
101
+ StoreInterface::class,
92
102
[],
93
103
'' ,
94
104
false
95
105
);
96
106
$ this ->customerGroup = $ this ->getMockForAbstractClass (
97
- \ Magento \ Customer \ Api \ Data \ GroupInterface::class,
107
+ GroupInterface::class,
98
108
[],
99
109
'' ,
100
110
false
@@ -108,14 +118,27 @@ protected function setUp()
108
118
);
109
119
}
110
120
111
- public function testExtract ()
121
+ /**
122
+ * @param int $storeId
123
+ * @param int $websiteId
124
+ * @param array $customerData
125
+ * @dataProvider getDataProvider
126
+ * @return void
127
+ */
128
+ public function testExtract (int $ storeId , int $ websiteId , array $ customerData )
112
129
{
113
- $ customerData = [
114
- 'firstname ' => 'firstname ' ,
115
- 'lastname ' => 'firstname ' ,
116
- 'email ' => 'email.example.com ' ,
117
- ];
130
+ $ this ->initializeExpectation ($ storeId , $ websiteId , $ customerData );
118
131
132
+ $ this ->assertSame ($ this ->customerData , $ this ->customerExtractor ->extract ('form-code ' , $ this ->request ));
133
+ }
134
+
135
+ /**
136
+ * @param int $storeId
137
+ * @param int $websiteId
138
+ * @param array $customerData
139
+ */
140
+ private function initializeExpectation (int $ storeId , int $ websiteId , array $ customerData ): void
141
+ {
119
142
$ this ->formFactory ->expects ($ this ->once ())
120
143
->method ('create ' )
121
144
->with ('customer ' , 'form-code ' )
@@ -136,24 +159,61 @@ public function testExtract()
136
159
->willReturn ($ this ->customerData );
137
160
$ this ->dataObjectHelper ->expects ($ this ->once ())
138
161
->method ('populateWithArray ' )
139
- ->with ($ this ->customerData , $ customerData , \ Magento \ Customer \ Api \ Data \ CustomerInterface::class)
162
+ ->with ($ this ->customerData , $ customerData , CustomerInterface::class)
140
163
->willReturn ($ this ->customerData );
141
164
$ this ->storeManager ->expects ($ this ->once ())
142
165
->method ('getStore ' )
143
166
->willReturn ($ this ->store );
144
167
$ this ->store ->expects ($ this ->once ())
145
168
->method ('getId ' )
146
- ->willReturn (1 );
169
+ ->willReturn ($ storeId );
147
170
$ this ->store ->expects ($ this ->once ())
148
171
->method ('getWebsiteId ' )
149
- ->willReturn (1 );
172
+ ->willReturn ($ websiteId );
150
173
$ this ->customerData ->expects ($ this ->once ())
151
174
->method ('setWebsiteId ' )
152
- ->with (1 );
175
+ ->with ($ websiteId );
153
176
$ this ->customerData ->expects ($ this ->once ())
154
177
->method ('setStoreId ' )
155
- ->with (1 );
178
+ ->with ($ storeId );
179
+ }
156
180
157
- $ this ->assertSame ($ this ->customerData , $ this ->customerExtractor ->extract ('form-code ' , $ this ->request ));
181
+ /**
182
+ * @return array
183
+ */
184
+ public function getDataProvider ()
185
+ {
186
+ return [
187
+ 'extract data when group id is null ' => [
188
+ 1 ,
189
+ 1 ,
190
+ [
191
+ 'firstname ' => 'firstname-1 ' ,
192
+ 'lastname ' => 'firstname-1 ' ,
193
+ 'email ' => 'email-1.example.com ' ,
194
+ 'group_id ' => null
195
+ ]
196
+ ],
197
+ 'extract data when group id is not null and default ' => [
198
+ 1 ,
199
+ 2 ,
200
+ [
201
+ 'firstname ' => 'firstname-2 ' ,
202
+ 'lastname ' => 'firstname-3 ' ,
203
+ 'email ' => 'email-2.example.com ' ,
204
+ 'group_id ' => 1
205
+ ]
206
+ ],
207
+ 'extract data when group id is different from default ' => [
208
+ 1 ,
209
+ 1 ,
210
+ [
211
+ 'firstname ' => 'firstname-3 ' ,
212
+ 'lastname ' => 'firstname-3 ' ,
213
+ 'email ' => 'email-3.example.com ' ,
214
+ 'group_id ' => 2
215
+ ]
216
+ ],
217
+ ];
158
218
}
159
219
}
0 commit comments