Skip to content

Commit 0756f41

Browse files
author
Maksym Savich
committed
MAGETWO-36484: Unit test code coverage in MLS10
1 parent 871c7d3 commit 0756f41

File tree

2 files changed

+132
-3
lines changed

2 files changed

+132
-3
lines changed

app/code/Magento/Config/Block/System/Config/Form/Fieldset/Factory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* \Magento\Config\Block\System\Config\Form\Fieldset object factory
9-
*/
107
namespace Magento\Config\Block\System\Config\Form\Fieldset;
118

9+
/**
10+
* Magento\Config\Block\System\Config\Form\Fieldset object factory
11+
*
12+
* @codeCoverageIgnore
13+
*/
1214
class Factory
1315
{
1416
/**
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Block\System\Config\Form\Fieldset\Modules;
7+
8+
class DisableOutputTest extends \PHPUnit_Framework_TestCase
9+
{
10+
public function testRender()
11+
{
12+
$testData = [
13+
'htmlId' => 'test_field_id',
14+
'label' => 'test_label',
15+
'elementHTML' => 'test_html',
16+
'legend' => 'test_legend',
17+
'comment' => 'test_comment',
18+
];
19+
20+
$testModuleList = [
21+
'testModuleWithConfigData',
22+
'testModuleNoConfigData',
23+
];
24+
25+
$configData = ['advanced/modules_disable_output/testModuleWithConfigData' => 'testModuleData'];
26+
27+
$fieldMock = $this->getMock('Magento\Config\Block\System\Config\Form\Field', [], [], '', false, false, true);
28+
$layoutMock = $this->getMock('Magento\Framework\View\Layout', [], [], '', false, false);
29+
$layoutMock->expects($this->once())
30+
->method('getBlockSingleton')
31+
->with('Magento\Config\Block\System\Config\Form\Field')
32+
->willReturn($fieldMock);
33+
34+
$groupMock = $this->getMock(
35+
'Magento\Config\Model\Config\Structure\Element\Group',
36+
[],
37+
[],
38+
'',
39+
false
40+
);
41+
$groupMock->expects($this->once())->method('getFieldsetCss')->willReturn('test_fieldset_css');
42+
43+
$elementMock = $this->getMock(
44+
'Magento\Framework\Data\Form\Element\Text',
45+
[
46+
'getHtmlId', 'getExpanded', 'getElements',
47+
'getLegend', 'getComment', 'addField', 'setRenderer', 'toHtml'
48+
],
49+
[],
50+
'',
51+
false,
52+
false,
53+
true
54+
);
55+
$elementMock->expects(
56+
$this->any()
57+
)->method(
58+
'getHtmlId'
59+
)->willReturn(
60+
$testData['htmlId']
61+
);
62+
$elementMock->expects($this->any())->method('getExpanded')->willReturn(true);
63+
$elementMock->expects(
64+
$this->any()
65+
)->method(
66+
'getLegend'
67+
)->willReturn(
68+
$testData['legend']
69+
);
70+
$elementMock->expects(
71+
$this->any()
72+
)->method(
73+
'getComment'
74+
)->willReturn(
75+
$testData['comment']
76+
);
77+
$elementMock->expects($this->any())->method('addField')->willReturn($elementMock);
78+
$elementMock->expects($this->any())->method('setRenderer')->willReturn($elementMock);
79+
$elementMock->expects($this->any())->method('toHtml')->willReturn('test_element_html');
80+
81+
$moduleListMock = $this->getMock(
82+
'Magento\Framework\Module\ModuleList',
83+
[],
84+
[],
85+
'',
86+
false,
87+
false
88+
);
89+
90+
$moduleListMock->expects($this->any())->method('getNames')->willReturn(
91+
array_merge(['Magento_Backend'], $testModuleList)
92+
);
93+
94+
$factory = $this->getMock('Magento\Framework\Data\Form\Element\Factory', [], [], '', false);
95+
$factoryColl = $this->getMock(
96+
'Magento\Framework\Data\Form\Element\CollectionFactory',
97+
[],
98+
[],
99+
'',
100+
false
101+
);
102+
$formMock = $this->getMock('Magento\Framework\Data\Form\AbstractForm', [], [$factory, $factoryColl]);
103+
$formMock->expects($this->any())->method('getConfigValue')->willReturn('testConfigData');
104+
105+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
106+
$object = $objectManager->getObject(
107+
'Magento\Config\Block\System\Config\Form\Fieldset\Modules\DisableOutput',
108+
[
109+
'moduleList' => $moduleListMock,
110+
'layout' => $layoutMock,
111+
'data' => [
112+
'group' => $groupMock,
113+
'form' => $formMock,
114+
'config_data' => $configData,
115+
],
116+
]
117+
);
118+
119+
$collection = $objectManager->getObject('Magento\Framework\Data\Form\Element\Collection');
120+
$elementMock->expects($this->any())->method('getElements')->willReturn($collection);
121+
122+
$actualHtml = $object->render($elementMock);
123+
$this->assertContains('test_element_html', $actualHtml);
124+
$this->assertContains('test_field_id', $actualHtml);
125+
$this->assertContains('test_comment', $actualHtml);
126+
}
127+
}

0 commit comments

Comments
 (0)