Skip to content

Commit 1445598

Browse files
author
Maksym Savich
committed
MAGETWO-36484: Unit test code coverage in MLS10
1 parent 4a9b003 commit 1445598

File tree

3 files changed

+91
-7
lines changed

3 files changed

+91
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function setUp()
3333
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3434

3535
$this->file = $objectManager->getObject(
36-
'\Magento\Config\Block\System\Config\Form\Field\File',
36+
'Magento\Config\Block\System\Config\Form\Field\File',
3737
[
3838
'factoryElement' => $factoryMock,
3939
'factoryCollection' => $collectionFactoryMock,

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111

1212
class HeadingTest extends \PHPUnit_Framework_TestCase
1313
{
14-
/**
15-
* @var \PHPUnit_Framework_MockObject_MockObject
16-
*/
17-
protected $_objectManagerMock;
18-
1914
/**
2015
* @var \Magento\Config\Block\System\Config\Form\Field\File
2116
*/
@@ -35,7 +30,7 @@ public function testRender()
3530

3631
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3732

38-
$heading = $objectManager->getObject('\Magento\Config\Block\System\Config\Form\Field\Heading', []);
33+
$heading = $objectManager->getObject('Magento\Config\Block\System\Config\Form\Field\Heading', []);
3934

4035
$html = $heading->render($elementMock);
4136

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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\Element\File
9+
*/
10+
namespace Magento\Config\Test\Unit\Block\System\Config\Form\Field;
11+
12+
class NotificationTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var \Magento\Config\Block\System\Config\Form\Field\File
16+
*/
17+
protected $file;
18+
19+
public function testRender()
20+
{
21+
$testCacheValue = time();
22+
$testDatetime = (new \DateTime(null, new \DateTimeZone('UTC')))->setTimestamp($testCacheValue);
23+
$formattedDate = (\IntlDateFormatter::formatObject($testDatetime));
24+
$htmlId = 'test_HTML_id';
25+
$label = 'test_label';
26+
27+
$cacheMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface')
28+
->disableOriginalConstructor()
29+
->setMethods(['load', 'getFrontend', 'remove', 'save', 'clean'])
30+
->getMock();
31+
$cacheMock->expects($this->any())->method('load')->willReturn($testCacheValue);
32+
33+
$localeDateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\TimezoneInterface')
34+
->disableOriginalConstructor()
35+
->setMethods(
36+
[
37+
'date',
38+
'getDefaultTimezonePath',
39+
'getDefaultTimezone',
40+
'getDateFormat',
41+
'getDateFormatWithLongYear',
42+
'getTimeFormat',
43+
'getDateTimeFormat',
44+
'scopeDate',
45+
'formatDate',
46+
'scopeTimeStamp',
47+
'getConfigTimezone',
48+
'isScopeDateInInterval',
49+
'formatDateTime',
50+
]
51+
)
52+
->getMock();
53+
$localeDateMock->expects($this->any())->method('date')->willReturn($testDatetime);
54+
$localeDateMock->expects($this->any())->method('getDateTimeFormat')->willReturn(null);
55+
56+
$elementMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\AbstractElement')
57+
->disableOriginalConstructor()
58+
->setMethods(['getHtmlId', 'getLabel'])
59+
->getMock();
60+
$elementMock->expects($this->any())->method('getHtmlId')->willReturn($htmlId);
61+
$elementMock->expects($this->any())->method('getLabel')->willReturn($label);
62+
63+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
64+
65+
$notification = $objectManager->getObject(
66+
'Magento\Config\Block\System\Config\Form\Field\Notification',
67+
[
68+
'cache' => $cacheMock,
69+
'localeDate' => $localeDateMock,
70+
]
71+
);
72+
73+
$html = $notification->render($elementMock);
74+
75+
$this->assertEquals(
76+
'<tr id="row_test_HTML_id">' .
77+
'<td class="label">' .
78+
'<label for="test_HTML_id">test_label</label>' .
79+
'</td>' .
80+
'<td class="value">' .
81+
$formattedDate .
82+
'</td>' .
83+
'<td class="scope-label"></td>' .
84+
'<td class=""></td>' .
85+
'</tr>',
86+
$html
87+
);
88+
}
89+
}

0 commit comments

Comments
 (0)