Skip to content

Commit 64951f4

Browse files
author
He, Joan(johe)
committed
Merge pull request #358 from magento-extensibility/develop
[Extensibility] Github PRs / Bugs / Test Coverage
2 parents b7a2dbb + 63e3cd2 commit 64951f4

File tree

34 files changed

+1382
-358
lines changed

34 files changed

+1382
-358
lines changed

app/code/Magento/Config/Block/System/Config/Form/Field/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\Field object factory
9-
*/
107
namespace Magento\Config\Block\System\Config\Form\Field;
118

9+
/**
10+
* Magento\Config\Block\System\Config\Form\Field Class Factory
11+
*
12+
* @codeCoverageIgnore
13+
*/
1214
class Factory
1315
{
1416
/**

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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Tests for \Magento\Framework\Data\Form\Field\File
9+
*/
10+
namespace Magento\Config\Test\Unit\Block\System\Config\Form\Field;
11+
12+
class FileTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var \Magento\Config\Block\System\Config\Form\Field\File
16+
*/
17+
protected $file;
18+
19+
/**
20+
* @var array
21+
*/
22+
protected $testData;
23+
24+
protected function setUp()
25+
{
26+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
27+
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+
41+
$this->file = $objectManager->getObject(
42+
'Magento\Config\Block\System\Config\Form\Field\File',
43+
['data' => $this->testData]
44+
);
45+
46+
$formMock = new \Magento\Framework\Object();
47+
$formMock->setHtmlIdPrefix($this->testData['html_id_prefix']);
48+
$formMock->setHtmlIdSuffix($this->testData['html_id_suffix']);
49+
$this->file->setForm($formMock);
50+
}
51+
52+
public function testGetElementHtml()
53+
{
54+
$html = $this->file->getElementHtml();
55+
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);
65+
$this->assertContains('disabled="disabled"', $html);
66+
$this->assertContains('type="file"', $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);
71+
}
72+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Tests for \Magento\Framework\Data\Form\Field\Heading
9+
*/
10+
namespace Magento\Config\Test\Unit\Block\System\Config\Form\Field;
11+
12+
class HeadingTest extends \PHPUnit_Framework_TestCase
13+
{
14+
public function testRender()
15+
{
16+
$htmlId = 'test_HTML_id';
17+
$label = 'test_label';
18+
19+
$elementMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\AbstractElement')
20+
->disableOriginalConstructor()
21+
->setMethods(['getHtmlId', 'getLabel'])
22+
->getMock();
23+
$elementMock->expects($this->any())->method('getHtmlId')->willReturn($htmlId);
24+
$elementMock->expects($this->any())->method('getLabel')->willReturn($label);
25+
26+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
27+
28+
$heading = $objectManager->getObject('Magento\Config\Block\System\Config\Form\Field\Heading', []);
29+
30+
$html = $heading->render($elementMock);
31+
32+
$this->assertEquals(
33+
'<tr class="system-fieldset-sub-head" id="row_' . $htmlId . '">' .
34+
'<td colspan="5">' .
35+
'<h4 id="' . $htmlId . '">' . $label . '</h4>' .
36+
'</td>' .
37+
'</tr>',
38+
$html
39+
);
40+
}
41+
}

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

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@
77
// @codingStandardsIgnoreFile
88

99
/**
10-
* Tests for \Magento\Framework\Data\Form\Element\Image
10+
* Tests for \Magento\Framework\Data\Form\Field\Image
1111
*/
1212
namespace Magento\Config\Test\Unit\Block\System\Config\Form\Field;
1313

