Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MessageTest.php
Go to the documentation of this file.
1 <?php
7 
8 class MessageTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $layoutFactoryMock;
14 
18  protected $helper;
19 
20  protected function setUp()
21  {
22  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23  $this->layoutFactoryMock = $this->createMock(\Magento\Framework\View\LayoutFactory::class);
24 
25  $this->helper = $objectManager->getObject(
26  \Magento\GiftMessage\Helper\Message::class,
27  [
28  'layoutFactory' => $this->layoutFactoryMock,
29  'skipMessageCheck' => ['onepage_checkout']
30  ]
31  );
32  }
33 
37  public function testGetInlineForCheckout()
38  {
39  $expectedHtml = '<a href="here">here</a>';
40  $layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
41  $entityMock = $this->createMock(\Magento\Framework\DataObject::class);
42  $inlineMock = $this->createPartialMock(
43  \Magento\GiftMessage\Block\Message\Inline::class,
44  ['setId', 'setDontDisplayContainer', 'setEntity', 'setCheckoutType', 'toHtml']
45  );
46 
47  $this->layoutFactoryMock->expects($this->once())->method('create')->will($this->returnValue($layoutMock));
48  $layoutMock->expects($this->once())->method('createBlock')->will($this->returnValue($inlineMock));
49 
50  $inlineMock->expects($this->once())->method('setId')->will($this->returnSelf());
51  $inlineMock->expects($this->once())->method('setDontDisplayContainer')->will($this->returnSelf());
52  $inlineMock->expects($this->once())->method('setEntity')->with($entityMock)->will($this->returnSelf());
53  $inlineMock->expects($this->once())->method('setCheckoutType')->will($this->returnSelf());
54  $inlineMock->expects($this->once())->method('toHtml')->will($this->returnValue($expectedHtml));
55 
56  $this->assertEquals($expectedHtml, $this->helper->getInline('onepage_checkout', $entityMock));
57  }
58 }
$objectManager
Definition: bootstrap.php:17