Skip to content

Commit 96710b5

Browse files
author
Dale Sikkema
committed
Merge remote-tracking branch 'origin/MAGETWO-37222' into MAGETWO-36484-unit-coverage
2 parents 87a0cd5 + d9482f7 commit 96710b5

File tree

6 files changed

+160
-186
lines changed

6 files changed

+160
-186
lines changed

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/FileTest.php

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,57 @@ class FileTest extends \PHPUnit_Framework_TestCase
1616
*/
1717
protected $file;
1818

19+
/**
20+
* @var array
21+
*/
22+
protected $testData;
23+
1924
protected function setUp()
2025
{
21-
$factoryMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\Factory')
22-
->disableOriginalConstructor()
23-
->getMock();
24-
25-
$collectionFactoryMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\CollectionFactory')
26-
->disableOriginalConstructor()
27-
->getMock();
28-
29-
$escaperMock = $this->getMockBuilder('Magento\Framework\Escaper')
30-
->disableOriginalConstructor()
31-
->getMock();
32-
3326
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3427

28+
$this->testData = [
29+
'before_element_html' => 'test_before_element_html',
30+
'html_id' => 'test_id',
31+
'name' => 'test_name',
32+
'value' => 'test_value',
33+
'title' => 'test_title',
34+
'disabled' => true,
35+
'after_element_js' => 'test_after_element_js',
36+
'after_element_html' => 'test_after_element_html',
37+
'html_id_prefix' => 'test_id_prefix_',
38+
'html_id_suffix' => '_test_id_suffix',
39+
];
40+
3541
$this->file = $objectManager->getObject(
3642
'Magento\Config\Block\System\Config\Form\Field\File',
37-
[
38-
'factoryElement' => $factoryMock,
39-
'factoryCollection' => $collectionFactoryMock,
40-
'escaper' => $escaperMock,
41-
'data' =>
42-
[
43-
'before_element_html' => 'test_before_element_html',
44-
'html_id' => 'test_id',
45-
'name' => 'test_name',
46-
'value' => 'test_value',
47-
'title' => 'test_title',
48-
'disabled' => true,
49-
'after_element_js' => 'test_after_element_js',
50-
'after_element_html' => 'test_after_element_html',
51-
]
52-
]
43+
['data' => $this->testData]
5344
);
5445

5546
$formMock = new \Magento\Framework\Object();
56-
$formMock->getHtmlIdPrefix('id_prefix');
57-
$formMock->getHtmlIdPrefix('id_suffix');
47+
$formMock->setHtmlIdPrefix($this->testData['html_id_prefix']);
48+
$formMock->setHtmlIdSuffix($this->testData['html_id_suffix']);
5849
$this->file->setForm($formMock);
5950
}
6051

6152
public function testGetElementHtml()
6253
{
6354
$html = $this->file->getElementHtml();
6455

65-
$this->assertContains('<label class="addbefore" for="test_id"', $html);
66-
$this->assertContains('test_before_element_html', $html);
67-
$this->assertContains('<input id="test_id"', $html);
68-
$this->assertContains('name="test_name"', $html);
69-
$this->assertContains('value="test_value"', $html);
56+
$expectedHtmlId = $this->testData['html_id_prefix']
57+
. $this->testData['html_id']
58+
. $this->testData['html_id_suffix'];
59+
60+
$this->assertContains('<label class="addbefore" for="' . $expectedHtmlId . '"', $html);
61+
$this->assertContains($this->testData['before_element_html'], $html);
62+
$this->assertContains('<input id="' . $expectedHtmlId . '"', $html);
63+
$this->assertContains('name="' . $this->testData['name'] . '"', $html);
64+
$this->assertContains('value="' . $this->testData['value'] . '"', $html);
7065
$this->assertContains('disabled="disabled"', $html);
7166
$this->assertContains('type="file"', $html);
72-
$this->assertContains('test_after_element_js', $html);
73-
$this->assertContains('<label class="addafter" for="test_id"', $html);
74-
$this->assertContains('test_after_element_html', $html);
75-
$this->assertContains('<input type="checkbox" name="test_name[delete]"', $html);
67+
$this->assertContains($this->testData['after_element_js'], $html);
68+
$this->assertContains('<label class="addafter" for="' . $expectedHtmlId . '"', $html);
69+
$this->assertContains($this->testData['after_element_html'], $html);
70+
$this->assertContains('<input type="checkbox" name="' . $this->testData['name'] . '[delete]"', $html);
7671
}
7772
}

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/HeadingTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testRender()
1818

