PdfDocumentsMassActionTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Controller\Adminhtml;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class PdfDocumentsMassActionTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Sales\Controller\Adminhtml\Order\PdfDocumentsMassAction
  12. */
  13. private $controller;
  14. /**
  15. * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $resultRedirect;
  18. /**
  19. * @var \Magento\Framework\Message\Manager|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $messageManager;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $orderCollectionFactoryMock;
  26. /**
  27. * @var \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. private $orderCollectionMock;
  30. /**
  31. * @var \PHPUnit_Framework_MockObject_MockObject
  32. */
  33. private $filterMock;
  34. /**
  35. * Test setup
  36. */
  37. protected function setUp()
  38. {
  39. $objectManagerHelper = new ObjectManagerHelper($this);
  40. $this->messageManager = $this->createPartialMock(
  41. \Magento\Framework\Message\Manager::class,
  42. ['addSuccessMessage', 'addErrorMessage']
  43. );
  44. $this->orderCollectionMock = $this->createMock(\Magento\Sales\Model\ResourceModel\Order\Collection::class);
  45. $this->filterMock = $this->createMock(\Magento\Ui\Component\MassAction\Filter::class);
  46. $this->orderCollectionFactoryMock = $this->createPartialMock(
  47. \Magento\Sales\Model\ResourceModel\Order\CollectionFactory::class,
  48. ['create']
  49. );
  50. $this->orderCollectionFactoryMock
  51. ->expects($this->once())
  52. ->method('create')
  53. ->willReturn($this->orderCollectionMock);
  54. $this->resultRedirect = $this->createMock(\Magento\Backend\Model\View\Result\Redirect::class);
  55. $resultRedirectFactory = $this->createMock(\Magento\Framework\Controller\ResultFactory::class);
  56. $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
  57. $this->controller = $objectManagerHelper->getObject(
  58. \Magento\Sales\Controller\Adminhtml\Order\Pdfinvoices::class,
  59. [
  60. 'filter' => $this->filterMock,
  61. 'resultFactory' => $resultRedirectFactory,
  62. 'messageManager' => $this->messageManager
  63. ]
  64. );
  65. $objectManagerHelper
  66. ->setBackwardCompatibleProperty(
  67. $this->controller,
  68. 'orderCollectionFactory',
  69. $this->orderCollectionFactoryMock
  70. );
  71. }
  72. /**
  73. * @throws \Magento\Framework\Exception\LocalizedException
  74. */
  75. public function testExecute()
  76. {
  77. $exception = new \Exception();
  78. $this->filterMock
  79. ->expects($this->once())
  80. ->method('getCollection')
  81. ->with($this->orderCollectionMock)
  82. ->willThrowException($exception);
  83. $this->messageManager->expects($this->once())->method('addErrorMessage');
  84. $this->resultRedirect->expects($this->once())->method('setPath')->willReturnSelf();
  85. $this->controller->execute($exception);
  86. }
  87. }