FormTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Block;
  7. use Magento\Framework\App\Area;
  8. use Magento\Framework\App\Config\Value;
  9. use Magento\Framework\App\ReinitableConfig;
  10. use Magento\Framework\App\State;
  11. use Magento\TestFramework\ObjectManager;
  12. class FormTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var ObjectManager;
  16. */
  17. private $objectManager;
  18. protected function setUp()
  19. {
  20. $this->objectManager = $this->getObjectManager();
  21. parent::setUp();
  22. }
  23. /**
  24. * @magentoDbIsolation enabled
  25. * @magentoDataFixture Magento/Review/_files/config.php
  26. * @dataProvider getCorrectFlagDataProvider
  27. */
  28. public function testGetCorrectFlag(
  29. $path,
  30. $scope,
  31. $scopeId,
  32. $value,
  33. $expectedResult
  34. ) {
  35. /** @var State $appState */
  36. $appState = $this->objectManager->get(State::class);
  37. $appState->setAreaCode(Area::AREA_FRONTEND);
  38. /** @var Value $config */
  39. $config = $this->objectManager->create(Value::class);
  40. $config->setPath($path);
  41. $config->setScope($scope);
  42. $config->setScopeId($scopeId);
  43. $config->setValue($value);
  44. $config->save();
  45. /** @var ReinitableConfig $reinitableConfig */
  46. $reinitableConfig = $this->objectManager->create(ReinitableConfig::class);
  47. $reinitableConfig->reinit();
  48. /** @var \Magento\Review\Block\Form $form */
  49. $form = $this->objectManager->create(\Magento\Review\Block\Form::class);
  50. $result = $form->getAllowWriteReviewFlag();
  51. $this->assertEquals($result, $expectedResult);
  52. }
  53. public function getCorrectFlagDataProvider()
  54. {
  55. return [
  56. [
  57. 'path' => 'catalog/review/allow_guest',
  58. 'scope' => 'websites',
  59. 'scopeId' => '1',
  60. 'value' => 0,
  61. 'expectedResult' => false,
  62. ],
  63. [
  64. 'path' => 'catalog/review/allow_guest',
  65. 'scope' => 'websites',
  66. 'scopeId' => '1',
  67. 'value' => 1,
  68. 'expectedResult' => true
  69. ]
  70. ];
  71. }
  72. private function getObjectManager()
  73. {
  74. return \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  75. }
  76. }