@@ -30,18 +30,43 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
30
30
*/
31
31
protected $ coreRegistryMock ;
32
32
33
+ /**
34
+ * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ protected $ localeDateMock ;
37
+
38
+ /**
39
+ * @var \Magento\Backend\Block\Template\Context|\PHPUnit_Framework_MockObject_MockObject
40
+ */
41
+ protected $ contextMock ;
42
+
43
+
33
44
protected function setUp ()
34
45
{
35
46
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
36
47
37
48
$ this ->coreRegistryMock = $ this ->getMock ('Magento\Framework\Registry ' , [], [], '' , false );
38
49
$ this ->adminHelperMock = $ this ->getMock ('\Magento\Sales\Helper\Admin ' , [], [], '' , false );
39
50
51
+ $ this ->contextMock = $ this ->getMockBuilder (\Magento \Backend \Block \Template \Context::class)
52
+ ->disableOriginalConstructor ()
53
+ ->setMethods (['getLocaleDate ' ])
54
+ ->getMock ();
55
+
56
+ $ this ->localeDateMock = $ this ->getMockBuilder (\Magento \Framework \Stdlib \DateTime \TimezoneInterface::class)
57
+ ->getMock ();
58
+
59
+ $ this ->contextMock ->expects ($ this ->any ())->method ('getLocaleDate ' )->will (
60
+ $ this ->returnValue ($ this ->localeDateMock )
61
+ );
62
+
40
63
$ this ->commentsHistory = $ this ->objectManager ->getObject (
41
64
'Magento\Sales\Block\Adminhtml\Order\View\Tab\History ' ,
42
65
[
43
66
'adminHelper ' => $ this ->adminHelperMock ,
44
- 'registry ' => $ this ->coreRegistryMock
67
+ 'registry ' => $ this ->coreRegistryMock ,
68
+ 'context ' => $ this ->contextMock ,
69
+ 'localeDate ' => $ this ->localeDateMock
45
70
]
46
71
);
47
72
}
@@ -63,4 +88,39 @@ public function testGetItemCommentIsNotSet()
63
88
$ this ->adminHelperMock ->expects ($ this ->never ())->method ('escapeHtmlWithLinks ' );
64
89
$ this ->assertEquals ('' , $ this ->commentsHistory ->getItemComment ($ item ));
65
90
}
91
+
92
+ public function testGetItemCreatedAtDate ()
93
+ {
94
+ $ date = new \DateTime ;
95
+ $ item = ['created_at ' => $ date ];
96
+
97
+ $ this ->localeDateMock ->expects ($ this ->once ())
98
+ ->method ('formatDateTime ' )
99
+ ->with ($ date , \IntlDateFormatter::MEDIUM , \IntlDateFormatter::NONE )
100
+ ->willReturn ('date ' );
101
+
102
+ $ this ->assertEquals ('date ' , $ this ->commentsHistory ->getItemCreatedAt ($ item ));
103
+ }
104
+
105
+ public function testGetItemCreatedAtTime ()
106
+ {
107
+ $ date = new \DateTime ;
108
+ $ item = ['created_at ' => $ date ];
109
+
110
+ $ this ->localeDateMock ->expects ($ this ->once ())
111
+ ->method ('formatDateTime ' )
112
+ ->with ($ date , \IntlDateFormatter::NONE , \IntlDateFormatter::MEDIUM )
113
+ ->willReturn ('time ' );
114
+
115
+ $ this ->assertEquals ('time ' , $ this ->commentsHistory ->getItemCreatedAt ($ item , 'time ' ));
116
+ }
117
+
118
+ public function testGetItemCreatedAtEmpty ()
119
+ {
120
+ $ item = ['title ' => "Test " ];
121
+
122
+ $ this ->localeDateMock ->expects ($ this ->never ())->method ('formatDateTime ' );
123
+ $ this ->assertEquals ('' , $ this ->commentsHistory ->getItemCreatedAt ($ item ));
124
+ $ this ->assertEquals ('' , $ this ->commentsHistory ->getItemCreatedAt ($ item , 'time ' ));
125
+ }
66
126
}
0 commit comments