EnvironmentTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Test\Unit\Model\Placeholder;
  7. use Magento\Config\Model\Placeholder\Environment;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\App\DeploymentConfig;
  10. use Magento\Framework\Config\ConfigOptionsListConstants;
  11. use \PHPUnit_Framework_MockObject_MockObject as Mock;
  12. /**
  13. * Class EnvironmentTest
  14. */
  15. class EnvironmentTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var Environment
  19. */
  20. private $model;
  21. /**
  22. * @var DeploymentConfig|Mock
  23. */
  24. private $deploymentConfigMock;
  25. protected function setUp()
  26. {
  27. $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
  28. ->disableOriginalConstructor()
  29. ->getMock();
  30. $this->model = new Environment(
  31. $this->deploymentConfigMock
  32. );
  33. }
  34. /**
  35. * @param string $path
  36. * @param string $scope
  37. * @param string $scopeId
  38. * @param string $expected
  39. * @dataProvider getGenerateDataProvider
  40. */
  41. public function testGenerate($path, $scope, $scopeId, $expected)
  42. {
  43. $this->assertSame(
  44. $expected,
  45. $this->model->generate($path, $scope, $scopeId)
  46. );
  47. }
  48. /**
  49. * @return array
  50. */
  51. public function getGenerateDataProvider()
  52. {
  53. return [
  54. [
  55. 'web/unsecure/base_url',
  56. ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
  57. null,
  58. Environment::PREFIX . 'DEFAULT__WEB__UNSECURE__BASE_URL'
  59. ],
  60. [
  61. 'web/unsecure/base_url',
  62. 'web',
  63. 'test',
  64. Environment::PREFIX . 'WEB__TEST__WEB__UNSECURE__BASE_URL'
  65. ],
  66. [
  67. 'web/unsecure/base_url',
  68. 'web',
  69. null,
  70. Environment::PREFIX . 'WEB__WEB__UNSECURE__BASE_URL'
  71. ],
  72. ];
  73. }
  74. /**
  75. * @param string $placeholder
  76. * @param bool $expected
  77. * @dataProvider getIsPlaceholderDataProvider
  78. */
  79. public function testIsApplicable($placeholder, $expected)
  80. {
  81. $this->assertSame(
  82. $expected,
  83. $this->model->isApplicable($placeholder)
  84. );
  85. }
  86. /**
  87. * @return array
  88. */
  89. public function getIsPlaceholderDataProvider()
  90. {
  91. return [
  92. [Environment::PREFIX . 'TEST', true],
  93. ['TEST', false],
  94. [Environment::PREFIX . 'TEST_test', true],
  95. [Environment::PREFIX . '-:A', false],
  96. [Environment::PREFIX . '_A', false],
  97. [Environment::PREFIX . 'A@#$', false]
  98. ];
  99. }
  100. /**
  101. * @param string $template
  102. * @param string $expected
  103. * @dataProvider restoreDataProvider
  104. */
  105. public function testRestore($template, $expected)
  106. {
  107. $this->assertSame(
  108. $expected,
  109. $this->model->restore($template)
  110. );
  111. }
  112. /**
  113. * @return array
  114. */
  115. public function restoreDataProvider()
  116. {
  117. return [
  118. [Environment::PREFIX . 'TEST__CONFIG', 'test/config'],
  119. [Environment::PREFIX . 'TEST__CONFIG__VALUE', 'test/config/value'],
  120. [Environment::PREFIX . 'TEST__CONFIG_VALUE', 'test/config_value'],
  121. ];
  122. }
  123. }