3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Catalog \Test \Unit \Controller \Adminhtml \Product \Initialization ;
7
8
8
9
use Magento \Catalog \Api \ProductRepositoryInterface as ProductRepository ;
11
12
use Magento \Catalog \Model \Product ;
12
13
use Magento \Catalog \Model \Product \Option ;
13
14
use Magento \Framework \App \RequestInterface ;
15
+ use Magento \Framework \Locale \Format ;
16
+ use Magento \Framework \Locale \FormatInterface ;
14
17
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
15
18
use Magento \Store \Api \Data \WebsiteInterface ;
16
19
use Magento \Store \Model \StoreManagerInterface ;
@@ -100,6 +103,11 @@ class HelperTest extends \PHPUnit\Framework\TestCase
100
103
*/
101
104
private $ dateTimeFilterMock ;
102
105
106
+ /**
107
+ * @var FormatInterface|\PHPUnit_Framework_MockObject_MockObject
108
+ */
109
+ protected $ localeFormatMock ;
110
+
103
111
/**
104
112
* @inheritdoc
105
113
*/
@@ -152,6 +160,10 @@ protected function setUp()
152
160
->setMethods (['prepareProductAttributes ' ])
153
161
->disableOriginalConstructor ()
154
162
->getMock ();
163
+ $ this ->localeFormatMock = $ this ->getMockBuilder (Format::class)
164
+ ->setMethods (['getNumber ' ])
165
+ ->disableOriginalConstructor ()
166
+ ->getMock ();
155
167
156
168
$ this ->helper = $ this ->objectManager ->getObject (
157
169
Helper::class,
@@ -164,7 +176,8 @@ protected function setUp()
164
176
'productLinkFactory ' => $ this ->productLinkFactoryMock ,
165
177
'productRepository ' => $ this ->productRepositoryMock ,
166
178
'linkTypeProvider ' => $ this ->linkTypeProviderMock ,
167
- 'attributeFilter ' => $ this ->attributeFilterMock
179
+ 'attributeFilter ' => $ this ->attributeFilterMock ,
180
+ 'localeFormat ' => $ this ->localeFormatMock ,
168
181
]
169
182
);
170
183
@@ -207,9 +220,9 @@ public function testInitialize(
207
220
->willReturn ($ this ->assembleLinkTypes ($ linkTypes ));
208
221
209
222
$ optionsData = [
210
- 'option1 ' => ['is_delete ' => true , 'name ' => 'name1 ' , 'price ' => 'price1 ' , 'option_id ' => '' ],
211
- 'option2 ' => ['is_delete ' => false , 'name ' => 'name1 ' , 'price ' => 'price1 ' , 'option_id ' => '13 ' ],
212
- 'option3 ' => ['is_delete ' => false , 'name ' => 'name1 ' , 'price ' => 'price1 ' , 'option_id ' => '14 ' ]
223
+ 'option1 ' => ['is_delete ' => true , 'name ' => 'name1 ' , 'price ' => '1 ' , 'option_id ' => '' ],
224
+ 'option2 ' => ['is_delete ' => false , 'name ' => 'name2 ' , 'price ' => '2 ' , 'option_id ' => '13 ' ],
225
+ 'option3 ' => ['is_delete ' => false , 'name ' => 'name3 ' , 'price ' => '3 ' , 'option_id ' => '14 ' ],
213
226
];
214
227
$ specialFromDate = '2018-03-03 19:30:00 ' ;
215
228
$ productData = [
@@ -252,7 +265,7 @@ public function testInitialize(
252
265
$ this ->requestMock ->expects ($ this ->any ())->method ('getPost ' )->willReturnMap (
253
266
[
254
267
['product ' , [], $ productData ],
255
- ['use_default ' , null , $ useDefaults ]
268
+ ['use_default ' , null , $ useDefaults ],
256
269
]
257
270
);
258
271
$ this ->linkResolverMock ->expects ($ this ->once ())->method ('getLinks ' )->willReturn ($ links );
@@ -279,16 +292,20 @@ public function testInitialize(
279
292
->willReturnMap ([
280
293
[
281
294
['data ' => $ optionsData ['option2 ' ]],
282
- $ firstExpectedCustomOption
283
- ], [
295
+ $ firstExpectedCustomOption ,
296
+ ],
297
+ [
284
298
['data ' => $ optionsData ['option3 ' ]],
285
- $ secondExpectedCustomOption
286
- ]
299
+ $ secondExpectedCustomOption,
300
+ ],
287
301
]);
288
302
$ website = $ this ->getMockBuilder (WebsiteInterface::class)->getMockForAbstractClass ();
289
303
$ website ->expects ($ this ->any ())->method ('getId ' )->willReturn (1 );
290
304
$ this ->storeManagerMock ->expects ($ this ->once ())->method ('isSingleStoreMode ' )->willReturn ($ isSingleStore );
291
305
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('getWebsite ' )->willReturn ($ website );
306
+ $ this ->localeFormatMock ->expects ($ this ->any ())
307
+ ->method ('getNumber ' )
308
+ ->willReturnArgument (0 );
292
309
293
310
$ this ->assembleProductRepositoryMock ($ links );
294
311
@@ -388,8 +405,8 @@ public function initializeDataProvider()
388
405
'price ' => 1.00 ,
389
406
'position ' => 1 ,
390
407
'record_id ' => 1 ,
391
- ]
392
- ]
408
+ ],
409
+ ],
393
410
],
394
411
'linkTypes ' => ['related ' , 'upsell ' , 'crosssell ' ],
395
412
'expected_links ' => [
@@ -533,16 +550,16 @@ public function mergeProductOptionsDataProvider()
533
550
[
534
551
'option_type_id ' => '2 ' ,
535
552
'key1 ' => 'val1 ' ,
536
- 'default_key1 ' => 'val2 '
537
- ]
538
- ]
539
- ]
553
+ 'default_key1 ' => 'val2 ' ,
554
+ ],
555
+ ],
556
+ ],
540
557
],
541
558
[
542
559
4 => [
543
560
'key1 ' => '1 ' ,
544
- 'values ' => [3 => ['key1 ' => 1 ]]
545
- ]
561
+ 'values ' => [3 => ['key1 ' => 1 ]],
562
+ ],
546
563
],
547
564
[
548
565
[
@@ -553,11 +570,11 @@ public function mergeProductOptionsDataProvider()
553
570
[
554
571
'option_type_id ' => '2 ' ,
555
572
'key1 ' => 'val1 ' ,
556
- 'default_key1 ' => 'val2 '
557
- ]
558
- ]
559
- ]
560
- ]
573
+ 'default_key1 ' => 'val2 ' ,
574
+ ],
575
+ ],
576
+ ],
577
+ ],
561
578
],
562
579
'key2 is replaced, key1 is not (checkbox is not checked) ' => [
563
580
[
@@ -573,17 +590,17 @@ public function mergeProductOptionsDataProvider()
573
590
'key1 ' => 'val1 ' ,
574
591
'key2 ' => 'val2 ' ,
575
592
'default_key1 ' => 'val11 ' ,
576
- 'default_key2 ' => 'val22 '
577
- ]
578
- ]
579
- ]
593
+ 'default_key2 ' => 'val22 ' ,
594
+ ],
595
+ ],
596
+ ],
580
597
],
581
598
[
582
599
5 => [
583
600
'key1 ' => '0 ' ,
584
601
'title ' => '1 ' ,
585
- 'values ' => [2 => ['key1 ' => 1 ]]
586
- ]
602
+ 'values ' => [2 => ['key1 ' => 1 ]],
603
+ ],
587
604
],
588
605
[
589
606
[
@@ -599,11 +616,11 @@ public function mergeProductOptionsDataProvider()
599
616
'key1 ' => 'val11 ' ,
600
617
'key2 ' => 'val2 ' ,
601
618
'default_key1 ' => 'val11 ' ,
602
- 'default_key2 ' => 'val22 '
603
- ]
604
- ]
605
- ]
606
- ]
619
+ 'default_key2 ' => 'val22 ' ,
620
+ ],
621
+ ],
622
+ ],
623
+ ],
607
624
],
608
625
'key1 is replaced, key2 has no default value ' => [
609
626
[
@@ -618,17 +635,17 @@ public function mergeProductOptionsDataProvider()
618
635
'key1 ' => 'val1 ' ,
619
636
'title ' => 'val2 ' ,
620
637
'default_key1 ' => 'val11 ' ,
621
- 'default_title ' => 'val22 '
622
- ]
623
- ]
624
- ]
638
+ 'default_title ' => 'val22 ' ,
639
+ ],
640
+ ],
641
+ ],
625
642
],
626
643
[
627
644
7 => [
628
645
'key1 ' => '1 ' ,
629
646
'key2 ' => '1 ' ,
630
- 'values ' => [2 => ['key1 ' => 0 , 'title ' => 1 ]]
631
- ]
647
+ 'values ' => [2 => ['key1 ' => 0 , 'title ' => 1 ]],
648
+ ],
632
649
],
633
650
[
634
651
[
@@ -643,10 +660,10 @@ public function mergeProductOptionsDataProvider()
643
660
'title ' => 'val22 ' ,
644
661
'default_key1 ' => 'val11 ' ,
645
662
'default_title ' => 'val22 ' ,
646
- 'is_delete_store_title ' => 1
647
- ]
648
- ]
649
- ]
663
+ 'is_delete_store_title ' => 1 ,
664
+ ],
665
+ ],
666
+ ],
650
667
],
651
668
],
652
669
];
0 commit comments