Skip to content

Commit cfd7771

Browse files
committed
Cover changes with unit test
1 parent eb40893 commit cfd7771

File tree

2 files changed

+108
-34
lines changed

2 files changed

+108
-34
lines changed

app/code/Magento/Config/Test/Unit/Model/Config/StructureTest.php

Lines changed: 98 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class StructureTest extends \PHPUnit\Framework\TestCase
5050
*/
5151
protected $_structureData;
5252

53+
/**
54+
* @inheritdoc
55+
*/
5356
protected function setUp()
5457
{
5558
$this->_flyweightFactory = $this->getMockBuilder(FlyweightFactory::class)
@@ -82,7 +85,12 @@ protected function setUp()
8285
);
8386
}
8487

85-
public function testGetTabsBuildsSectionTree()
88+
/**
89+
* Verify tabs build section tree
90+
*
91+
* @return void
92+
*/
93+
public function testGetTabsBuildsSectionTree(): void
8694
{
8795
$expected = ['tab1' => ['children' => ['section1' => ['tab' => 'tab1']]]];
8896

@@ -108,7 +116,12 @@ public function testGetTabsBuildsSectionTree()
108116
$this->assertEquals($this->_tabIteratorMock, $model->getTabs());
109117
}
110118

111-
public function testGetSectionList()
119+
/**
120+
* Verify get section list method
121+
*
122+
* @return void
123+
*/
124+
public function testGetSectionList(): void
112125
{
113126
$expected = [
114127
'section1_child_id_1' => true,
@@ -152,6 +165,8 @@ public function testGetSectionList()
152165
}
153166

154167
/**
168+
* Verify Get Element return empty element if element is requested
169+
*
155170
* @param string $path
156171
* @param string $expectedType
157172
* @param string $expectedId
@@ -174,6 +189,8 @@ public function testGetElementReturnsEmptyElementIfNotExistingElementIsRequested
174189
}
175190

176191
/**
192+
* Verify get Element return empty by path element if not exist
193+
*
177194
* @param string $path
178195
* @param string $expectedType
179196
* @param string $expectedId
@@ -196,6 +213,8 @@ public function testGetElementReturnsEmptyByConfigPathElementIfNotExistingElemen
196213
}
197214

198215
/**
216+
* Verify Element return e,pty element if not exists
217+
*
199218
* @param string $expectedType
200219
* @param string $expectedId
201220
* @param string $expectedPath
@@ -234,21 +253,33 @@ public function emptyElementDataProvider()
234253
];
235254
}
236255

237-
public function testGetElementReturnsProperElementByPath()
256+
/**
257+
* Verify get element returns proper element by path
258+
*
259+
* @return void
260+
*/
261+
public function testGetElementReturnsProperElementByPath(): void
238262
{
239263
$elementMock = $this->getElementPathReturnsProperElementByPath();
240264

241265
$this->assertEquals($elementMock, $this->_model->getElement('section_1/group_level_1/field_3'));
242266
}
243267

244-
public function testGetElementByConfigPathReturnsProperElementByPath()
268+
/**
269+
* Verify get element by config path return proper path
270+
*
271+
* @return void
272+
*/
273+
public function testGetElementByConfigPathReturnsProperElementByPath(): void
245274
{
246275
$elementMock = $this->getElementPathReturnsProperElementByPath();
247276

248277
$this->assertEquals($elementMock, $this->_model->getElementByConfigPath('section_1/group_level_1/field_3'));
249278
}
250279

251280
/**
281+
* Build mock element
282+
*
252283
* @return Mock
253284
*/
254285
private function getElementPathReturnsProperElementByPath()
@@ -271,7 +302,12 @@ private function getElementPathReturnsProperElementByPath()
271302
return $elementMock;
272303
}
273304

