|
| 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