DismissTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\Notification;
  7. use Magento\AsynchronousOperations\Model\BulkNotificationManagement;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. use Magento\Framework\App\RequestInterface;
  10. use Magento\Framework\Controller\ResultFactory;
  11. use Magento\AsynchronousOperations\Controller\Adminhtml\Notification\Dismiss;
  12. use Magento\Framework\Controller\Result\Json;
  13. class DismissTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var Dismiss
  17. */
  18. private $model;
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject
  21. */
  22. private $notificationManagementMock;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. private $requestMock;
  27. /**
  28. * @var \PHPUnit_Framework_MockObject_MockObject
  29. */
  30. private $resultFactoryMock;
  31. /**
  32. * @var \PHPUnit_Framework_MockObject_MockObject
  33. */
  34. private $jsonResultMock;
  35. protected function setUp()
  36. {
  37. $objectManager = new ObjectManager($this);
  38. $this->notificationManagementMock = $this->createMock(BulkNotificationManagement::class);
  39. $this->requestMock = $this->createMock(RequestInterface::class);
  40. $this->resultFactoryMock = $this->createPartialMock(ResultFactory::class, ['create']);
  41. $this->jsonResultMock = $this->createMock(Json::class);
  42. $this->model = $objectManager->getObject(
  43. Dismiss::class,
  44. [
  45. 'notificationManagement' => $this->notificationManagementMock,
  46. 'request' => $this->requestMock,
  47. 'resultFactory' => $this->resultFactoryMock,
  48. ]
  49. );
  50. }
  51. public function testExecute()
  52. {
  53. $bulkUuids = ['49da7406-1ec3-4100-95ae-9654c83a6801'];
  54. $this->requestMock->expects($this->any())
  55. ->method('getParam')
  56. ->with('uuid', [])
  57. ->willReturn($bulkUuids);
  58. $this->notificationManagementMock->expects($this->once())
  59. ->method('acknowledgeBulks')
  60. ->with($bulkUuids)
  61. ->willReturn(true);
  62. $this->resultFactoryMock->expects($this->once())
  63. ->method('create')
  64. ->with(ResultFactory::TYPE_JSON, [])
  65. ->willReturn($this->jsonResultMock);
  66. $this->assertEquals($this->jsonResultMock, $this->model->execute());
  67. }
  68. public function testExecuteSetsBadRequestResponseStatusIfBulkWasNotAcknowledgedCorrectly()
  69. {
  70. $bulkUuids = ['49da7406-1ec3-4100-95ae-9654c83a6801'];
  71. $this->requestMock->expects($this->any())
  72. ->method('getParam')
  73. ->with('uuid', [])
  74. ->willReturn($bulkUuids);
  75. $this->resultFactoryMock->expects($this->once())
  76. ->method('create')
  77. ->with(ResultFactory::TYPE_JSON, [])
  78. ->willReturn($this->jsonResultMock);
  79. $this->notificationManagementMock->expects($this->once())
  80. ->method('acknowledgeBulks')
  81. ->with($bulkUuids)
  82. ->willReturn(false);
  83. $this->jsonResultMock->expects($this->once())
  84. ->method('setHttpResponseCode')
  85. ->with(400);
  86. $this->assertEquals($this->jsonResultMock, $this->model->execute());
  87. }
  88. }