Skip to content

Commit 0b77392

Browse files
author
Timon de Groot
committed
Update Product Initialization Helper unit test
1 parent 98bc420 commit 0b77392

File tree

1 file changed

+60
-43
lines changed
  • app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization

1 file changed

+60
-43
lines changed

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Initialization;
78

89
use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepository;
@@ -11,6 +12,8 @@
1112
use Magento\Catalog\Model\Product;
1213
use Magento\Catalog\Model\Product\Option;
1314
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\Locale\Format;
16+
use Magento\Framework\Locale\FormatInterface;
1417
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1518
use Magento\Store\Api\Data\WebsiteInterface;
1619
use Magento\Store\Model\StoreManagerInterface;
@@ -100,6 +103,11 @@ class HelperTest extends \PHPUnit\Framework\TestCase
100103
*/
101104
private $dateTimeFilterMock;
102105

106+
/**
107+
* @var FormatInterface|\PHPUnit_Framework_MockObject_MockObject
108+
*/
109+
protected $localeFormatMock;
110+
103111
/**
104112
* @inheritdoc
105113
*/
@@ -152,6 +160,10 @@ protected function setUp()
152160
->setMethods(['prepareProductAttributes'])
153161
->disableOriginalConstructor()
154162
->getMock();
163+
$this->localeFormatMock = $this->getMockBuilder(Format::class)
164+
->setMethods(['getNumber'])
165+
->disableOriginalConstructor()
166+
->getMock();
155167

156168
$this->helper = $this->objectManager->getObject(
157169
Helper::class,
@@ -164,7 +176,8 @@ protected function setUp()
164176
'productLinkFactory' => $this->productLinkFactoryMock,
165177
'productRepository' => $this->productRepositoryMock,
166178
'linkTypeProvider' => $this->linkTypeProviderMock,
167-
'attributeFilter' => $this->attributeFilterMock
179+
'attributeFilter' => $this->attributeFilterMock,
180+
'localeFormat' => $this->localeFormatMock,
168181
]
169182
);
170183

@@ -207,9 +220,9 @@ public function testInitialize(
207220
->willReturn($this->assembleLinkTypes($linkTypes));
208221

209222
$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'],
213226
];
214227
$specialFromDate = '2018-03-03 19:30:00';
215228
$productData = [
@@ -252,7 +265,7 @@ public function testInitialize(
252265
$this->requestMock->expects($this->any())->method('getPost')->willReturnMap(
253266
[
254267
['product', [], $productData],
255-
['use_default', null, $useDefaults]
268+
['use_default', null, $useDefaults],
256269
]
257270
);
258271
$this->linkResolverMock->expects($this->once())->method('getLinks')->willReturn($links);
@@ -279,16 +292,20 @@ public function testInitialize(
279292
->willReturnMap([
280293
[
281294
['data' => $optionsData['option2']],
282-
$firstExpectedCustomOption
283-
], [
295+
$firstExpectedCustomOption,
296+
],
297+
[
284298
['data' => $optionsData['option3']],
285-
$secondExpectedCustomOption
286-
]
299+
$secondExpectedCustomOption,
300+
],
287301
]);
288302
$website = $this->getMockBuilder(WebsiteInterface::class)->getMockForAbstractClass();
289303
$website->expects($this->any())->method('getId')->willReturn(1);
290304
$this->storeManagerMock->expects($this->once())->method('isSingleStoreMode')->willReturn($isSingleStore);
291305
$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($website);
306+
$this->localeFormatMock->expects($this->any())
307+
->method('getNumber')
308+
->willReturnArgument(0);
292309

293310
$this->assembleProductRepositoryMock($links);
294311

@@ -388,8 +405,8 @@ public function initializeDataProvider()
388405
'price' => 1.00,
389406
'position' => 1,
390407
'record_id' => 1,
391-
]
392-
]
408+
],
409+
],
393410
],
394411
'linkTypes' => ['related', 'upsell', 'crosssell'],
395412
'expected_links' => [
@@ -533,16 +550,16 @@ public function mergeProductOptionsDataProvider()
533550
[
534551
'option_type_id' => '2',
535552
'key1' => 'val1',
536-
'default_key1' => 'val2'
537-
]
538-
]
539-
]
553+
'default_key1' => 'val2',
554+
],
555+
],
556+
],
540557
],
541558
[
542559
4 => [
543560
'key1' => '1',
544-
'values' => [3 => ['key1' => 1]]
545-
]
561+
'values' => [3 => ['key1' => 1]],
562+
],
546563
],
547564
[
548565
[
@@ -553,11 +570,11 @@ public function mergeProductOptionsDataProvider()
553570
[
554571
'option_type_id' => '2',
555572
'key1' => 'val1',
556-
'default_key1' => 'val2'
557-
]
558-
]
559-
]
560-
]
573+
'default_key1' => 'val2',
574+
],
575+
],
576+
],
577+
],
561578
],
562579
'key2 is replaced, key1 is not (checkbox is not checked)' => [
563580
[
@@ -573,17 +590,17 @@ public function mergeProductOptionsDataProvider()
573590
'key1' => 'val1',
574591
'key2' => 'val2',
575592
'default_key1' => 'val11',
576-
'default_key2' => 'val22'
577-
]
578-
]
579-
]
593+
'default_key2' => 'val22',
594+
],
595+
],
596+
],
580597
],
581598
[
582599
5 => [
583600
'key1' => '0',
584601
'title' => '1',
585-
'values' => [2 => ['key1' => 1]]
586-
]
602+
'values' => [2 => ['key1' => 1]],
603+
],
587604
],
588605
[
589606
[
@@ -599,11 +616,11 @@ public function mergeProductOptionsDataProvider()
599616
'key1' => 'val11',
600617
'key2' => 'val2',
601618
'default_key1' => 'val11',
602-
'default_key2' => 'val22'
603-
]
604-
]
605-
]
606-
]
619+
'default_key2' => 'val22',
620+
],
621+
],
622+
],
623+
],
607624
],
608625
'key1 is replaced, key2 has no default value' => [
609626
[
@@ -618,17 +635,17 @@ public function mergeProductOptionsDataProvider()
618635
'key1' => 'val1',
619636
'title' => 'val2',
620637
'default_key1' => 'val11',
621-
'default_title' => 'val22'
622-
]
623-
]
624-
]
638+
'default_title' => 'val22',
639+
],
640+
],
641+
],
625642
],
626643
[
627644
7 => [
628645
'key1' => '1',
629646
'key2' => '1',
630-
'values' => [2 => ['key1' => 0, 'title' => 1]]
631-
]
647+
'values' => [2 => ['key1' => 0, 'title' => 1]],
648+
],
632649
],
633650
[
634651
[
@@ -643,10 +660,10 @@ public function mergeProductOptionsDataProvider()
643660
'title' => 'val22',
644661
'default_key1' => 'val11',
645662
'default_title' => 'val22',
646-
'is_delete_store_title' => 1
647-
]
648-
]
649-
]
663+
'is_delete_store_title' => 1,
664+
],
665+
],
666+
],
650667
],
651668
],
652669
];

0 commit comments

Comments
 (0)