ContainerTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Test\Unit\Component\Control;
  7. use \Magento\Ui\Component\Control\Container;
  8. class ContainerTest extends \PHPUnit\Framework\TestCase
  9. {
  10. public function testToHtml()
  11. {
  12. $data = [];
  13. $id = 1;
  14. $nameInLayout = 'test-name';
  15. $blockName = $nameInLayout . '-' . $id . '-button';
  16. $expectedHtml = 'test html';
  17. $blockButtonMock = $this->createMock(Container::DEFAULT_CONTROL);
  18. $blockButtonMock->expects($this->once())->method('toHtml')->willReturn($expectedHtml);
  19. $contextMock = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
  20. $eventManagerMock = $this->getMockForAbstractClass(\Magento\Framework\Event\ManagerInterface::class);
  21. $contextMock->expects($this->any())->method('getEventManager')->willReturn($eventManagerMock);
  22. $scopeConfigMock = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  23. $scopeConfigMock->expects($this->any())->method('getValue')->withAnyParameters()->willReturn(false);
  24. $contextMock->expects($this->any())->method('getScopeConfig')->willReturn($scopeConfigMock);
  25. $layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
  26. $layoutMock->expects($this->once())
  27. ->method('createBlock')
  28. ->with(Container::DEFAULT_CONTROL, $blockName)
  29. ->willReturn($blockButtonMock);
  30. $contextMock->expects($this->any())->method('getLayout')->willReturn($layoutMock);
  31. $itemMock = $this->createPartialMock(\Magento\Ui\Component\Control\Item::class, ['getId', 'getData']);
  32. $itemMock->expects($this->any())->method('getData')->willReturn($data);
  33. $itemMock->expects($this->any())->method('getId')->willReturn($id);
  34. $abstractContextMock = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class)
  35. ->disableOriginalConstructor()
  36. ->setMethods(['getNameInLayout'])
  37. ->getMockForAbstractClass();
  38. $abstractContextMock->expects($this->any())->method('getNameInLayout')->willReturn($nameInLayout);
  39. $container = new Container($contextMock);
  40. $container->setButtonItem($itemMock);
  41. $container->setData('context', $abstractContextMock);
  42. $this->assertEquals($expectedHtml, $container->toHtml());
  43. }
  44. }