7
7
8
8
use Magento \Catalog \Api \Data \ProductInterface ;
9
9
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable ;
10
- use Magento \Framework \Model \ResourceModel \Db \Context ;
11
- use Magento \Framework \DB \Select ;
12
10
use Magento \Framework \App \ScopeResolverInterface ;
11
+ use Magento \Framework \DB \Select ;
12
+ use Magento \Framework \Model \ResourceModel \Db \Context ;
13
13
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
14
14
15
15
/**
@@ -74,13 +74,18 @@ protected function setUp()
74
74
->method ('getMetadata ' )
75
75
->with (ProductInterface::class)
76
76
->willReturn ($ this ->metadataMock );
77
+
77
78
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
79
+ $ context = $ this ->getMockBuilder (Context::class)
80
+ ->disableOriginalConstructor ()
81
+ ->getMock ();
82
+ $ context ->expects ($ this ->any ())->method ('getResources ' )->willReturn ($ this ->resource );
83
+
78
84
$ this ->configurable = $ this ->objectManagerHelper ->getObject (
79
85
\Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable::class,
80
86
[
81
- 'resource ' => $ this -> resource ,
87
+ 'context ' => $ context ,
82
88
'catalogProductRelation ' => $ this ->relation ,
83
- 'scopeResolver ' => $ this ->getMockForAbstractClass (\Magento \Framework \App \ScopeResolverInterface::class)
84
89
]
85
90
);
86
91
$ reflection = new \ReflectionClass (
@@ -89,6 +94,13 @@ protected function setUp()
89
94
$ reflectionProperty = $ reflection ->getProperty ('metadataPool ' );
90
95
$ reflectionProperty ->setAccessible (true );
91
96
$ reflectionProperty ->setValue ($ this ->configurable , $ this ->metadataPoolMock );
97
+
98
+ $ reflectionProperty = $ reflection ->getProperty ('scopeResolver ' );
99
+ $ reflectionProperty ->setAccessible (true );
100
+ $ reflectionProperty ->setValue (
101
+ $ this ->configurable ,
102
+ $ this ->getMockForAbstractClass (\Magento \Framework \App \ScopeResolverInterface::class)
103
+ );
92
104
}
93
105
94
106
public function testSaveProducts ()
@@ -98,11 +110,11 @@ public function testSaveProducts()
98
110
->setMethods (['__sleep ' , '__wakeup ' , 'getData ' ])
99
111
->disableOriginalConstructor ()
100
112
->getMock ();
101
-
102
- $ this ->metadataMock ->expects ($ this ->once ())
113
+
114
+ $ this ->metadataMock ->expects ($ this ->once ())
103
115
->method ('getLinkField ' )
104
116
->willReturn ('link ' );
105
- $ mainProduct ->expects ($ this ->once ())
117
+ $ mainProduct ->expects ($ this ->once ())
106
118
->method ('getData ' )
107
119
->with ('link ' )
108
120
->willReturn (3 );
@@ -140,14 +152,15 @@ public function testGetConfigurableOptions()
140
152
[
141
153
$ this ->getMockBuilder (Context::class)->disableOriginalConstructor ()->getMock (),
142
154
$ this ->relation ,
143
- $ scopeResolver
144
155
],
145
156
'' ,
146
157
true
147
158
);
148
- $ context = $ this ->getMockBuilder (Context::class)
149
- ->disableOriginalConstructor ()
150
- ->getMock ();
159
+
160
+ $ reflection = new \ReflectionClass ('Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable ' );
161
+ $ reflectionProperty = $ reflection ->getProperty ('scopeResolver ' );
162
+ $ reflectionProperty ->setAccessible (true );
163
+ $ reflectionProperty ->setValue ($ configurable , $ scopeResolver );
151
164
152
165
$ reflection = new \ReflectionClass (Configurable::class);
153
166
$ reflectionProperty = $ reflection ->getProperty ('metadataPool ' );
@@ -183,7 +196,7 @@ public function testGetConfigurableOptions()
183
196
['eav_attribute ' , 'eav_attribute value ' ],
184
197
['catalog_product_entity ' , 'catalog_product_entity value ' ],
185
198
['eav_attribute_option_value ' , 'eav_attribute_option_value value ' ],
186
- ['catalog_product_super_attribute_label ' , 'catalog_product_super_attribute_label value ' ]
199
+ ['catalog_product_super_attribute_label ' , 'catalog_product_super_attribute_label value ' ],
187
200
]
188
201
)
189
202
);
@@ -240,22 +253,22 @@ public function testGetConfigurableOptions()
240
253
[
241
254
['product_entity ' => 'catalog_product_entity value ' ],
242
255
'product_entity.link = super_attribute.product_id ' ,
243
- []
256
+ [],
244
257
],
245
258
[
246
259
['product_link ' => 'catalog_product_super_link value ' ],
247
260
'product_link.parent_id = super_attribute.product_id ' ,
248
- []
261
+ [],
249
262
],
250
263
[
251
264
['attribute ' => 'eav_attribute value ' ],
252
265
'attribute.attribute_id = super_attribute.attribute_id ' ,
253
- []
266
+ [],
254
267
],
255
268
[
256
269
['entity ' => 'catalog_product_entity value ' ],
257
270
'entity.entity_id = product_link.product_id ' ,
258
- []
271
+ [],
259
272
],
260
273
[
261
274
['entity_value ' => 'getBackendTable value ' ],
@@ -264,10 +277,10 @@ public function testGetConfigurableOptions()
264
277
[
265
278
'entity_value.attribute_id = super_attribute.attribute_id ' ,
266
279
'entity_value.store_id = 0 ' ,
267
- 'entity_value.link = entity.link '
280
+ 'entity_value.link = entity.link ' ,
268
281
]
269
282
),
270
- []
283
+ [],
271
284
]
272
285
);
273
286
$ select ->expects ($ this ->exactly (2 ))
@@ -280,21 +293,21 @@ public function testGetConfigurableOptions()
280
293
' AND ' ,
281
294
[
282
295
'option_value.option_id = entity_value.value ' ,
283
- 'option_value.store_id = ' . 123
296
+ 'option_value.store_id = ' . 123 ,
284
297
]
285
298
),
286
- []
299
+ [],
287
300
],
288
301
[
289
302
['default_option_value ' => 'eav_attribute_option_value value ' ],
290
303
implode (
291
304
' AND ' ,
292
305
[
293
306
'default_option_value.option_id = entity_value.value ' ,
294
- 'default_option_value.store_id = ' . \Magento \Store \Model \Store::DEFAULT_STORE_ID
307
+ 'default_option_value.store_id = ' . \Magento \Store \Model \Store::DEFAULT_STORE_ID ,
295
308
]
296
309
),
297
- []
310
+ [],
298
311
]
299
312
);
300
313
$ select ->expects ($ this ->exactly (2 ))
@@ -303,11 +316,11 @@ public function testGetConfigurableOptions()
303
316
->withConsecutive (
304
317
[
305
318
'super_attribute.product_id = ? ' ,
306
- 'getId value '
319
+ 'getId value ' ,
307
320
],
308
321
[
309
322
'attribute.attribute_id = ? ' ,
310
- 'getAttributeId value '
323
+ 'getAttributeId value ' ,
311
324
]
312
325
);
313
326
0 commit comments