Skip to content

Commit 8690b25

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-arcticfoxes/MAGETWO-91435
2 parents d37aab1 + 92b9a39 commit 8690b25

File tree

134 files changed

+2735
-459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+2735
-459
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ protected function initializeProductData(array $productData, $createNew)
334334
unset($productData['media_gallery']);
335335
if ($createNew) {
336336
$product = $this->productFactory->create();
337-
if ($this->storeManager->hasSingleStore()) {
338-
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
339-
}
337+
$this->assignProductToWebsites($product);
340338
} else {
341339
$this->removeProductFromLocalCache($productData['sku']);
342340
$product = $this->get($productData['sku']);
@@ -345,31 +343,20 @@ protected function initializeProductData(array $productData, $createNew)
345343
foreach ($productData as $key => $value) {
346344
$product->setData($key, $value);
347345
}
348-
$this->assignProductToWebsites($product, $createNew);
349346

350347
return $product;
351348
}
352349

353350
/**
354351
* @param \Magento\Catalog\Model\Product $product
355-
* @param bool $createNew
356352
* @return void
357353
*/
358-
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product, $createNew)
354+
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
359355
{
360-
$websiteIds = $product->getWebsiteIds();
361-
362-
if (!$this->storeManager->hasSingleStore()) {
363-
$websiteIds = array_unique(
364-
array_merge(
365-
$websiteIds,
366-
[$this->storeManager->getStore()->getWebsiteId()]
367-
)
368-
);
369-
}
370-
371-
if ($createNew && $this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
356+
if ($this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
372357
$websiteIds = array_keys($this->storeManager->getWebsites());
358+
} else {
359+
$websiteIds = [$this->storeManager->getStore()->getWebsiteId()];
373360
}
374361

375362
$product->setWebsiteIds($websiteIds);

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ public function testGetBySkuFromCacheInitializedInGetById()
553553

554554
public function testSaveExisting()
555555
{
556-
$this->storeManagerMock->expects($this->any())->method('getWebsites')->willReturn([1 => 'default']);
557556
$this->resourceModelMock->expects($this->any())->method('getIdBySku')->will($this->returnValue(100));
558557
$this->productFactoryMock->expects($this->any())
559558
->method('create')
@@ -566,7 +565,6 @@ public function testSaveExisting()
566565
->expects($this->once())
567566
->method('toNestedArray')
568567
->will($this->returnValue($this->productData));
569-
$this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
570568
$this->productMock->expects($this->atLeastOnce())->method('getSku')->willReturn($this->productData['sku']);
571569

572570
$this->assertEquals($this->productMock, $this->model->save($this->productMock));
@@ -588,7 +586,6 @@ public function testSaveNew()
588586
->expects($this->once())
589587
->method('toNestedArray')
590588
->will($this->returnValue($this->productData));
591-
$this->productMock->method('getWebsiteIds')->willReturn([]);
592589
$this->productMock->method('getSku')->willReturn('simple');
593590

594591
$this->assertEquals($this->productMock, $this->model->save($this->productMock));
@@ -615,7 +612,6 @@ public function testSaveUnableToSaveException()
615612
->expects($this->once())
616613
->method('toNestedArray')
617614
->will($this->returnValue($this->productData));
618-
$this->productMock->method('getWebsiteIds')->willReturn([]);
619615
$this->productMock->method('getSku')->willReturn('simple');
620616

621617
$this->model->save($this->productMock);
@@ -642,7 +638,6 @@ public function testSaveException()
642638
->expects($this->once())
643639
->method('toNestedArray')
644640
->will($this->returnValue($this->productData));
645-
$this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
646641
$this->productMock->method('getSku')->willReturn('simple');
647642

648643
$this->model->save($this->productMock);
@@ -667,7 +662,6 @@ public function testSaveInvalidProductException()
667662
->expects($this->once())
668663
->method('toNestedArray')
669664
->will($this->returnValue($this->productData));
670-
$this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
671665
$this->productMock->method('getSku')->willReturn('simple');
672666

673667
$this->model->save($this->productMock);
@@ -697,9 +691,6 @@ public function testSaveThrowsTemporaryStateExceptionIfDatabaseConnectionErrorOc
697691
->expects($this->once())
698692
->method('toNestedArray')
699693
->will($this->returnValue($this->productData));
700-
$this->productMock->expects($this->once())
701-
->method('getWebsiteIds')
702-
->willReturn([]);
703694
$this->productMock->method('getSku')->willReturn('simple');
704695

705696
$this->model->save($this->productMock);
@@ -847,7 +838,6 @@ public function testSaveExistingWithOptions(array $newOptions, array $existingOp
847838
->method('toNestedArray')
848839
->will($this->returnValue($this->productData));
849840

850-
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
851841
$this->initializedProductMock->expects($this->atLeastOnce())
852842
->method('getSku')->willReturn($this->productData['sku']);
853843
$this->productMock->expects($this->atLeastOnce())->method('getSku')->willReturn($this->productData['sku']);
@@ -1083,7 +1073,6 @@ public function testSaveWithLinks(array $newLinks, array $existingLinks, array $
10831073
$outputLinks[] = $outputLink;
10841074
}
10851075
}
1086-
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
10871076

10881077
if (!empty($outputLinks)) {
10891078
$this->initializedProductMock->expects($this->once())
@@ -1264,7 +1253,6 @@ public function testSaveExistingWithNewMediaGalleryEntries()
12641253
'media_type' => 'media_type',
12651254
]
12661255
);
1267-
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
12681256
$this->initializedProductMock->expects($this->atLeastOnce())
12691257
->method('getSku')->willReturn($this->productData['sku']);
12701258
$this->productMock->expects($this->atLeastOnce())->method('getSku')->willReturn($this->productData['sku']);
@@ -1305,7 +1293,6 @@ public function testSaveWithDifferentWebsites()
13051293
2 => ['second'],
13061294
3 => ['third']
13071295
]);
1308-
$this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn([1,2,3]);
13091296
$this->productMock->expects($this->once())->method('setWebsiteIds')->willReturn([2,3]);
13101297
$this->productMock->method('getSku')->willReturn('simple');
13111298

