![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-ui/Test/Unit/Component/Control/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Ui\Test\Unit\Component\Control; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Event\ManagerInterface; use Magento\Framework\View\Element\AbstractBlock; use Magento\Framework\View\Element\Template\Context; use Magento\Framework\View\Layout; use Magento\Ui\Component\Control\Container; use Magento\Ui\Component\Control\Item; use PHPUnit\Framework\TestCase; class ContainerTest extends TestCase { public function testToHtml() { $data = []; $id = 1; $nameInLayout = 'test-name'; $blockName = $nameInLayout . '-' . $id . '-button'; $expectedHtml = 'test html'; $blockButtonMock = $this->createMock(Container::DEFAULT_CONTROL); $blockButtonMock->expects($this->once())->method('toHtml')->willReturn($expectedHtml); $contextMock = $this->createMock(Context::class); $eventManagerMock = $this->getMockForAbstractClass(ManagerInterface::class); $contextMock->expects($this->any())->method('getEventManager')->willReturn($eventManagerMock); $scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class); $scopeConfigMock->expects($this->any())->method('getValue')->withAnyParameters()->willReturn(false); $contextMock->expects($this->any())->method('getScopeConfig')->willReturn($scopeConfigMock); $layoutMock = $this->createMock(Layout::class); $layoutMock->expects($this->once()) ->method('createBlock') ->with(Container::DEFAULT_CONTROL, $blockName) ->willReturn($blockButtonMock); $contextMock->expects($this->any())->method('getLayout')->willReturn($layoutMock); $itemMock = $this->getMockBuilder(Item::class) ->addMethods(['getId']) ->onlyMethods(['getData']) ->disableOriginalConstructor() ->getMock(); $itemMock->expects($this->any())->method('getData')->willReturn($data); $itemMock->expects($this->any())->method('getId')->willReturn($id); $abstractContextMock = $this->getMockBuilder(AbstractBlock::class) ->disableOriginalConstructor() ->setMethods(['getNameInLayout']) ->getMockForAbstractClass(); $abstractContextMock->expects($this->any())->method('getNameInLayout')->willReturn($nameInLayout); $container = new Container($contextMock); $container->setButtonItem($itemMock); $container->setData('context', $abstractContextMock); $this->assertEquals($expectedHtml, $container->toHtml()); } }