Skip to content

Commit 326b87d

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop-sidecar-pr9' into 2.4-develop-sidecar-pr9
2 parents 9c00ec7 + c2a0175 commit 326b87d

File tree

2 files changed

+232
-0
lines changed

2 files changed

+232
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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\CatalogInventory\Model\Config\Backend;
9+
10+
use Magento\CatalogInventory\Model\Configuration;
11+
use Magento\CatalogInventory\Model\Indexer\Stock\Processor;
12+
use Magento\CatalogInventory\Model\Stock;
13+
use Magento\Config\Model\Config\BackendFactory;
14+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
15+
use Magento\Framework\Indexer\StateInterface;
16+
use Magento\Framework\ObjectManagerInterface;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Checks that the backorders config backend model is working correctly
22+
*/
23+
class BackordersTest extends TestCase
24+
{
25+
/** @var ObjectManagerInterface */
26+
private $objectManager;
27+
28+
/** @var Backorders */
29+
private $backorders;
30+
31+
/** @var BackendFactory */
32+
private $backendFactory;
33+
34+
/** @var MutableScopeConfigInterface */
35+
private $mutableConfig;
36+
37+
/** @var Processor */
38+
private $stockIndexerProcessor;
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
protected function setUp(): void
44+
{
45+
$this->objectManager = Bootstrap::getObjectManager();
46+
$this->backendFactory = $this->objectManager->create(BackendFactory::class);
47+
$this->backorders = $this->backendFactory->create(Backorders::class, [
48+
'data' => [
49+
'path' => Configuration::XML_PATH_BACKORDERS,
50+
]
51+
]);
52+
$this->mutableConfig = $this->objectManager->get(MutableScopeConfigInterface::class);
53+
$this->stockIndexerProcessor = $this->objectManager->get(Processor::class);
54+
}
55+
56+
/**
57+
* @dataProvider afterSaveDataProvider
58+
* @param int $value
59+
* @param int $currentValue
60+
* @param string $expectedIndexerStatus
61+
* @magentoDbIsolation disabled
62+
* @return void
63+
*/
64+
public function testAfterSave(int $value, int $currentValue, string $expectedIndexerStatus): void
65+
{
66+
$this->stockIndexerProcessor->reindexAll();
67+
$this->mutableConfig->setValue(Configuration::XML_PATH_BACKORDERS, $currentValue);
68+
$this->backorders->setValue((string)$value);
69+
$this->backorders->afterSave();
70+
71+
$this->assertEquals($expectedIndexerStatus, $this->stockIndexerProcessor->getIndexer()->getStatus());
72+
}
73+
74+
/**
75+
* Data provider for testAfterSave
76+
*
77+
* @return array
78+
*/
79+
public function afterSaveDataProvider(): array
80+
{
81+
return [
82+
'set_backorders' => [
83+
'value' => Stock::BACKORDERS_YES_NONOTIFY,
84+
'current_value' => Stock::BACKORDERS_NO,
85+
'expected_indexer_status' => StateInterface::STATUS_INVALID,
86+
],
87+
'unset_backorders' => [
88+
'value' => Stock::BACKORDERS_NO,
89+
'current_value' => Stock::BACKORDERS_YES_NONOTIFY,
90+
'expected_indexer_status' => StateInterface::STATUS_INVALID,
91+
],
92+
'same_backorders' => [
93+
'value' => Stock::BACKORDERS_YES_NONOTIFY,
94+
'current_value' => Stock::BACKORDERS_YES_NONOTIFY,
95+
'expected_indexer_status' => StateInterface::STATUS_VALID,
96+
],
97+
];
98+
}
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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\CatalogInventory\Ui\DataProvider\Product;
9+
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
13+
use Magento\Framework\View\Element\UiComponentFactory;
14+
use Magento\Framework\View\Element\UiComponentInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Checks that the product quantity filter is working correctly
20+
*
21+
* @magentoAppArea adminhtml
22+
*/
23+
class AddQuantityFilterToCollectionTest extends TestCase
24+
{
25+
/** @var ObjectManagerInterface */
26+
private $objectManager;
27+
28+
/** @var UiComponentFactory */
29+
private $componentFactory;
30+
31+
/** @var RequestInterface */
32+
private $request;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp(): void
38+
{
39+
parent::setUp();
40+
41+
$this->objectManager = Bootstrap::getObjectManager();
42+
$this->request = $this->objectManager->get(RequestInterface::class);
43+
$this->componentFactory = $this->objectManager->get(UiComponentFactory::class);
44+
}
45+
46+
/**
47+
* @dataProvider quantityFilterProvider
48+
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
49+
* @param array $filter
50+
* @param array $expectedProducts
51+
* @return void
52+
*/
53+
public function testQuantityFilter(array $filter, array $expectedProducts): void
54+
{
55+
$this->request->setParams([ContextInterface::FILTER_VAR => $filter]);
56+
$dataProviderData = $this->getComponentProvidedData('product_listing');
57+
$actualProducts = array_column($dataProviderData['items'], 'sku');
58+
$this->assertEquals($expectedProducts, $actualProducts, 'Expected products do not match actual products!');
59+
}
60+
61+
/**
62+
* Data provider for testQuantityFilter
63+
*
64+
* @return array
65+
*/
66+
public function quantityFilterProvider(): array
67+
{
68+
return [
69+
'from' => [
70+
'filter' => [
71+
'qty' => [
72+
'from' => 100,
73+
],
74+
],
75+
'expected_products' => [
76+
'simple1',
77+
'simple3',
78+
],
79+
],
80+
'to' => [
81+
'filter' => [
82+
'qty' => [
83+
'to' => 100,
84+
],
85+
],
86+
'expected_products' => [
87+
'simple1',
88+
'simple2',
89+
],
90+
],
91+
'both' => [
92+
'filter' => [
93+
'qty' => [
94+
'from' => 60,
95+
'to' => 130,
96+
],
97+
],
98+
'expected_products' => [
99+
'simple1',
100+
],
101+
],
102+
];
103+
}
104+
105+
/**
106+
* Call prepare method in the child components
107+
*
108+
* @param UiComponentInterface $component
109+
* @return void
110+
*/
111+
private function prepareChildComponents(UiComponentInterface $component): void
112+
{
113+
foreach ($component->getChildComponents() as $child) {
114+
$this->prepareChildComponents($child);
115+
}
116+
117+
$component->prepare();
118+
}
119+
120+
/**
121+
* Get component provided data
122+
*
123+
* @param string $namespace
124+
* @return array
125+
*/
126+
private function getComponentProvidedData(string $namespace): array
127+
{
128+
$component = $this->componentFactory->create($namespace);
129+
$this->prepareChildComponents($component);
130+
131+
return $component->getContext()->getDataProvider()->getData();
132+
}
133+
}

0 commit comments

Comments
 (0)