Skip to content

Commit b692701

Browse files
merge magento/2.3-develop into magento-chaika/Chaika-PR-2019-09-03-2.3
2 parents d0d1f50 + 2b77618 commit b692701

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,12 +832,14 @@ public function getStoreIds()
832832
if (!$this->hasStoreIds()) {
833833
$storeIds = [];
834834
if ($websiteIds = $this->getWebsiteIds()) {
835-
if ($this->_storeManager->isSingleStoreMode()) {
835+
if (!$this->isObjectNew() && $this->_storeManager->isSingleStoreMode()) {
836836
$websiteIds = array_keys($websiteIds);
837837
}
838838
foreach ($websiteIds as $websiteId) {
839839
$websiteStores = $this->_storeManager->getWebsite($websiteId)->getStoreIds();
840-
$storeIds = array_merge($storeIds, $websiteStores);
840+
foreach ($websiteStores as $websiteStore) {
841+
$storeIds []= $websiteStore;
842+
}
841843
}
842844
}
843845
$this->setStoreIds($storeIds);
@@ -920,9 +922,9 @@ public function beforeSave()
920922
//Validate changing of design.
921923
$userType = $this->getUserContext()->getUserType();
922924
if ((
923-
$userType === UserContextInterface::USER_TYPE_ADMIN
925+
$userType === UserContextInterface::USER_TYPE_ADMIN
924926
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION
925-
)
927+
)
926928
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_product_design')
927929
) {
928930
$this->setData('custom_design', $this->getOrigData('custom_design'));

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

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Api\ExtensibleDataInterface;
1414
use Magento\Framework\Api\ExtensionAttributesFactory;
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
16+
use Magento\Store\Model\StoreManagerInterface;
1617

1718
/**
1819
* Product Test
@@ -207,6 +208,11 @@ class ProductTest extends \PHPUnit\Framework\TestCase
207208
*/
208209
private $eavConfig;
209210

211+
/**
212+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
213+
*/
214+
private $storeManager;
215+
210216
/**
211217
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
212218
*/
@@ -303,13 +309,13 @@ protected function setUp()
303309
->disableOriginalConstructor()
304310
->getMock();
305311

306-
$storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
312+
$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
307313
->disableOriginalConstructor()
308314
->getMockForAbstractClass();
309-
$storeManager->expects($this->any())
315+
$this->storeManager->expects($this->any())
310316
->method('getStore')
311317
->will($this->returnValue($this->store));
312-
$storeManager->expects($this->any())
318+
$this->storeManager->expects($this->any())
313319
->method('getWebsite')
314320
->will($this->returnValue($this->website));
315321
$this->indexerRegistryMock = $this->createPartialMock(
@@ -394,7 +400,7 @@ protected function setUp()
394400
'extensionFactory' => $this->extensionAttributesFactory,
395401
'productPriceIndexerProcessor' => $this->productPriceProcessor,
396402
'catalogProductOptionFactory' => $optionFactory,
397-
'storeManager' => $storeManager,
403+
'storeManager' => $this->storeManager,
398404
'resource' => $this->resource,
399405
'registry' => $this->registry,
400406
'moduleManager' => $this->moduleManager,
@@ -450,6 +456,48 @@ public function testGetStoreIds()
450456
$this->assertEquals($expectedStoreIds, $this->model->getStoreIds());
451457
}
452458

459+
/**
460+
* @dataProvider getSingleStoreIds
461+
* @param bool $isObjectNew
462+
*/
463+
public function testGetStoreSingleSiteModelIds(
464+
bool $isObjectNew
465+
) {
466+
$websiteIDs = [0 => 2];
467+
$this->model->setWebsiteIds(
468+
!$isObjectNew ? $websiteIDs : array_flip($websiteIDs)
469+
);
470+
471+
$this->model->isObjectNew($isObjectNew);
472+
473+
$this->storeManager->expects(
474+
$this->exactly(
475+
(int) !$isObjectNew
476+
)
477+
)
478+
->method('isSingleStoreMode')
479+
->will($this->returnValue(true));
480+
481+
$this->website->expects(
482+
$this->once()
483+
)->method('getStoreIds')
484+
->will($this->returnValue($websiteIDs));
485+
486+
$this->assertEquals($websiteIDs, $this->model->getStoreIds());
487+
}
488+
489+
public function getSingleStoreIds()
490+
{
491+
return [
492+
[
493+
false
494+
],
495+
[
496+
true
497+
],
498+
];
499+
}
500+
453501
public function testGetStoreId()
454502
{
455503
$this->model->setStoreId(3);
@@ -1221,8 +1269,7 @@ public function testGetMediaGalleryImagesMerging()
12211269
{
12221270
$mediaEntries =
12231271
[
1224-
'images' =>
1225-
[
1272+
'images' => [
12261273
[
12271274
'value_id' => 1,
12281275
'file' => 'imageFile.jpg',

0 commit comments

Comments
 (0)