Skip to content

Commit 23fca8f

Browse files
committed
MAGETWO-58833: [Backport] Order comments history shows time of comment twice - for 2.0.x
1 parent 0d31c3e commit 23fca8f

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,11 @@ public function getItemCreatedAt(array $item, $dateType = 'date', $format = \Int
157157
if (!isset($item['created_at'])) {
158158
return '';
159159
}
160-
$date = $item['created_at'] instanceof \DateTimeInterface
161-
? $item['created_at']
162-
: new \DateTime($item['created_at']);
163160
if ('date' === $dateType) {
164-
return $this->_localeDate->formatDateTime($date, $format, $format);
161+
return $this->formatDate($item['created_at'], $format);
165162
}
166-
return $this->_localeDate->formatDateTime($date, \IntlDateFormatter::NONE, $format);
163+
164+
return $this->formatTime($item['created_at'], $format);
167165
}
168166

169167
/**

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/View/Tab/HistoryTest.php

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,43 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
3030
*/
3131
protected $coreRegistryMock;
3232

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+
3344
protected function setUp()
3445
{
3546
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3647

3748
$this->coreRegistryMock = $this->getMock('Magento\Framework\Registry', [], [], '', false);
3849
$this->adminHelperMock = $this->getMock('\Magento\Sales\Helper\Admin', [], [], '', false);
3950

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+
4063
$this->commentsHistory = $this->objectManager->getObject(
4164
'Magento\Sales\Block\Adminhtml\Order\View\Tab\History',
4265
[
4366
'adminHelper' => $this->adminHelperMock,
44-
'registry' => $this->coreRegistryMock
67+
'registry' => $this->coreRegistryMock,
68+
'context' => $this->contextMock,
69+
'localeDate' => $this->localeDateMock
4570
]
4671
);
4772
}
@@ -63,4 +88,39 @@ public function testGetItemCommentIsNotSet()
6388
$this->adminHelperMock->expects($this->never())->method('escapeHtmlWithLinks');
6489
$this->assertEquals('', $this->commentsHistory->getItemComment($item));
6590
}
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+
}
66126
}

0 commit comments

Comments
 (0)