1919
$elementMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\AbstractElement')
2020
->disableOriginalConstructor()
21-
->setMethods(['getHtmlId', 'getLabel'])
21+
->setMethods(['getHtmlId', 'getLabel'])
2222
->getMock();
2323
$elementMock->expects($this->any())->method('getHtmlId')->willReturn($htmlId);
2424
$elementMock->expects($this->any())->method('getLabel')->willReturn($label);
@@ -31,9 +31,9 @@ public function testRender()
3131

3232
$this->assertEquals(
3333
'<tr class="system-fieldset-sub-head" id="row_' . $htmlId . '">' .
34-
'<td colspan="5">' .
35-
'<h4 id="' . $htmlId . '">' . $label . '</h4>' .
36-
'</td>' .
34+
'<td colspan="5">' .
35+
'<h4 id="' . $htmlId . '">' . $label . '</h4>' .
36+
'</td>' .
3737
'</tr>',
3838
$html
3939
);

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/ImageTest.php

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,36 @@ class ImageTest extends \PHPUnit_Framework_TestCase
2121
/**
2222
* @var \Magento\Config\Block\System\Config\Form\Field\Image
2323
*/
24-
protected $_image;
24+
protected $image;
25+
26+
/**
27+
* @var array
28+
*/
29+
protected $testData;
2530

