1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\AsynchronousOperations\Test\Unit\Controller\Adminhtml\Index;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $viewMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $requestMock;
/**
* @var \Magento\AsynchronousOperations\Controller\Adminhtml\Index\Index
*/
private $model;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $resultFactoryMock;
protected function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->viewMock = $this->createMock(\Magento\Framework\App\ViewInterface::class);
$this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
$this->resultFactoryMock = $this->createMock(\Magento\Framework\View\Result\PageFactory::class);
$this->model = $objectManager->getObject(
\Magento\AsynchronousOperations\Controller\Adminhtml\Index\Index::class,
[
'request' => $this->requestMock,
'view' => $this->viewMock,
'resultPageFactory' => $this->resultFactoryMock
]
);
}
public function testExecute()
{
$itemId = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations';
$prependText = 'Bulk Actions Log';
$layoutMock = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
$menuModelMock = $this->createMock(\Magento\Backend\Model\Menu::class);
$pageMock = $this->createMock(\Magento\Framework\View\Result\Page::class);
$pageConfigMock = $this->createMock(\Magento\Framework\View\Page\Config::class);
$titleMock = $this->createMock(\Magento\Framework\View\Page\Title::class);
$this->resultFactoryMock->expects($this->once())->method('create')->willReturn($pageMock);
$blockMock = $this->createPartialMock(
\Magento\Framework\View\Element\BlockInterface::class,
['setActive', 'getMenuModel', 'toHtml']
);
$this->viewMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
$layoutMock->expects($this->once())->method('getBlock')->willReturn($blockMock);
$blockMock->expects($this->once())->method('setActive')->with($itemId);
$blockMock->expects($this->once())->method('getMenuModel')->willReturn($menuModelMock);
$menuModelMock->expects($this->once())->method('getParentItems')->willReturn([]);
$pageMock->expects($this->once())->method('getConfig')->willReturn($pageConfigMock);
$pageConfigMock->expects($this->once())->method('getTitle')->willReturn($titleMock);
$titleMock->expects($this->once())->method('prepend')->with($prependText);
$pageMock->expects($this->once())->method('initLayout');
$this->model->execute();
}
}