Skip to content

Commit 4670034

Browse files
committed
Merge remote-tracking branches 'local/ACP2E-1214', 'local/ACP2E-1223' and 'local/ACP2E-1296' into PR_combine
4 parents 18bdb6a + e5df77c + 74e6857 + 0d90748 commit 4670034

File tree

8 files changed

+251
-25
lines changed

8 files changed

+251
-25
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price/DisabledProductOptionPriceModifier.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ public function modifyPrice(IndexTableStructure $priceTable, array $entityIds =
8585
foreach ($this->getBundleIds($entityIds) as $entityId) {
8686
$entityId = (int) $entityId;
8787
foreach ($this->getWebsiteIdsOfProduct($entityId) as $websiteId) {
88+
$websiteId = (int) $websiteId;
8889
$productIdsDisabledRequired = $this->selectionProductsDisabledRequired
89-
->getChildProductIds($entityId, (int)$websiteId);
90+
->getChildProductIds($entityId, $websiteId);
9091
if ($productIdsDisabledRequired) {
9192
$connection = $this->resourceConnection->getConnection('indexer');
9293
$select = $connection->select();
@@ -118,9 +119,8 @@ private function getWebsiteIdsOfProduct(int $entityId): array
118119
['product_in_websites' => $this->resourceConnection->getTableName('catalog_product_website')],
119120
['website_id']
120121
)->where('product_in_websites.product_id = ?', $entityId);
121-
foreach ($connection->fetchCol($select) as $websiteId) {
122-
$this->websiteIdsOfProduct[$entityId][] = (int)$websiteId;
123-
}
122+
$this->websiteIdsOfProduct[$entityId] = $connection->fetchCol($select);
123+
124124
return $this->websiteIdsOfProduct[$entityId];
125125
}
126126

app/code/Magento/Reports/Block/Adminhtml/Filter/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ protected function _initFormValues()
201201
{
202202
$data = $this->getFilterData()->getData();
203203
foreach ($data as $key => $value) {
204-
if (is_array($value) && isset($value[0])) {
205-
$data[$key] = explode(',', $value[0]);
204+
if (is_array($value) && count($value) === 1) {
205+
$data[$key] = explode(',', reset($value));
206206
}
207207
}
208208
$this->getForm()->addValues($data);

app/code/Magento/Reports/Block/Adminhtml/Sales/Coupons/Grid.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,11 @@ protected function _addCustomFilter($collection, $filterData)
211211
{
212212
if ($filterData->getPriceRuleType()) {
213213
$rulesList = $filterData->getData('rules_list');
214-
if (isset($rulesList[0])) {
215-
$rulesIds = explode(',', $rulesList[0]);
216-
$collection->addRuleFilter($rulesIds);
214+
if (is_array($rulesList) && count($rulesList) > 0) {
215+
if (count($rulesList) === 1) {
216+
$rulesList = explode(',', reset($rulesList));
217+
}
218+
$collection->addRuleFilter($rulesList);
217219
}
218220
}
219221

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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\Reports\Test\Unit\Block\Adminhtml\Filter;
9+
10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Framework\Data\Form;
12+
use Magento\Framework\Data\Form\Element\AbstractElement;
13+
use Magento\Framework\Data\Form\Element\Collection;
14+
use Magento\Framework\Data\FormFactory;
15+
use Magento\Framework\DataObject;
16+
use Magento\Framework\Registry;
17+
use Magento\Framework\UrlInterface;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
use ReflectionClass;
21+
22+
class FormTest extends TestCase
23+
{
24+
/**
25+
* @var Context|MockObject
26+
*/
27+
private $context;
28+
29+
/**
30+
* @var Registry|MockObject
31+
*/
32+
private $registry;
33+
34+
/**
35+
* @var FormFactory|MockObject
36+
*/
37+
private $formFactory;
38+
39+
/**
40+
* @var \Magento\Reports\Block\Adminhtml\Filter\Form
41+
*/
42+
private $model;
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
protected function setUp(): void
48+
{
49+
parent::setUp();
50+
$this->context = $this->createMock(Context::class);
51+
$this->registry = $this->createMock(Registry::class);
52+
$this->formFactory = $this->createMock(FormFactory::class);
53+
$this->context->method('getUrlBuilder')
54+
->willReturn($this->getMockForAbstractClass(UrlInterface::class));
55+
$this->model = new \Magento\Reports\Block\Adminhtml\Filter\Form(
56+
$this->context,
57+
$this->registry,
58+
$this->formFactory
59+
);
60+
}
61+
62+
/**
63+
* @return void
64+
* @throws \ReflectionException
65+
*/
66+
public function testMultiselectInitialValues(): void
67+
{
68+
$this->context->method('getUrlBuilder')
69+
->willReturn($this->getMockForAbstractClass(UrlInterface::class));
70+
$this->model->setData('filter_data', new DataObject(['multiselect' => ['5', '6']]));
71+
$form = $this->getMockBuilder(Form::class)
72+
->disableOriginalConstructor()
73+
->onlyMethods(['getElements'])
74+
->getMockForAbstractClass();
75+
$element = $this->getMockBuilder(AbstractElement::class)
76+
->disableOriginalConstructor()
77+
->getMockForAbstractClass();
78+
79+
$element->setId('multiselect');
80+
$form->method('getElements')->willReturn(new Collection($form));
81+
$reflection = new ReflectionClass($form);
82+
$reflectionProp = $reflection->getProperty('_allElements');
83+
$reflectionProp->setAccessible(true);
84+
$reflectionProp->setValue($form, new Collection($form));
85+
$form->addElement($element);
86+
$this->model->setForm($form);
87+
$reflection = new ReflectionClass($this->model);
88+
$reflectionMethod = $reflection->getMethod('_initFormValues');
89+
$reflectionMethod->setAccessible(true);
90+
$reflectionMethod->invoke($this->model);
91+
$this->assertEquals(['5', '6'], $this->model->getForm()->getElement('multiselect')->getValue());
92+
}
93+
}

app/code/Magento/Reports/Test/Unit/Block/Adminhtml/Sales/Coupons/GridTest.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,37 @@ protected function setUp(): void
6767
* @dataProvider getCountTotalsDataProvider
6868
*
6969
* @param string $reportType
70-
* @param int $priceRuleType
70+
* @param array|null $rulesList
7171
* @param int $collectionSize
7272
* @param bool $expectedCountTotals
73+
* @param array|null $expectedRuleFilter
7374
* @return void
7475
*/
7576
public function testGetCountTotals(
7677
string $reportType,
77-
int $priceRuleType,
78+
?array $rulesList,
7879
int $collectionSize,
79-
bool $expectedCountTotals
80+
bool $expectedCountTotals,
81+
?array $expectedRuleFilter = null
8082
): void {
8183
$filterData = new DataObject();
8284
$filterData->setData('report_type', $reportType);
8385
$filterData->setData('period_type', 'day');
8486
$filterData->setData('from', '2000-01-01');
8587
$filterData->setData('to', '2000-01-30');
8688
$filterData->setData('store_ids', '1');
87-
$filterData->setData('price_rule_type', $priceRuleType);
88-
if ($priceRuleType) {
89-
$filterData->setData('rules_list', ['0,1']);
90-
}
89+
$filterData->setData('price_rule_type', $rulesList !== null);
90+
$filterData->setData('rules_list', $rulesList);
9191
$filterData->setData('order_statuses', 'statuses');
9292
$this->model->setFilterData($filterData);
9393

9494
$resourceCollectionName = $this->model->getResourceCollectionName();
95-
$collectionMock = $this->buildBaseCollectionMock($filterData, $resourceCollectionName, $collectionSize);
95+
$collectionMock = $this->buildBaseCollectionMock(
96+
$filterData,
97+
$resourceCollectionName,
98+
$collectionSize,
99+
$expectedRuleFilter
100+
);
96101

97102
$store = $this->getMockBuilder(StoreInterface::class)
98103
->getMock();
@@ -111,23 +116,26 @@ public function testGetCountTotals(
111116
public function getCountTotalsDataProvider(): array
112117
{
113118
return [
114-
['created_at_shipment', 0, 0, false],
115-
['created_at_shipment', 0, 1, true],
116-
['updated_at_order', 0, 1, true],
117-
['updated_at_order', 1, 1, true],
119+
['created_at_shipment', null, 0, false],
120+
['created_at_shipment', null, 1, true],
121+
['updated_at_order', null, 1, true],
122+
['updated_at_order', ['1,2'], 1, true, ['1', '2']],
123+
['updated_at_order', ['1', '2'], 1, true, ['1', '2']],
118124
];
119125
}
120126

121127
/**
122-
* @param \Magento\Framework\DataObject $filterData
128+
* @param DataObject $filterData
123129
* @param string $resourceCollectionName
124130
* @param int $collectionSize
131+
* @param array|null $ruleFilter
125132
* @return MockObject
126133
*/
127134
private function buildBaseCollectionMock(
128135
DataObject $filterData,
129136
string $resourceCollectionName,
130-
int $collectionSize
137+
int $collectionSize,
138+
?array $ruleFilter
131139
): MockObject {
132140
$collectionMock = $this->getMockBuilder($resourceCollectionName)
133141
->disableOriginalConstructor()
@@ -159,7 +167,7 @@ private function buildBaseCollectionMock(
159167
if ($filterData->getData('price_rule_type')) {
160168
$collectionMock->expects($this->once())
161169
->method('addRuleFilter')
162-
->with(\explode(',', $filterData->getData('rules_list')[0]))
170+
->with($ruleFilter)
163171
->willReturnSelf();
164172
}
165173

app/code/Magento/Review/Controller/Adminhtml/Product/MassDelete.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ public function execute()
7171
} catch (LocalizedException $e) {
7272
$this->messageManager->addErrorMessage($e->getMessage());
7373
} catch (\Exception $e) {
74-
$this->messageManager->addExceptionMessage($e, __('Something went wrong while deleting these records.'));
74+
$this->messageManager->addExceptionMessage(
75+
$e,
76+
__('Something went wrong while deleting these records.')
77+
);
7578
}
7679
}
7780
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
@@ -123,6 +126,7 @@ private function getCollection(): Collection
123126
->getIdFieldName(),
124127
$this->getRequest()->getParam('reviews')
125128
);
129+
$collection->addStoreData();
126130

127131
$this->collection = $collection;
128132
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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\Review\Test\Unit\Controller\Adminhtml\Product;
9+
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\Controller\Result\Redirect;
13+
use Magento\Framework\Controller\ResultFactory;
14+
use Magento\Framework\Message\ManagerInterface;
15+
use Magento\Framework\Registry;
16+
use Magento\Review\Controller\Adminhtml\Product\MassDelete;
17+
use Magento\Review\Model\RatingFactory;
18+
use Magento\Review\Model\ResourceModel\Review as ReviewResourceModel;
19+
use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;
20+
use Magento\Review\Model\ResourceModel\Review\CollectionFactory as ReviewCollectionFactory;
21+
use Magento\Review\Model\ReviewFactory;
22+
use PHPUnit\Framework\MockObject\MockObject;
23+
use PHPUnit\Framework\TestCase;
24+
25+
class MassDeleteTest extends TestCase
26+
{
27+
/**
28+
* @var MassDelete
29+
*/
30+
private $massDelete;
31+
32+
/**
33+
* @var RequestInterface|MockObject
34+
*/
35+
private $requestMock;
36+
37+
/**
38+
* @var ReviewCollectionFactory|MockObject
39+
*/
40+
private $collectionFactoryMock;
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
protected function setUp(): void
46+
{
47+
$contextMock = $this->createMock(Context::class);
48+
$this->requestMock = $this->createMock(RequestInterface::class);
49+
$contextMock->method('getRequest')
50+
->willReturn($this->requestMock);
51+
$messageManagerMock = $this->createMock(ManagerInterface::class);
52+
$contextMock->method('getMessageManager')
53+
->willReturn($messageManagerMock);
54+
$resultFactoryMock = $this->createMock(ResultFactory::class);
55+
$contextMock->method('getResultFactory')
56+
->willReturn($resultFactoryMock);
57+
$resultMock = $this->createMock(Redirect::class);
58+
$resultFactoryMock->method('create')
59+
->willReturn($resultMock);
60+
61+
$coreRegistryMock = $this->createMock(Registry::class);
62+
$reviewFactoryMock = $this->createMock(ReviewFactory::class);
63+
$ratingFactoryMock = $this->createMock(RatingFactory::class);
64+
$this->collectionFactoryMock = $this->createMock(ReviewCollectionFactory::class);
65+
66+
$this->massDelete = new MassDelete(
67+
$contextMock,
68+
$coreRegistryMock,
69+
$reviewFactoryMock,
70+
$ratingFactoryMock,
71+
$this->collectionFactoryMock
72+
);
73+
}
74+
75+
public function testExecute(): void
76+
{
77+
$this->requestMock->expects(self::atLeastOnce())
78+
->method('getParam')
79+
->willReturnMap(
80+
[
81+
['reviews', null, [10, 20]],
82+
['ret', 'index', 'index'],
83+
]
84+
);
85+
86+
$collectionMock = $this->createMock(ReviewCollection::class);
87+
$this->collectionFactoryMock->expects(self::once())
88+
->method('create')
89+
->willReturn($collectionMock);
90+
$resource = $this->createMock(ReviewResourceModel::class);
91+
$collectionMock->method('getResource')
92+
->willReturn($resource);
93+
$resource->method('getIdFieldName')
94+
->willReturn('id');
95+
$collectionMock->expects(self::once())
96+
->method('addFieldToFilter')
97+
->with('main_table.id', [10, 20])
98+
->willReturnSelf();
99+
$collectionMock->expects(self::once())
100+
->method('addStoreData')
101+
->willReturnSelf();
102+
103+
$this->massDelete->execute();
104+
}
105+
}

dev/tests/integration/testsuite/Magento/Bundle/Model/ResourceModel/Indexer/PriceTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Bundle\Model\ResourceModel\Indexer;
88

9+
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
910
use Magento\Catalog\Api\ProductRepositoryInterface;
1011
use Magento\Catalog\Model\Indexer\Product\Price;
1112
use Magento\Customer\Model\Group;
@@ -14,6 +15,7 @@
1415
use Magento\Store\Api\WebsiteRepositoryInterface;
1516
use Magento\TestFramework\Catalog\Model\Product\Price\GetPriceIndexDataByProductId;
1617
use Magento\CatalogInventory\Model\Indexer\Stock;
18+
use Magento\TestFramework\Fixture\DataFixture;
1719
use Magento\TestFramework\Helper\Bootstrap;
1820
use PHPUnit\Framework\TestCase;
1921

@@ -91,6 +93,18 @@ public function testExecuteRowWithShowOutOfStock(): void
9193
$this->assertIndexTableData($bundleProduct->getId(), $expectedPrices);
9294
}
9395

96+
#[
97+
DataFixture(
98+
BundleProductFixture::class,
99+
['sku' => 'bundle1', 'extension_attributes' => ['website_ids' => []]]
100+
),
101+
]
102+
public function testExecuteForBundleWithoutWebsites(): void
103+
{
104+
$bundleProduct = $this->productRepository->get('bundle1');
105+
$this->indexer->executeRow($bundleProduct->getId());
106+
}
107+
94108
/**
95109
* Asserts price data in index table.
96110
*

0 commit comments

Comments
 (0)