Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RendererListTest.php
Go to the documentation of this file.
1 <?php
7 
8 class RendererListTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $renderList;
14 
18  protected $contextMock;
19 
23  protected $layoutMock;
24 
28  protected $blockMock;
29 
30  protected function setUp()
31  {
32  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33 
34  $this->blockMock = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class)
35  ->setMethods(['setRenderedBlock', 'getTemplate', 'setTemplate'])->disableOriginalConstructor()
36  ->getMockForAbstractClass();
37 
38  $this->layoutMock = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class)
39  ->setMethods(['getBlock', 'getChildName'])->disableOriginalConstructor()->getMockForAbstractClass();
40 
41  $this->layoutMock->expects($this->any())
42  ->method('getBlock')
43  ->will($this->returnValue($this->blockMock));
44 
45  $this->contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\Context::class)
46  ->setMethods(['getLayout'])->disableOriginalConstructor()->getMock();
47 
48  $this->contextMock->expects($this->any())
49  ->method('getLayout')
50  ->will($this->returnValue($this->layoutMock));
51 
52  $this->renderList = $objectManagerHelper->getObject(
53  \Magento\Framework\View\Element\RendererList::class,
54  ['context' => $this->contextMock]
55  );
56  }
57 
58  public function testGetRenderer()
59  {
60  $this->blockMock->expects($this->any())
61  ->method('setRenderedBlock')
62  ->will($this->returnValue($this->blockMock));
63 
64  $this->blockMock->expects($this->any())
65  ->method('getTemplate')
66  ->will($this->returnValue('template'));
67 
68  $this->blockMock->expects($this->any())
69  ->method('setTemplate')
70  ->will($this->returnValue($this->blockMock));
71 
72  $this->layoutMock->expects($this->any())
73  ->method('getChildName')
74  ->will($this->returnValue(true));
75 
77  $this->assertInstanceOf(
78  \Magento\Framework\View\Element\BlockInterface::class,
79  $this->renderList->getRenderer('type', null, null)
80  );
82  $this->assertInstanceOf(
83  \Magento\Framework\View\Element\BlockInterface::class,
84  $this->renderList->getRenderer('type', null, 'renderer_template')
85  );
86  }
87 
91  public function testGetRendererWithException()
92  {
93  $this->assertInstanceOf(
94  \Magento\Framework\View\Element\BlockInterface::class,
95  $this->renderList->getRenderer(null)
96  );
97  }
98 }