PriceIndexerDimensionsModeSetCommandTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Setup\Console\Command;
  7. use Magento\Catalog\Model\Indexer\Product\Price\DimensionModeConfiguration;
  8. use Symfony\Component\Console\Tester\CommandTester;
  9. use Magento\Framework\Console\Cli;
  10. use Magento\Framework\ObjectManagerInterface;
  11. use Magento\TestFramework\Helper\Bootstrap;
  12. /**
  13. * Test command that sets indexer mode for catalog_product_price indexer
  14. */
  15. class PriceIndexerDimensionsModeSetCommandTest extends \Magento\TestFramework\Indexer\TestCase
  16. {
  17. /** @var ObjectManagerInterface */
  18. private $objectManager;
  19. /** @var \Magento\Indexer\Console\Command\IndexerSetDimensionsModeCommand */
  20. private $command;
  21. /** @var CommandTester */
  22. private $commandTester;
  23. /**
  24. * setUp
  25. */
  26. public function setUp()
  27. {
  28. $this->objectManager = Bootstrap::getObjectManager();
  29. $this->objectManager->get(\Magento\TestFramework\App\Config::class)->clean();
  30. $this->command = $this->objectManager->create(
  31. \Magento\Indexer\Console\Command\IndexerSetDimensionsModeCommand::class
  32. );
  33. $this->commandTester = new CommandTester($this->command);
  34. parent::setUp();
  35. }
  36. /**
  37. * setUpBeforeClass
  38. */
  39. public static function setUpBeforeClass()
  40. {
  41. $db = Bootstrap::getInstance()->getBootstrap()
  42. ->getApplication()
  43. ->getDbInstance();
  44. if (!$db->isDbDumpExists()) {
  45. throw new \LogicException('DB dump does not exist.');
  46. }
  47. $db->restoreFromDbDump();
  48. parent::setUpBeforeClass();
  49. }
  50. /**
  51. * @magentoAppArea adminhtml
  52. * @magentoAppIsolation enabled
  53. *
  54. * @param string $previousMode
  55. * @param string $currentMode
  56. * @dataProvider modesDataProvider
  57. */
  58. public function testSwitchMode($previousMode, $currentMode)
  59. {
  60. $this->commandTester->execute(
  61. [
  62. 'indexer' => 'catalog_product_price',
  63. 'mode' => $currentMode,
  64. ]
  65. );
  66. $expectedOutput = 'Dimensions mode for indexer "Product Price" was changed from \''
  67. . $previousMode . '\' to \'' . $currentMode . '\'' . PHP_EOL;
  68. $actualOutput = $this->commandTester->getDisplay();
  69. $this->assertContains($expectedOutput, $actualOutput);
  70. static::assertEquals(
  71. Cli::RETURN_SUCCESS,
  72. $this->commandTester->getStatusCode(),
  73. $this->commandTester->getDisplay(true)
  74. );
  75. }
  76. /**
  77. * Modes data provider
  78. * @return array
  79. */
  80. public function modesDataProvider()
  81. {
  82. return [
  83. [DimensionModeConfiguration::DIMENSION_NONE, DimensionModeConfiguration::DIMENSION_WEBSITE],
  84. [DimensionModeConfiguration::DIMENSION_WEBSITE, DimensionModeConfiguration::DIMENSION_CUSTOMER_GROUP],
  85. [
  86. DimensionModeConfiguration::DIMENSION_CUSTOMER_GROUP,
  87. DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP
  88. ],
  89. [
  90. DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP,
  91. DimensionModeConfiguration::DIMENSION_NONE
  92. ],
  93. [
  94. DimensionModeConfiguration::DIMENSION_NONE,
  95. DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP
  96. ],
  97. [
  98. DimensionModeConfiguration::DIMENSION_WEBSITE_AND_CUSTOMER_GROUP,
  99. DimensionModeConfiguration::DIMENSION_CUSTOMER_GROUP
  100. ],
  101. [DimensionModeConfiguration::DIMENSION_CUSTOMER_GROUP, DimensionModeConfiguration::DIMENSION_WEBSITE],
  102. [DimensionModeConfiguration::DIMENSION_WEBSITE, DimensionModeConfiguration::DIMENSION_NONE],
  103. ];
  104. }
  105. /**
  106. * @magentoAppArea adminhtml
  107. * @magentoAppIsolation enabled
  108. */
  109. public function testSwitchModeForSameMode()
  110. {
  111. $this->commandTester->execute(
  112. [
  113. 'indexer' => 'catalog_product_price',
  114. 'mode' => DimensionModeConfiguration::DIMENSION_NONE
  115. ]
  116. );
  117. $expectedOutput = 'Dimensions mode for indexer "Product Price" has not been changed' . PHP_EOL;
  118. $actualOutput = $this->commandTester->getDisplay();
  119. $this->assertContains($expectedOutput, $actualOutput);
  120. static::assertEquals(
  121. Cli::RETURN_SUCCESS,
  122. $this->commandTester->getStatusCode(),
  123. $this->commandTester->getDisplay(true)
  124. );
  125. }
  126. /**
  127. * @magentoAppArea adminhtml
  128. * @magentoAppIsolation enabled
  129. *
  130. * @expectedException \InvalidArgumentException
  131. */
  132. public function testSwitchModeWithInvalidArgument()
  133. {
  134. $this->commandTester->execute(
  135. [
  136. 'indexer' => 'indexer_not_valid'
  137. ]
  138. );
  139. }
  140. }