123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Ui\Test\Unit\Component\Control;
- use Magento\Framework\View\Element\AbstractBlock;
- use Magento\Framework\View\Element\UiComponent\Context;
- use Magento\Framework\View\Element\UiComponentInterface;
- use Magento\Framework\View\LayoutInterface;
- use Magento\Ui\Component\Control\ActionPool;
- class ActionPoolTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * Actions toolbar block name
- */
- const ACTIONS_PAGE_TOOLBAR = 'page.actions.toolbar';
- /**
- * @var ActionPool
- */
- protected $actionPool;
- /**
- * @var Context| \PHPUnit_Framework_MockObject_MockObject
- */
- protected $contextMock;
- /**
- * @var ItemFactory| \PHPUnit_Framework_MockObject_MockObject
- */
- protected $itemFactoryMock;
- /**
- * @var AbstractBlock| \PHPUnit_Framework_MockObject_MockObject
- */
- protected $toolbarBlockMock;
- /**
- * @var UiComponentInterface| \PHPUnit_Framework_MockObject_MockObject
- */
- protected $uiComponentInterfaceMock;
- /**
- * @var Object[]| \PHPUnit_Framework_MockObject_MockObject
- */
- protected $items;
- /**
- * @var LayoutInterface[]| \PHPUnit_Framework_MockObject_MockObject
- */
- protected $layoutMock;
- /**
- * @var string
- */
- protected $key = 'id';
- protected function setUp()
- {
- $this->contextMock = $this->createPartialMock(
- \Magento\Framework\View\Element\UiComponent\Context::class,
- ['getPageLayout']
- );
- $this->toolbarBlockMock = $this->createPartialMock(
- \Magento\Framework\View\Element\AbstractBlock::class,
- ['setChild']
- );
- $this->layoutMock = $this->getMockForAbstractClass(\Magento\Framework\View\LayoutInterface::class);
- $this->contextMock->expects($this->any())->method('getPageLayout')->willReturn($this->layoutMock);
- $this->layoutMock->expects($this->once())
- ->method('getBlock')
- ->with(static::ACTIONS_PAGE_TOOLBAR)
- ->willReturn($this->toolbarBlockMock);
- $this->itemFactoryMock = $this->createPartialMock(\Magento\Ui\Component\Control\ItemFactory::class, ['create']);
- $this->uiComponentInterfaceMock = $this->getMockForAbstractClass(
- \Magento\Framework\View\Element\UiComponentInterface::class
- );
- $this->items[$this->key] = $this->createPartialMock(\Magento\Ui\Component\Control\Item::class, ['setData']);
- $this->actionPool = new ActionPool(
- $this->contextMock,
- $this->itemFactoryMock
- );
- }
- public function testAdd()
- {
- $data = ['id' => 'id'];
- $this->uiComponentInterfaceMock->expects($this->once())->method('getName')->willReturn('name');
- $this->itemFactoryMock->expects($this->any())->method('create')->willReturn($this->items[$this->key]);
- $this->items[$this->key]->expects($this->any())->method('setData')->with($data)->willReturnSelf();
- $this->contextMock->expects($this->any())->method('getPageLayout')->willReturn($this->layoutMock);
- $toolbarContainerMock = $this->createMock(\Magento\Backend\Block\Widget\Button\Toolbar\Container::class);
- $this->layoutMock->expects($this->once())
- ->method('createBlock')
- ->with(
- \Magento\Ui\Component\Control\Container::class,
- 'container-name-' . $this->key,
- [
- 'data' => [
- 'button_item' => $this->items[$this->key],
- 'context' => $this->uiComponentInterfaceMock,
- ]
- ]
- )
- ->willReturn($toolbarContainerMock);
- $this->toolbarBlockMock->expects($this->once())
- ->method('setChild')
- ->with($this->key, $toolbarContainerMock)
- ->willReturnSelf();
- $this->actionPool->add($this->key, $data, $this->uiComponentInterfaceMock);
- }
- public function testRemove()
- {
- $this->testAdd();
- $this->actionPool->remove($this->key);
- }
- public function testUpdate()
- {
- $this->testAdd();
- $data = ['id' => 'id'];
- $this->items[$this->key]->expects($this->any())->method('setData')->with($data)->willReturnSelf();
- $this->actionPool->update($this->key, $data);
- }
- }
|