274-
public function testGetElementByPathPartsIfSectionDataIsEmpty()
305+
/**
306+
* Verefy get element by path part
307+
*
308+
* @return void
309+
*/
310+
public function testGetElementByPathPartsIfSectionDataIsEmpty(): void
275311
{
276312
$fieldData = [
277313
'id' => 'field_3',
@@ -342,15 +378,25 @@ public function testGetFirstSectionReturnsFirstAllowedSection()
342378
$this->assertEquals('currentSection', $this->_model->getFirstSection()->getData());
343379
}
344380

345-
public function testGetElementReturnsProperElementByPathCachesObject()
381+
/**
382+
* Verify get element return element by path caches object
383+
*
384+
* @return void
385+
*/
386+
public function testGetElementReturnsProperElementByPathCachesObject(): void
346387
{
347388
$elementMock = $this->getElementReturnsProperElementByPathCachesObject();
348389

349390
$this->assertEquals($elementMock, $this->_model->getElement('section_1/group_level_1/field_3'));
350391
$this->assertEquals($elementMock, $this->_model->getElement('section_1/group_level_1/field_3'));
351392
}
352393

353-
public function testGetElementByConfigPathReturnsProperElementByPathCachesObject()
394+
/**
395+
* Verify Get Element by id returns proper element
396+
*
397+
* @return void
398+
*/
399+
public function testGetElementByConfigPathReturnsProperElementByPathCachesObject(): void
354400
{
355401
$elementMock = $this->getElementReturnsProperElementByPathCachesObject();
356402

@@ -393,6 +439,8 @@ public function testGetFieldPathsByAttribute($attributeName, $attributeValue, $p
393439
}
394440

395441
/**
442+
* DataProvider
443+
*
396444
* @return array
397445
*/
398446
public function getFieldPathsByAttributeDataProvider()
@@ -411,33 +459,53 @@ public function getFieldPathsByAttributeDataProvider()
411459
];
412460
}
413461

414-
public function testGetFieldPaths()
462+
/**
463+
* Verify get Fields paths method
464+
*
465+
* @dataProvider getFieldPaths
466+
* @param array $expected
467+
* @return void
468+
*/
469+
public function testGetFieldPaths(array $expected): void
415470
{
416-
$expected = [
417-
'section/group/field2' => [
418-
'field_2'
419-
],
420-
'field_3' => [
421-
'field_3',
422-
'field_3'
423-
],
424-
'field_3_1' => [
425-
'field_3_1'
426-
],
427-
'field_3_1_1' => [
428-
'field_3_1_1'
429-
],
430-
'section/group/field4' => [
431-
'field_4',
432-
],
433-
'field_5' => [
434-
'field_5',
435-
],
436-
];
437-
438471
$this->assertSame(
439472
$expected,
440473
$this->_model->getFieldPaths()
441474
);
442475
}
476+
477+
/**
478+
* dataprovider for Field Paths
479+
*
480+
* @return array
481+
*/
482+
public function getFieldPaths(): array
483+
{
484+
return [
485+
[
486+
[
487+
'section/group/field2' => [
488+
'field_2'
489+
],
490+
'field_3' => [
491+
'field_3',
492+
'field_3'
493+
],
494+
'field_3_1' => [
495+
'field_3_1'
496+
],
497+
'field_3_1_1' => [
498+
'field_3_1_1'
499+
],
500+
'section/group/field4' => [
501+
'field_4',
502+
],
503+
'field_5' => [
504+
'field_5',
505+
],
506+
'section_3' => ['section_3']
507+
]
508+
]
509+
];
510+
}
443511
}

app/code/Magento/Config/Test/Unit/Model/_files/converted_config.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
'translate' => 'label',
7777
'showInWebsite' => '1',
7878
'backend_model' =>
79-
\Magento\Config\Model\Config\Backend\Encrypted::class,
79+
\Magento\Config\Model\Config\Backend\Encrypted::class,
8080
'type' => 'text',
8181
'label' => 'Field 3.1.1',
8282
'_elementType' => 'field',
@@ -158,14 +158,14 @@
158158
],
159159
'_elementType' => 'field',
160160
],
161-
'field_5' => [
161+
'field_5' => [
162162
'id' => 'field_5',
163163
'translate' => 'label',
164164
'showInWebsite' => '1',
165165
'type' => 'text',
166166
'label' => '',
167167
'_elementType' => 'field',
168-
],
168+
],
169169
],
170170
'_elementType' => 'group',
171171
],
@@ -190,7 +190,13 @@
190190
],
191191
'_elementType' => 'section',
192192
],
193-
],
193+
'section_3' => [
194+
'id' => 'section_3',
195+
'type' => 'text',
196+
'tab' => 'tab_1',
197+
'_elementType' => 'field'
198+
],
199+
],
194200
],
195201
],
196202
];

0 commit comments

Comments
 (0)