MessageTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\GiftMessage\Test\Unit\Helper;
  7. class MessageTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $layoutFactoryMock;
  13. /**
  14. * @var \Magento\GiftMessage\Helper\Message
  15. */
  16. protected $helper;
  17. protected function setUp()
  18. {
  19. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  20. $this->layoutFactoryMock = $this->createMock(\Magento\Framework\View\LayoutFactory::class);
  21. $this->helper = $objectManager->getObject(
  22. \Magento\GiftMessage\Helper\Message::class,
  23. [
  24. 'layoutFactory' => $this->layoutFactoryMock,
  25. 'skipMessageCheck' => ['onepage_checkout']
  26. ]
  27. );
  28. }
  29. /**
  30. * Make sure that isMessagesAllowed is not called
  31. */
  32. public function testGetInlineForCheckout()
  33. {
  34. $expectedHtml = '<a href="here">here</a>';
  35. $layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
  36. $entityMock = $this->createMock(\Magento\Framework\DataObject::class);
  37. $inlineMock = $this->createPartialMock(
  38. \Magento\GiftMessage\Block\Message\Inline::class,
  39. ['setId', 'setDontDisplayContainer', 'setEntity', 'setCheckoutType', 'toHtml']
  40. );
  41. $this->layoutFactoryMock->expects($this->once())->method('create')->will($this->returnValue($layoutMock));
  42. $layoutMock->expects($this->once())->method('createBlock')->will($this->returnValue($inlineMock));
  43. $inlineMock->expects($this->once())->method('setId')->will($this->returnSelf());
  44. $inlineMock->expects($this->once())->method('setDontDisplayContainer')->will($this->returnSelf());
  45. $inlineMock->expects($this->once())->method('setEntity')->with($entityMock)->will($this->returnSelf());
  46. $inlineMock->expects($this->once())->method('setCheckoutType')->will($this->returnSelf());
  47. $inlineMock->expects($this->once())->method('toHtml')->will($this->returnValue($expectedHtml));
  48. $this->assertEquals($expectedHtml, $this->helper->getInline('onepage_checkout', $entityMock));
  49. }
  50. }