2631
protected function setUp()
2732
{
28-
$factoryMock = $this->getMock('Magento\Framework\Data\Form\Element\Factory', [], [], '', false);
29-
$collectionFactoryMock = $this->getMock(
30-
'Magento\Framework\Data\Form\Element\CollectionFactory',
31-
[],
32-
[],
33-
'',
34-
false
35-
);
36-
$escaperMock = $this->getMock('Magento\Framework\Escaper', [], [], '', false);
33+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3734
$this->urlBuilderMock = $this->getMock('Magento\Framework\Url', [], [], '', false);
38-
$this->_image = new \Magento\Config\Block\System\Config\Form\Field\Image(
39-
$factoryMock,
40-
$collectionFactoryMock,
41-
$escaperMock,
42-
$this->urlBuilderMock
35+
$this->image = $objectManager->getObject(
36+
'Magento\Config\Block\System\Config\Form\Field\Image',
37+
[
38+
'urlBuilder' => $this->urlBuilderMock,
39+
]
4340
);
41+
42+
$this->testData = [
43+
'html_id_prefix' => 'test_id_prefix_',
44+
'html_id' => 'test_id',
45+
'html_id_suffix' => '_test_id_suffix',
46+
'path' => 'catalog/product/placeholder',
47+
'value' => 'test_value',
48+
];
49+
4450
$formMock = new \Magento\Framework\Object();
45-
$formMock->getHtmlIdPrefix('id_prefix');
46-
$formMock->getHtmlIdPrefix('id_suffix');
47-
$this->_image->setForm($formMock);
51+
$formMock->setHtmlIdPrefix($this->testData['html_id_prefix']);
52+
$formMock->setHtmlIdSuffix($this->testData['html_id_suffix']);
53+
$this->image->setForm($formMock);
4854
}
4955

5056
/**
@@ -57,8 +63,9 @@ public function testGetElementHtmlWithValue()
5763
$this->urlBuilderMock->expects($this->once())->method('getBaseUrl')
5864
->with(['_type' => $type])->will($this->returnValue($url));
5965

60-
$this->_image->setValue('test_value');
61-
$this->_image->setFieldConfig(
66+
$this->image->setValue($this->testData['value']);
67+
$this->image->setHtmlId($this->testData['html_id']);
68+
$this->image->setFieldConfig(
6269
[
6370
'id' => 'placeholder',
6471
'type' => 'image',
@@ -71,25 +78,33 @@ public function testGetElementHtmlWithValue()
7178
'upload_dir' => [
7279
'config' => 'system/filesystem/media',
7380
'scope_info' => '1',
74-
'value' => 'catalog/product/placeholder',
81+
'value' => $this->testData['path'],
7582
],
7683
'base_url' => [
7784
'type' => $type,
7885
'scope_info' => '1',
79-
'value' => 'catalog/product/placeholder',
86+
'value' => $this->testData['path'],
8087
],
8188
'_elementType' => 'field',
8289
'path' => 'catalog/placeholder',
8390
]);
8491

85-
$html = $this->_image->getElementHtml();
92+
$expectedHtmlId = $this->testData['html_id_prefix']
93+
. $this->testData['html_id']
94+
. $this->testData['html_id_suffix'];
95+
96+
$html = $this->image->getElementHtml();
8697
$this->assertContains('class="input-file"', $html);
8798
$this->assertContains('<input', $html);
8899
$this->assertContains('type="file"', $html);
89100
$this->assertContains('value="test_value"', $html);
90101
$this->assertContains(
91-
'<a href="' . $url
92-
. 'catalog/product/placeholder/test_value" onclick="imagePreview(\'_image\'); return false;"',
102+
'<a href="'
103+
. $url
104+
. $this->testData['path']
105+
. '/'
106+
. $this->testData['value']
107+
. '" onclick="imagePreview(\'' . $expectedHtmlId . '_image\'); return false;"',
93108
$html
94109
);
95110
$this->assertContains('<input type="checkbox"', $html);

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/NotificationTest.php

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class NotificationTest extends \PHPUnit_Framework_TestCase
1313
{
1414
public function testRender()
1515
{
16-
$testCacheValue = time();
16+
$testCacheValue = '1433259723';
1717
$testDatetime = (new \DateTime(null, new \DateTimeZone('UTC')))->setTimestamp($testCacheValue);
1818
$formattedDate = (\IntlDateFormatter::formatObject($testDatetime));
1919
$htmlId = 'test_HTML_id';
@@ -27,30 +27,13 @@ public function testRender()
2727

2828
$localeDateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\TimezoneInterface')
2929
->disableOriginalConstructor()
30-
->setMethods(
31-
[
32-
'date',
33-
'getDefaultTimezonePath',
34-
'getDefaultTimezone',
35-
'getDateFormat',
36-
'getDateFormatWithLongYear',
37-
'getTimeFormat',
38-
'getDateTimeFormat',
39-
'scopeDate',
40-
'formatDate',
41-
'scopeTimeStamp',
42-
'getConfigTimezone',
43-
'isScopeDateInInterval',
44-
'formatDateTime',
45-
]
46-
)
4730
->getMock();
4831
$localeDateMock->expects($this->any())->method('date')->willReturn($testDatetime);
4932
$localeDateMock->expects($this->any())->method('getDateTimeFormat')->willReturn(null);
5033

5134
$elementMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\AbstractElement')
5235
->disableOriginalConstructor()
53-
->setMethods(['getHtmlId', 'getLabel'])
36+
->setMethods(['getHtmlId', 'getLabel'])
5437
->getMock();
5538
$elementMock->expects($this->any())->method('getHtmlId')->willReturn($htmlId);
5639
$elementMock->expects($this->any())->method('getLabel')->willReturn($label);
@@ -68,15 +51,15 @@ public function testRender()
6851
$html = $notification->render($elementMock);
6952

7053
$this->assertEquals(
71-
'<tr id="row_test_HTML_id">' .
72-
'<td class="label">' .
73-
'<label for="test_HTML_id">test_label</label>' .
74-
'</td>' .
75-
'<td class="value">' .
76-
$formattedDate .
77-
'</td>' .
78-
'<td class="scope-label"></td>' .
79-
'<td class=""></td>' .
54+
'<tr id="row_' . $htmlId . '">' .
55+
'<td class="label">' .
56+
'<label for="' . $htmlId . '">' . $label . '</label>' .
57+
'</td>' .
58+
'<td class="value">' .
59+
$formattedDate .
60+
'</td>' .
61+
'<td class="scope-label"></td>' .
62+
'<td class=""></td>' .
8063
'</tr>',
8164
$html
8265
);

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/RegexceptionsTest.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,37 @@ class RegexceptionsTest extends \PHPUnit_Framework_TestCase
4444
protected function setUp()
4545
{
4646
$this->cellParameters = [
47-
'label' => 'testLabel',
4847
'size' => 'testSize',
4948
'style' => 'testStyle',
5049
'class' => 'testClass',
5150
];
5251

53-
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
52+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
53+
54+
$this->labelFactoryMock = $this->getMockBuilder('Magento\Framework\View\Design\Theme\LabelFactory')
55+
->disableOriginalConstructor()
56+
->getMock();
57+
$this->labelMock = $this->getMockBuilder('Magento\Framework\View\Design\Theme\Label')
58+
->disableOriginalConstructor()
59+
->getMock();
60+
$this->elementFactoryMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\Factory')
61+
->disableOriginalConstructor()
62+
->getMock();
63+
$this->elementMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\AbstractElement')
64+
->disableOriginalConstructor()
65+
->setMethods(
66+
['setForm', 'setName', 'setHtmlId', 'setValues', 'getName', 'getHtmlId', 'getValues', 'getElementHtml']
67+
)
68+
->getMock();
5469

55-
$this->labelFactoryMock = $this->getMock('Magento\Framework\View\Design\Theme\LabelFactory', [], [], '', false);
56-
$this->labelMock = $this->getMock('Magento\Framework\View\Design\Theme\Label', [], [], '', false);
57-
58-
$this->elementFactoryMock = $this->getMock('Magento\Framework\Data\Form\Element\Factory', [], [], '', false);
59-
$this->elementMock = $this->getMock(
60-
'Magento\Framework\Data\Form\Element\AbstractElement',
61-
['setForm', 'setName', 'setHtmlId', 'setValues', 'getName', 'getHtmlId', 'getValues', 'getElementHtml'],
62-
[],
63-
'',
64-
false
65-
);
6670
$data = [
6771
'elementFactory' => $this->elementFactoryMock,
6872
'labelFactory' => $this->labelFactoryMock,
6973
'data' => [
7074
'element' => $this->elementMock
7175
],
7276
];
73-
$this->object = $helper->getObject('Magento\Config\Block\System\Config\Form\Field\Regexceptions', $data);
77+
$this->object = $objectManager->getObject('Magento\Config\Block\System\Config\Form\Field\Regexceptions', $data);
7478
}
7579

7680
public function testRenderCellTemplateValueColumn()
@@ -79,10 +83,10 @@ public function testRenderCellTemplateValueColumn()
7983
$expectedResult = 'testValueElementHtml';
8084

8185
$this->elementFactoryMock->expects($this->once())->method('create')->willReturn($this->elementMock);
82-
$this->elementMock->expects($this->once())->method('setForm')->willReturn($this->elementMock);
83-
$this->elementMock->expects($this->once())->method('setName')->willReturn($this->elementMock);
84-
$this->elementMock->expects($this->once())->method('setHtmlId')->willReturn($this->elementMock);
85-
$this->elementMock->expects($this->once())->method('setValues')->willReturn($this->elementMock);
86+
$this->elementMock->expects($this->once())->method('setForm')->willReturnSelf();
87+
$this->elementMock->expects($this->once())->method('setName')->willReturnSelf();
88+
$this->elementMock->expects($this->once())->method('setHtmlId')->willReturnSelf();
89+
$this->elementMock->expects($this->once())->method('setValues')->willReturnSelf();
8690
$this->elementMock->expects($this->once())->method('getElementHtml')->willReturn($expectedResult);
8791

8892
$this->labelFactoryMock->expects($this->once())->method('create')->willReturn($this->labelMock);
@@ -102,28 +106,24 @@ public function testRenderCellTemplateValueColumn()
102106
public function testRenderCellTemplateOtherColumn()
103107
{
104108
$columnName = 'testCellName';
105-
$expectedResult = '<input type="text" id="<%- _id %>_testCellName" name="[<%- _id %>][testCellName]"' .
106-
' value="<%- testCellName %>" size="testSize" class="testClass" style="testStyle"/>';
107109

108110
$this->object->addColumn(
109111
$columnName,
110112
$this->cellParameters
111113
);
112114

113-
$this->assertEquals(
114-
$expectedResult,
115-
$this->object->renderCellTemplate($columnName)
116-
);
115+
$actual = $this->object->renderCellTemplate($columnName);
116+
foreach ($this->cellParameters as $parameter) {
117+
$this->assertContains($parameter, $actual, 'Parameter \'' . $parameter . '\' missing in render output.');
118+
}
117119
}
118120

119121
public function testRenderCellTemplateWrongColumnName()
120122
{
121-
$columnName = 'testCellName';
123+
$columnName = 'testCellName';
124+
$wrongColumnName = 'wrongTestCellName';
122125

123-
$this->object->addColumn(
124-
$columnName . 'Wrong',
125-
$this->cellParameters
126-
);
126+
$this->object->addColumn($wrongColumnName, $this->cellParameters);
127127

128128
$this->setExpectedException('\Exception', 'Wrong column name specified.');
129129

0 commit comments

Comments
 (0)