IndexTest.php 3.1 KB

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