Skip to content

Commit 16826bd

Browse files
committed
MC-39687: Create automated test for: "Set backorders "Allow Qty Below 0" and check indexers"
1 parent 1c3837c commit 16826bd

File tree

1 file changed

+99
-0
lines changed
  • dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Config/Backend

1 file changed

+99
-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+
}

0 commit comments

Comments
 (0)