123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\AsynchronousOperations\Test\Unit\Controller\Adminhtml\Notification;
- use Magento\AsynchronousOperations\Model\BulkNotificationManagement;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
- use Magento\Framework\App\RequestInterface;
- use Magento\Framework\Controller\ResultFactory;
- use Magento\AsynchronousOperations\Controller\Adminhtml\Notification\Dismiss;
- use Magento\Framework\Controller\Result\Json;
- class DismissTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var Dismiss
- */
- private $model;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- private $notificationManagementMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- private $requestMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- private $resultFactoryMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- private $jsonResultMock;
- protected function setUp()
- {
- $objectManager = new ObjectManager($this);
- $this->notificationManagementMock = $this->createMock(BulkNotificationManagement::class);
- $this->requestMock = $this->createMock(RequestInterface::class);
- $this->resultFactoryMock = $this->createPartialMock(ResultFactory::class, ['create']);
- $this->jsonResultMock = $this->createMock(Json::class);
- $this->model = $objectManager->getObject(
- Dismiss::class,
- [
- 'notificationManagement' => $this->notificationManagementMock,
- 'request' => $this->requestMock,
- 'resultFactory' => $this->resultFactoryMock,
- ]
- );
- }
- public function testExecute()
- {
- $bulkUuids = ['49da7406-1ec3-4100-95ae-9654c83a6801'];
- $this->requestMock->expects($this->any())
- ->method('getParam')
- ->with('uuid', [])
- ->willReturn($bulkUuids);
- $this->notificationManagementMock->expects($this->once())
- ->method('acknowledgeBulks')
- ->with($bulkUuids)
- ->willReturn(true);
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(ResultFactory::TYPE_JSON, [])
- ->willReturn($this->jsonResultMock);
- $this->assertEquals($this->jsonResultMock, $this->model->execute());
- }
- public function testExecuteSetsBadRequestResponseStatusIfBulkWasNotAcknowledgedCorrectly()
- {
- $bulkUuids = ['49da7406-1ec3-4100-95ae-9654c83a6801'];
- $this->requestMock->expects($this->any())
- ->method('getParam')
- ->with('uuid', [])
- ->willReturn($bulkUuids);
- $this->resultFactoryMock->expects($this->once())
- ->method('create')
- ->with(ResultFactory::TYPE_JSON, [])
- ->willReturn($this->jsonResultMock);
- $this->notificationManagementMock->expects($this->once())
- ->method('acknowledgeBulks')
- ->with($bulkUuids)
- ->willReturn(false);
- $this->jsonResultMock->expects($this->once())
- ->method('setHttpResponseCode')
- ->with(400);
- $this->assertEquals($this->jsonResultMock, $this->model->execute());
- }
- }
|