LayoutTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Pricing\Test\Unit\Render;
  7. use \Magento\Framework\Pricing\Render\Layout;
  8. /**
  9. * Test class for \Magento\Framework\Pricing\Render\Layout
  10. */
  11. class LayoutTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var Layout
  15. */
  16. protected $model;
  17. /**
  18. * @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $layout;
  21. /**
  22. * @var \Magento\Framework\View\LayoutFactory|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $layoutFactory;
  25. /**
  26. * @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $generalLayout;
  29. protected function setUp()
  30. {
  31. $this->layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
  32. $this->generalLayout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
  33. $isCacheable = false;
  34. $this->generalLayout->expects($this->once())
  35. ->method('isCacheable')
  36. ->will($this->returnValue(false));
  37. $layoutFactory = $this->getMockBuilder(\Magento\Framework\View\LayoutFactory::class)
  38. ->disableOriginalConstructor()
  39. ->setMethods(['create'])
  40. ->getMock();
  41. $layoutFactory->expects($this->once())
  42. ->method('create')
  43. ->with($this->equalTo(['cacheable' => $isCacheable]))
  44. ->will($this->returnValue($this->layout));
  45. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  46. $this->model = $objectManager->getObject(
  47. \Magento\Framework\Pricing\Render\Layout::class,
  48. [
  49. 'layoutFactory' => $layoutFactory,
  50. 'generalLayout' => $this->generalLayout
  51. ]
  52. );
  53. }
  54. public function testAddHandle()
  55. {
  56. $handle = 'test_handle';
  57. $layoutProcessor = $this->createMock(\Magento\Framework\View\Layout\ProcessorInterface::class);
  58. $layoutProcessor->expects($this->once())
  59. ->method('addHandle')
  60. ->with($handle);
  61. $this->layout->expects($this->once())
  62. ->method('getUpdate')
  63. ->will($this->returnValue($layoutProcessor));
  64. $this->model->addHandle($handle);
  65. }
  66. public function testLoadLayout()
  67. {
  68. $layoutProcessor = $this->createMock(\Magento\Framework\View\Layout\ProcessorInterface::class);
  69. $layoutProcessor->expects($this->once())
  70. ->method('load');
  71. $this->layout->expects($this->once())
  72. ->method('getUpdate')
  73. ->will($this->returnValue($layoutProcessor));
  74. $this->layout->expects($this->once())
  75. ->method('generateXml');
  76. $this->layout->expects($this->once())
  77. ->method('generateElements');
  78. $this->model->loadLayout();
  79. }
  80. public function testGetBlock()
  81. {
  82. $blockName = 'block.name';
  83. $block = $this->createMock(\Magento\Framework\View\Element\BlockInterface::class);
  84. $this->layout->expects($this->once())
  85. ->method('getBlock')
  86. ->with($blockName)
  87. ->will($this->returnValue($block));
  88. $this->assertEquals($block, $this->model->getBlock($blockName));
  89. }
  90. }