DumpConfigSourceAggregatedTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Test\Unit\App\Config\Source;
  7. use Magento\Config\App\Config\Source\DumpConfigSourceAggregated;
  8. use Magento\Config\Model\Config\Export\ExcludeList;
  9. use Magento\Config\Model\Config\TypePool;
  10. use Magento\Framework\App\Config\ConfigSourceInterface;
  11. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  12. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  13. class DumpConfigSourceAggregatedTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var ConfigSourceInterface|MockObject
  17. */
  18. private $sourceMock;
  19. /**
  20. * @var ConfigSourceInterface|MockObject
  21. */
  22. private $sourceTwoMock;
  23. /**
  24. * @var ExcludeList|MockObject
  25. */
  26. private $excludeListMock;
  27. /**
  28. * @var TypePool|MockObject
  29. */
  30. private $typePoolMock;
  31. /**
  32. * @var ObjectManagerHelper
  33. */
  34. private $objectManagerHelper;
  35. /**
  36. * @var DumpConfigSourceAggregated
  37. */
  38. private $model;
  39. public function setUp()
  40. {
  41. $this->objectManagerHelper = new ObjectManagerHelper($this);
  42. $this->sourceMock = $this->getMockBuilder(ConfigSourceInterface::class)
  43. ->getMockForAbstractClass();
  44. $this->sourceTwoMock = $this->getMockBuilder(ConfigSourceInterface::class)
  45. ->getMockForAbstractClass();
  46. $this->excludeListMock = $this->getMockBuilder(ExcludeList::class)
  47. ->disableOriginalConstructor()
  48. ->getMock();
  49. $this->typePoolMock = $this->getMockBuilder(TypePool::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $this->sourceMock->expects($this->once())
  53. ->method('get')
  54. ->with('')
  55. ->willReturn([
  56. 'default' => [
  57. 'web' => [
  58. 'unsecure' => ['without_type' => 'some_value'],
  59. 'secure' => ['environment_type' => 'some_environment_value'],
  60. 'some_key' => [
  61. 'without_type' => 'some_value',
  62. 'sensitive_type' => 'some_sensitive_value'
  63. ],
  64. ]
  65. ],
  66. 'test' => [
  67. 'test' => [
  68. 'test1' => [
  69. 'test2' => ['without_type' => 5]
  70. ]
  71. ]
  72. ]
  73. ]);
  74. $this->sourceTwoMock->expects($this->once())
  75. ->method('get')
  76. ->with('')
  77. ->willReturn([
  78. 'default' => [
  79. 'web' => [
  80. 'another_key' => ['sensitive_type' => 'some_sensitive_value']
  81. ]
  82. ]
  83. ]);
  84. $this->typePoolMock->expects($this->any())
  85. ->method('isPresent')
  86. ->willReturnMap([
  87. ['web/unsecure/without_type', TypePool::TYPE_SENSITIVE, false],
  88. ['web/secure/environment_type', TypePool::TYPE_ENVIRONMENT, true],
  89. ['test1/test2/test/without_type', TypePool::TYPE_SENSITIVE, false],
  90. ['web/some_key/without_type', TypePool::TYPE_ENVIRONMENT, false],
  91. ['web/some_key/sensitive_type', TypePool::TYPE_SENSITIVE, true],
  92. ['web/another_key/sensitive_type', TypePool::TYPE_SENSITIVE, true],
  93. ]);
  94. $this->model = new DumpConfigSourceAggregated(
  95. $this->excludeListMock,
  96. [
  97. [
  98. 'source' => $this->sourceTwoMock,
  99. 'sortOrder' => 100
  100. ],
  101. [
  102. 'source' => $this->sourceMock,
  103. 'sortOrder' => 10
  104. ],
  105. ],
  106. $this->typePoolMock,
  107. [
  108. 'default' => 'include',
  109. 'sensitive' => 'exclude',
  110. 'environment' => 'exclude',
  111. ]
  112. );
  113. }
  114. public function testGet()
  115. {
  116. $this->assertEquals(
  117. [
  118. 'test' => [
  119. 'test' => [
  120. 'test1' => [
  121. 'test2' => ['without_type' => 5]
  122. ]
  123. ],
  124. ],
  125. 'default' => [
  126. 'web' => [
  127. 'unsecure' => [
  128. 'without_type' => 'some_value',
  129. ],
  130. 'some_key' => [
  131. 'without_type' => 'some_value',
  132. ],
  133. ]
  134. ],
  135. ],
  136. $this->model->get('')
  137. );
  138. }
  139. public function testGetWithExcludeDefault()
  140. {
  141. $this->objectManagerHelper->setBackwardCompatibleProperty(
  142. $this->model,
  143. 'rules',
  144. [
  145. 'default' => 'exclude',
  146. 'sensitive' => 'include',
  147. 'environment' => 'include',
  148. ]
  149. );
  150. $this->assertEquals(
  151. [
  152. 'default' => [
  153. 'web' => [
  154. 'secure' => ['environment_type' => 'some_environment_value'],
  155. 'some_key' => [
  156. 'sensitive_type' => 'some_sensitive_value'
  157. ],
  158. 'another_key' => ['sensitive_type' => 'some_sensitive_value']
  159. ]
  160. ],
  161. ],
  162. $this->model->get('')
  163. );
  164. }
  165. public function testGetExcludedFields()
  166. {
  167. $this->assertEquals(
  168. [
  169. 'web/secure/environment_type',
  170. 'web/some_key/sensitive_type',
  171. 'web/another_key/sensitive_type'
  172. ],
  173. $this->model->getExcludedFields()
  174. );
  175. }
  176. }