Skip to content

Commit dc7207b

Browse files
committed
MAGETWO-92402: Write tests
1 parent ce9cfa4 commit dc7207b

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

dev/tests/integration/framework/Magento/TestFramework/Annotation/IndexerDimensionMode.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
namespace Magento\TestFramework\Annotation;
88

99
use Magento\Catalog\Model\Indexer\Product\Price\ModeSwitcher;
10+
use Magento\Framework\App\Cache\TypeListInterface;
1011
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
1113
use Magento\TestFramework\Application;
1214
use Magento\TestFramework\App\Config;
1315
use Magento\TestFramework\Helper\Bootstrap;
@@ -19,7 +21,10 @@
1921
*/
2022
class IndexerDimensionMode
2123
{
22-
private $modeSwithcer;
24+
protected $cacheTypeList;
25+
private $configReader;
26+
27+
private $modeSwitcher;
2328

2429
private $configWriter;
2530

@@ -36,28 +41,53 @@ public function __construct(Application $application)
3641

3742
private function restoreDb()
3843
{
44+
$this->db = Bootstrap::getInstance()->getBootstrap()
45+
->getApplication()
46+
->getDbInstance();
3947
$this->db->restoreFromDbDump();
48+
$this->cacheTypeList->cleanType('config');
49+
$this->objectManager->get(Config::class)->clean();
4050
}
4151

4252
private function initSwicher()
4353
{
44-
if (!$this->modeSwithcer) {
54+
if (!$this->modeSwitcher) {
4555
$this->objectManager = Bootstrap::getObjectManager();
46-
$this->modeSwithcer = $this->objectManager->get(ModeSwitcher::class);
56+
$this->modeSwitcher = $this->objectManager->get(ModeSwitcher::class);
4757
$this->configWriter = $this->objectManager->get(ConfigInterface::class);
58+
$this->configReader = $this->objectManager->get(ScopeConfigInterface::class);
59+
$this->cacheTypeList = $this->objectManager->get(TypeListInterface::class);
4860
}
4961
}
5062

5163
/**
5264
* @param string $mode
5365
*/
54-
private function setDimensionMode($mode = DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP)
66+
private function setDimensionMode($mode, $test)
5567
{
5668
$this->initSwicher();
57-
$this->modeSwithcer->createTables($mode);
58-
$this->modeSwithcer->moveData($mode, DimensionModeConfiguration::DIMENSION_NONE);
59-
$this->configWriter->saveConfig(ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE, $mode);
60-
$this->objectManager->get(Config::class)->clean();
69+
70+
$this->configReader->clean();
71+
$previousMode = $this->configReader->getValue(ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE) ?:
72+
DimensionModeConfiguration::DIMENSION_NONE;
73+
74+
if ($previousMode !== $mode) {
75+
//Create new tables and move data
76+
$this->modeSwitcher->createTables($mode);
77+
$this->modeSwitcher->moveData($mode, $previousMode);
78+
79+
//Change config options
80+
$this->configWriter->saveConfig(ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE, $mode);
81+
$this->cacheTypeList->cleanType('config');
82+
$this->objectManager->get(Config::class)->clean();
83+
84+
//Delete old tables
85+
$this->modeSwitcher->dropTables($previousMode);
86+
87+
} else {
88+
$this->fail('Dimensions mode for indexer has not been changed', $test);
89+
}
90+
6191
}
6292

6393
/**
@@ -85,7 +115,7 @@ public function startTest(TestCase $test)
85115

86116
if ($annotations[0] == 'price') {
87117
$this->isDimensionMode = true;
88-
$this->setDimensionMode();
118+
$this->setDimensionMode(DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP, $test);
89119
}
90120
}
91121

@@ -99,7 +129,6 @@ public function endTest(TestCase $test)
99129
{
100130
if ($this->isDimensionMode) {
101131
$this->restoreDb();
102-
$this->objectManager->get(Config::class)->clean();
103132
$this->isDimensionMode = false;
104133
}
105134
}

dev/tests/integration/framework/Magento/TestFramework/Bootstrap/DocBlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ protected function _getSubscribers(\Magento\TestFramework\Application $applicati
5454
new \Magento\TestFramework\Isolation\WorkingDirectory(),
5555
new \Magento\TestFramework\Isolation\DeploymentConfig(),
5656
new \Magento\TestFramework\Annotation\AppIsolation($application),
57+
new \Magento\TestFramework\Annotation\IndexerDimensionMode($application),
5758
new \Magento\TestFramework\Isolation\AppConfig(),
5859
new \Magento\TestFramework\Annotation\ConfigFixture(),
5960
new \Magento\TestFramework\Annotation\DataFixtureBeforeTransaction($this->_fixturesBaseDir),
@@ -70,7 +71,6 @@ protected function _getSubscribers(\Magento\TestFramework\Application $applicati
7071
new \Magento\TestFramework\Annotation\Cache($application),
7172
new \Magento\TestFramework\Annotation\AdminConfigFixture(),
7273
new \Magento\TestFramework\Annotation\ConfigFixture(),
73-
new \Magento\TestFramework\Annotation\IndexerDimensionMode($application),
7474
];
7575
}
7676
}

0 commit comments

Comments
 (0)