1414
class ImageTest extends \PHPUnit_Framework_TestCase
1515
{
16-
/**
17-
* @var \PHPUnit_Framework_MockObject_MockObject
18-
*/
19-
protected $_objectManagerMock;
20-
2116
/**
2217
* @var \Magento\Framework\Url|\PHPUnit_Framework_MockObject_MockObject
2318
*/
@@ -26,30 +21,36 @@ class ImageTest extends \PHPUnit_Framework_TestCase
2621
/**
2722
* @var \Magento\Config\Block\System\Config\Form\Field\Image
2823
*/
29-
protected $_image;
24+
protected $image;
25+
26+
/**
27+
* @var array
28+
*/
29+
protected $testData;
3030

3131
protected function setUp()
3232
{
33-
$factoryMock = $this->getMock('Magento\Framework\Data\Form\Element\Factory', [], [], '', false);
34-
$collectionFactoryMock = $this->getMock(
35-
'Magento\Framework\Data\Form\Element\CollectionFactory',
36-
[],
37-
[],
38-
'',
39-
false
40-
);
41-
$escaperMock = $this->getMock('Magento\Framework\Escaper', [], [], '', false);
33+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
4234
$this->urlBuilderMock = $this->getMock('Magento\Framework\Url', [], [], '', false);
43-
$this->_image = new \Magento\Config\Block\System\Config\Form\Field\Image(
44-
$factoryMock,
45-
$collectionFactoryMock,
46-
$escaperMock,
47-
$this->urlBuilderMock
35+
$this->image = $objectManager->getObject(
36+
'Magento\Config\Block\System\Config\Form\Field\Image',
37+
[
38+
'urlBuilder' => $this->urlBuilderMock,
39+
]
4840
);
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+
4950
$formMock = new \Magento\Framework\Object();
50-
$formMock->getHtmlIdPrefix('id_prefix');
51-
$formMock->getHtmlIdPrefix('id_suffix');
52-
$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);
5354
}
5455

5556
/**
@@ -62,8 +63,9 @@ public function testGetElementHtmlWithValue()
6263
$this->urlBuilderMock->expects($this->once())->method('getBaseUrl')
6364
->with(['_type' => $type])->will($this->returnValue($url));
6465

65-
$this->_image->setValue('test_value');
66-
$this->_image->setFieldConfig(
66+
$this->image->setValue($this->testData['value']);
67+
$this->image->setHtmlId($this->testData['html_id']);
68+
$this->image->setFieldConfig(
6769
[
6870
'id' => 'placeholder',
6971
'type' => 'image',
@@ -76,25 +78,33 @@ public function testGetElementHtmlWithValue()
7678
'upload_dir' => [
7779
'config' => 'system/filesystem/media',
7880
'scope_info' => '1',
79-
'value' => 'catalog/product/placeholder',
81+
'value' => $this->testData['path'],
8082
],
8183
'base_url' => [
8284
'type' => $type,
8385
'scope_info' => '1',
84-
'value' => 'catalog/product/placeholder',
86+
'value' => $this->testData['path'],
8587
],
8688
'_elementType' => 'field',
8789
'path' => 'catalog/placeholder',
8890
]);
8991

90-
$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();
9197
$this->assertContains('class="input-file"', $html);
9298
$this->assertContains('<input', $html);
9399
$this->assertContains('type="file"', $html);
94100
$this->assertContains('value="test_value"', $html);
95101
$this->assertContains(
96-
'<a href="' . $url
97-
. '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;"',
98108
$html
99109
);
100110
$this->assertContains('<input type="checkbox"', $html);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Tests for \Magento\Framework\Data\Form\Field\Notification
9+
*/
10+
namespace Magento\Config\Test\Unit\Block\System\Config\Form\Field;
11+
12+
class NotificationTest extends \PHPUnit_Framework_TestCase
13+
{
14+
public function testRender()
15+
{
16+
$testCacheValue = '1433259723';
17+
$testDatetime = (new \DateTime(null, new \DateTimeZone('UTC')))->setTimestamp($testCacheValue);
18+
$formattedDate = (\IntlDateFormatter::formatObject($testDatetime));
19+
$htmlId = 'test_HTML_id';
20+
$label = 'test_label';
21+
22+
$cacheMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface')
23+
->disableOriginalConstructor()
24+
->setMethods(['load', 'getFrontend', 'remove', 'save', 'clean'])
25+
->getMock();
26+
$cacheMock->expects($this->any())->method('load')->willReturn($testCacheValue);
27+
28+
$localeDateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\TimezoneInterface')
29+
->disableOriginalConstructor()
30+
->getMock();
31+
$localeDateMock->expects($this->any())->method('date')->willReturn($testDatetime);
32+
$localeDateMock->expects($this->any())->method('getDateTimeFormat')->willReturn(null);
33+
34+
$elementMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\AbstractElement')
35+
->disableOriginalConstructor()
36+
->setMethods(['getHtmlId', 'getLabel'])
37+
->getMock();
38+
$elementMock->expects($this->any())->method('getHtmlId')->willReturn($htmlId);
39+
$elementMock->expects($this->any())->method('getLabel')->willReturn($label);
40+
41+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
42+
43+
$notification = $objectManager->getObject(
44+
'Magento\Config\Block\System\Config\Form\Field\Notification',
45+
[
46+
'cache' => $cacheMock,
47+
'localeDate' => $localeDateMock,
48+
]
49+
);
50+
51+
$html = $notification->render($elementMock);
52+
53+
$this->assertEquals(
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>' .
63+
'</tr>',
64+
$html
65+
);
66+
}
67+
}

0 commit comments

Comments
 (0)