@@ -1377,7 +1364,6 @@ public function testSaveExistingWithMediaGalleryEntries()
13771364
$this->mediaGalleryProcessor->expects($this->once())
13781365
->method('setMediaAttribute')
13791366
->with($this->initializedProductMock, ['image', 'small_image'], 'filename1');
1380-
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
13811367
$this->initializedProductMock->expects($this->atLeastOnce())
13821368
->method('getSku')->willReturn($this->productData['sku']);
13831369
$this->productMock->expects($this->atLeastOnce())->method('getSku')->willReturn($this->productData['sku']);
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Ui\Component\Product;
9+
10+
use Magento\Catalog\Ui\Component\Product\MassAction;
11+
use Magento\Framework\AuthorizationInterface;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
14+
15+
class MassActionTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/**
18+
* @var ContextInterface|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
private $contextMock;
21+
22+
/**
23+
* @var ObjectManager
24+
*/
25+
private $objectManager;
26+
27+
/**
28+
* @var AuthorizationInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $authorizationMock;
31+
32+
/**
33+
* @var MassAction
34+
*/
35+
private $massAction;
36+
37+
protected function setUp()
38+
{
39+
$this->objectManager = new ObjectManager($this);
40+
41+
$this->contextMock = $this->getMockBuilder(ContextInterface::class)
42+
->getMockForAbstractClass();
43+
$this->authorizationMock = $this->getMockBuilder(AuthorizationInterface::class)
44+
->getMockForAbstractClass();
45+
46+
$this->massAction = $this->objectManager->getObject(
47+
MassAction::class,
48+
[
49+
'authorization' => $this->authorizationMock,
50+
'context' => $this->contextMock,
51+
'data' => []
52+
]
53+
);
54+
}
55+
56+
public function testGetComponentName()
57+
{
58+
$this->assertTrue($this->massAction->getComponentName() === MassAction::NAME);
59+
}
60+
61+
/**
62+
* @param string $componentName
63+
* @param array $componentData
64+
* @param bool $isAllowed
65+
* @param bool $expectActionConfig
66+
* @return void
67+
* @dataProvider getPrepareDataProvider
68+
*/
69+
public function testPrepare($componentName, $componentData, $isAllowed = true, $expectActionConfig = true)
70+
{
71+
$processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
72+
->disableOriginalConstructor()
73+
->getMock();
74+
$this->contextMock->expects($this->atLeastOnce())->method('getProcessor')->willReturn($processor);
75+
/** @var \Magento\Ui\Component\MassAction $action */
76+
$action = $this->objectManager->getObject(
77+
\Magento\Ui\Component\MassAction::class,
78+
[
79+
'context' => $this->contextMock,
80+
'data' => [
81+
'name' => $componentName,
82+
'config' => $componentData,
83+
]
84+
]
85+
);
86+
$this->authorizationMock->method('isAllowed')
87+
->willReturn($isAllowed);
88+
$this->massAction->addComponent('action', $action);
89+
$this->massAction->prepare();
90+
$expected = $expectActionConfig ? ['actions' => [$action->getConfiguration()]] : [];
91+
$this->assertEquals($expected, $this->massAction->getConfiguration());
92+
}
93+
94+
/**
95+
* @return array
96+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
97+
*/
98+
public function getPrepareDataProvider() : array
99+
{
100+
return [
101+
[
102+
'test_component1',
103+
[
104+
'type' => 'first_action',
105+
'label' => 'First Action',
106+
'url' => '/module/controller/firstAction'
107+
],
108+
],
109+
[
110+
'test_component2',
111+
[
112+
'type' => 'second_action',
113+
'label' => 'Second Action',
114+
'actions' => [
115+
[
116+
'type' => 'second_sub_action1',
117+
'label' => 'Second Sub Action 1',
118+
'url' => '/module/controller/secondSubAction1'
119+
],
120+
[
121+
'type' => 'second_sub_action2',
122+
'label' => 'Second Sub Action 2',
123+
'url' => '/module/controller/secondSubAction2'
124+
],
125+
]
126+
],
127+
],
128+
[
129+
'status_component',
130+
[
131+
'type' => 'status',
132+
'label' => 'Status',
133+
'actions' => [
134+
[
135+
'type' => 'enable',
136+
'label' => 'Second Sub Action 1',
137+
'url' => '/module/controller/enable'
138+
],
139+
[
140+
'type' => 'disable',
141+
'label' => 'Second Sub Action 2',
142+
'url' => '/module/controller/disable'
143+
],
144+
]
145+
],
146+
],
147+
[
148+
'status_component_not_allowed',
149+
[
150+
'type' => 'status',
151+
'label' => 'Status',
152+
'actions' => [
153+
[
154+
'type' => 'enable',
155+
'label' => 'Second Sub Action 1',
156+
'url' => '/module/controller/enable'
157+
],
158+
[
159+
'type' => 'disable',
160+
'label' => 'Second Sub Action 2',
161+
'url' => '/module/controller/disable'
162+
],
163+
]
164+
],
165+
false,
166+
false
167+
],
168+
[
169+
'delete_component',
170+
[
171+
'type' => 'delete',
172+
'label' => 'First Action',
173+
'url' => '/module/controller/delete'
174+
],
175+
],
176+
[
177+
'delete_component_not_allowed',
178+
[
179+
'type' => 'delete',
180+
'label' => 'First Action',
181+
'url' => '/module/controller/delete'
182+
],
183+
false,
184+
false
185+
],
186+
[
187+
'attributes_component',
188+
[
189+
'type' => 'delete',
190+
'label' => 'First Action',
191+
'url' => '/module/controller/attributes'
192+
],
193+
],
194+
[
195+
'attributes_component_not_allowed',
196+
[
197+
'type' => 'delete',
198+
'label' => 'First Action',
199+
'url' => '/module/controller/attributes'
200+
],
201+
false,
202+
false
203+
],
204+
];
205+
}
206+
207+
/**
208+
* @param bool $expected
209+
* @param string $actionType
210+
* @param int $callNum
211+
* @param string $resource
212+
* @param bool $isAllowed
213+
* @dataProvider isActionAllowedDataProvider
214+
*/
215+
public function testIsActionAllowed($expected, $actionType, $callNum, $resource = '', $isAllowed = true)
216+
{
217+
$this->authorizationMock->expects($this->exactly($callNum))
218+
->method('isAllowed')
219+
->with($resource)
220+
->willReturn($isAllowed);
221+
222+
$this->assertEquals($expected, $this->massAction->isActionAllowed($actionType));
223+
}
224+
225+
public function isActionAllowedDataProvider()
226+
{
227+
return [
228+
'other' => [true, 'other', 0,],
229+
'delete-allowed' => [true, 'delete', 1, 'Magento_Catalog::products'],
230+
'delete-not-allowed' => [false, 'delete', 1, 'Magento_Catalog::products', false],
231+
'status-allowed' => [true, 'status', 1, 'Magento_Catalog::products'],
232+
'status-not-allowed' => [false, 'status', 1, 'Magento_Catalog::products', false],
233+
'attributes-allowed' => [true, 'attributes', 1, 'Magento_Catalog::update_attributes'],
234+
'attributes-not-allowed' => [false, 'attributes', 1, 'Magento_Catalog::update_attributes', false],
235+
236+
];
237+
}
238+
}

0 commit comments

Comments
 (0)