Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DumpConfigSourceAggregatedTest.php
Go to the documentation of this file.
1 <?php
7 
13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 
15 class DumpConfigSourceAggregatedTest extends \PHPUnit\Framework\TestCase
16 {
20  private $sourceMock;
21 
25  private $sourceTwoMock;
26 
30  private $excludeListMock;
31 
35  private $typePoolMock;
36 
40  private $objectManagerHelper;
41 
45  private $model;
46 
47  public function setUp()
48  {
49  $this->objectManagerHelper = new ObjectManagerHelper($this);
50  $this->sourceMock = $this->getMockBuilder(ConfigSourceInterface::class)
51  ->getMockForAbstractClass();
52  $this->sourceTwoMock = $this->getMockBuilder(ConfigSourceInterface::class)
53  ->getMockForAbstractClass();
54  $this->excludeListMock = $this->getMockBuilder(ExcludeList::class)
55  ->disableOriginalConstructor()
56  ->getMock();
57  $this->typePoolMock = $this->getMockBuilder(TypePool::class)
58  ->disableOriginalConstructor()
59  ->getMock();
60 
61  $this->sourceMock->expects($this->once())
62  ->method('get')
63  ->with('')
64  ->willReturn([
65  'default' => [
66  'web' => [
67  'unsecure' => ['without_type' => 'some_value'],
68  'secure' => ['environment_type' => 'some_environment_value'],
69  'some_key' => [
70  'without_type' => 'some_value',
71  'sensitive_type' => 'some_sensitive_value'
72  ],
73  ]
74  ],
75  'test' => [
76  'test' => [
77  'test1' => [
78  'test2' => ['without_type' => 5]
79  ]
80  ]
81  ]
82  ]);
83 
84  $this->sourceTwoMock->expects($this->once())
85  ->method('get')
86  ->with('')
87  ->willReturn([
88  'default' => [
89  'web' => [
90  'another_key' => ['sensitive_type' => 'some_sensitive_value']
91  ]
92  ]
93  ]);
94 
95  $this->typePoolMock->expects($this->any())
96  ->method('isPresent')
97  ->willReturnMap([
98  ['web/unsecure/without_type', TypePool::TYPE_SENSITIVE, false],
99  ['web/secure/environment_type', TypePool::TYPE_ENVIRONMENT, true],
100  ['test1/test2/test/without_type', TypePool::TYPE_SENSITIVE, false],
101  ['web/some_key/without_type', TypePool::TYPE_ENVIRONMENT, false],
102  ['web/some_key/sensitive_type', TypePool::TYPE_SENSITIVE, true],
103  ['web/another_key/sensitive_type', TypePool::TYPE_SENSITIVE, true],
104  ]);
105 
106  $this->model = new DumpConfigSourceAggregated(
107  $this->excludeListMock,
108  [
109  [
110  'source' => $this->sourceTwoMock,
111  'sortOrder' => 100
112  ],
113  [
114  'source' => $this->sourceMock,
115  'sortOrder' => 10
116  ],
117 
118  ],
119  $this->typePoolMock,
120  [
121  'default' => 'include',
122  'sensitive' => 'exclude',
123  'environment' => 'exclude',
124  ]
125  );
126  }
127 
128  public function testGet()
129  {
130  $this->assertEquals(
131  [
132  'test' => [
133  'test' => [
134  'test1' => [
135  'test2' => ['without_type' => 5]
136  ]
137  ],
138  ],
139  'default' => [
140  'web' => [
141  'unsecure' => [
142  'without_type' => 'some_value',
143  ],
144  'some_key' => [
145  'without_type' => 'some_value',
146  ],
147  ]
148  ],
149  ],
150  $this->model->get('')
151  );
152  }
153 
154  public function testGetWithExcludeDefault()
155  {
156  $this->objectManagerHelper->setBackwardCompatibleProperty(
157  $this->model,
158  'rules',
159  [
160  'default' => 'exclude',
161  'sensitive' => 'include',
162  'environment' => 'include',
163  ]
164  );
165 
166  $this->assertEquals(
167  [
168  'default' => [
169  'web' => [
170  'secure' => ['environment_type' => 'some_environment_value'],
171  'some_key' => [
172  'sensitive_type' => 'some_sensitive_value'
173  ],
174  'another_key' => ['sensitive_type' => 'some_sensitive_value']
175  ]
176  ],
177  ],
178  $this->model->get('')
179  );
180  }
181 
182  public function testGetExcludedFields()
183  {
184  $this->assertEquals(
185  [
186  'web/secure/environment_type',
187  'web/some_key/sensitive_type',
188  'web/another_key/sensitive_type'
189  ],
190  $this->model->getExcludedFields()
191  );
192  }
193 }