1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\InventoryIndexer\Test\Integration;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
use Magento\InventoryIndexer\Indexer\InventoryIndexer;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Tests Indexer invalidation after Source enabled or disabled.
*/
class InvalidateAfterEnablingOrDisablingSourceTest extends TestCase
{
/**
* @var SourceRepositoryInterface
*/
private $sourceRepository;
/**
* @var IndexerInterface
*/
private $indexer;
protected function setUp()
{
$this->sourceRepository = Bootstrap::getObjectManager()->get(SourceRepositoryInterface::class);
/** @var IndexerRegistry $indexerRegistry */
$indexerRegistry = Bootstrap::getObjectManager()->get(IndexerRegistry::class);
$this->indexer = $indexerRegistry->get(InventoryIndexer::INDEXER_ID);
}
/**
* Tests Source enabling and disabling when both Stocks and Source Items are connected to current Source.
*
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*
* @dataProvider indexerInvalidationDataProvider
* @param string $sourceCode
* @param bool $enable
* @param bool $expectedValid
*
* @magentoDbIsolation disabled
*/
public function testIndexerInvalidation(string $sourceCode, bool $enable, bool $expectedValid)
{
$this->setSourceEnabledStatus($sourceCode, $enable);
$this->assertEquals($expectedValid, $this->indexer->isValid());
}
/**
* @return array
*/
public function indexerInvalidationDataProvider(): array
{
return [
['eu-1', true, true],
['eu-1', false, false],
['eu-disabled', true, false],
['eu-disabled', false, true],
];
}
/**
* Tests Source enabling and disabling when no Stocks or Source Items are connected to Source.
*
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*
* @dataProvider sourceDoesNotHaveAllRelationsDataProvider
* @param string $sourceCode
* @param bool $enable
* @param bool $expectedValid
*/
public function testIndexerInvalidationIfSourceDoesNotHaveAnyRelations(
string $sourceCode,
bool $enable,
bool $expectedValid
) {
$this->setSourceEnabledStatus($sourceCode, $enable);
$this->assertEquals($expectedValid, $this->indexer->isValid());
}
/**
* Tests Source enabling and disabling when no Stocks are connected to current Source.
*
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*
* @dataProvider sourceDoesNotHaveAllRelationsDataProvider
* @param string $sourceCode
* @param bool $enable
* @param bool $expectedValid
*/
public function testIndexerInvalidationIfSourceDoesNotHaveStockLinks(
string $sourceCode,
bool $enable,
bool $expectedValid
) {
$this->setSourceEnabledStatus($sourceCode, $enable);
$this->assertEquals($expectedValid, $this->indexer->isValid());
}
/**
* Tests Source enabling and disabling when no Source Items are connected to current Source.
*
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
*
* @dataProvider sourceDoesNotHaveAllRelationsDataProvider
* @param string $sourceCode
* @param bool $enable
* @param bool $expectedValid
*
* @magentoDbIsolation disabled
*/
public function testIndexerInvalidationIfSourceDoesNotHaveSourceItems(
string $sourceCode,
bool $enable,
bool $expectedValid
) {
$this->setSourceEnabledStatus($sourceCode, $enable);
$this->assertEquals($expectedValid, $this->indexer->isValid());
}
/**
* @return array
*/
public function sourceDoesNotHaveAllRelationsDataProvider(): array
{
return [
['eu-1', true, true],
['eu-1', false, true],
['eu-disabled', true, true],
['eu-disabled', false, true],
];
}
/**
* @param string $sourceCode
* @param bool $enable
* @return void
*/
private function setSourceEnabledStatus(string $sourceCode, bool $enable)
{
$source = $this->sourceRepository->get($sourceCode);
$source->setEnabled($enable);
$this->sourceRepository->save($source);
}
}