DetailsTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Bulk;
  7. /**
  8. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  9. */
  10. class DetailsTest 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\Bulk\Details
  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\Bulk\Details::class,
  36. [
  37. 'request' => $this->requestMock,
  38. 'resultPageFactory' => $this->resultFactoryMock,
  39. 'view' => $this->viewMock,
  40. ]
  41. );
  42. }
  43. public function testExecute()
  44. {
  45. $id = '42';
  46. $parameterName = 'uuid';
  47. $itemId = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations';
  48. $layoutMock = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
  49. $blockMock = $this->createPartialMock(
  50. \Magento\Framework\View\Element\BlockInterface::class,
  51. ['setActive', 'getMenuModel', 'toHtml']
  52. );
  53. $menuModelMock = $this->createMock(\Magento\Backend\Model\Menu::class);
  54. $this->viewMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
  55. $layoutMock->expects($this->once())->method('getBlock')->willReturn($blockMock);
  56. $blockMock->expects($this->once())->method('setActive')->with($itemId);
  57. $blockMock->expects($this->once())->method('getMenuModel')->willReturn($menuModelMock);
  58. $menuModelMock->expects($this->once())->method('getParentItems')->willReturn([]);
  59. $pageMock = $this->createMock(\Magento\Framework\View\Result\Page::class);
  60. $pageConfigMock = $this->createMock(\Magento\Framework\View\Page\Config::class);
  61. $titleMock = $this->createMock(\Magento\Framework\View\Page\Title::class);
  62. $this->resultFactoryMock->expects($this->once())->method('create')->willReturn($pageMock);
  63. $this->requestMock->expects($this->once())->method('getParam')->with($parameterName)->willReturn($id);
  64. $pageMock->expects($this->once())->method('getConfig')->willReturn($pageConfigMock);
  65. $pageConfigMock->expects($this->once())->method('getTitle')->willReturn($titleMock);
  66. $titleMock->expects($this->once())->method('prepend')->with($this->stringContains($id));
  67. $pageMock->expects($this->once())->method('initLayout');
  68. $this->assertEquals($pageMock, $this->model->execute());
  69. }
  70. }