45 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
47 $this->coreRegistryMock = $this->createMock(\
Magento\Framework\Registry::class);
48 $this->adminHelperMock = $this->createMock(\
Magento\Sales\Helper\Admin::class);
50 $this->contextMock = $this->getMockBuilder(\
Magento\Backend\Block\Template\Context::class)
51 ->disableOriginalConstructor()
52 ->setMethods([
'getLocaleDate'])
55 $this->localeDateMock = $this->getMockBuilder(\
Magento\Framework\Stdlib\DateTime\TimezoneInterface::class)
58 $this->contextMock->expects($this->any())->method(
'getLocaleDate')->will(
59 $this->returnValue($this->localeDateMock)
62 $this->commentsHistory = $this->objectManager->getObject(
63 \
Magento\Sales\Block\Adminhtml\Order\View\Tab\History::class,
65 'adminHelper' => $this->adminHelperMock,
66 'registry' => $this->coreRegistryMock,
67 'context' => $this->contextMock,
68 'localeDate' => $this->localeDateMock
75 $expectation =
'Authorized amount of £20.00 Transaction ID: "XXX123123XXX"';
76 $item[
'comment'] =
'Authorized amount of £20.00 Transaction ID: "XXX123123XXX"';
77 $this->adminHelperMock->expects($this->once())
78 ->method(
'escapeHtmlWithLinks')
79 ->with(
$item[
'comment'], [
'b',
'br',
'strong',
'i',
'u',
'a'])
80 ->willReturn($expectation);
81 $this->assertEquals($expectation, $this->commentsHistory->getItemComment(
$item));
87 $this->adminHelperMock->expects($this->never())->method(
'escapeHtmlWithLinks');
88 $this->assertEquals(
'', $this->commentsHistory->getItemComment(
$item));
93 $date = new \DateTime;
94 $item = [
'created_at' => $date ];
96 $this->localeDateMock->expects($this->once())
97 ->method(
'formatDateTime')
98 ->with($date, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE)
101 $this->assertEquals(
'date', $this->commentsHistory->getItemCreatedAt(
$item));
106 $date = new \DateTime;
107 $item = [
'created_at' => $date ];
109 $this->localeDateMock->expects($this->once())
110 ->method(
'formatDateTime')
111 ->with($date, \IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM)
112 ->willReturn(
'time');
114 $this->assertEquals(
'time', $this->commentsHistory->getItemCreatedAt(
$item,
'time'));
119 $item = [
'title' =>
"Test" ];
121 $this->localeDateMock->expects($this->never())->method(
'formatDateTime');
122 $this->assertEquals(
'', $this->commentsHistory->getItemCreatedAt(
$item));
123 $this->assertEquals(
'', $this->commentsHistory->getItemCreatedAt(
$item,
'time'));
testGetItemCreatedAtTime()
testGetItemCreatedAtDate()
testGetItemCreatedAtEmpty()
testGetItemCommentIsNotSet()