|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Review\Test\Unit\Controller\Adminhtml\Product; |
| 9 | + |
| 10 | +use Magento\Backend\App\Action\Context; |
| 11 | +use Magento\Framework\App\RequestInterface; |
| 12 | +use Magento\Framework\Controller\Result\Redirect; |
| 13 | +use Magento\Framework\Controller\ResultFactory; |
| 14 | +use Magento\Framework\Message\ManagerInterface; |
| 15 | +use Magento\Framework\Registry; |
| 16 | +use Magento\Review\Controller\Adminhtml\Product\MassDelete; |
| 17 | +use Magento\Review\Model\RatingFactory; |
| 18 | +use Magento\Review\Model\ResourceModel\Review as ReviewResourceModel; |
| 19 | +use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection; |
| 20 | +use Magento\Review\Model\ResourceModel\Review\CollectionFactory as ReviewCollectionFactory; |
| 21 | +use Magento\Review\Model\ReviewFactory; |
| 22 | +use PHPUnit\Framework\MockObject\MockObject; |
| 23 | +use PHPUnit\Framework\TestCase; |
| 24 | + |
| 25 | +class MassDeleteTest extends TestCase |
| 26 | +{ |
| 27 | + /** |
| 28 | + * @var MassDelete |
| 29 | + */ |
| 30 | + private $massDelete; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var RequestInterface|MockObject |
| 34 | + */ |
| 35 | + private $requestMock; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var ReviewCollectionFactory|MockObject |
| 39 | + */ |
| 40 | + private $collectionFactoryMock; |
| 41 | + |
| 42 | + /** |
| 43 | + * @inheritdoc |
| 44 | + */ |
| 45 | + protected function setUp(): void |
| 46 | + { |
| 47 | + $contextMock = $this->createMock(Context::class); |
| 48 | + $this->requestMock = $this->createMock(RequestInterface::class); |
| 49 | + $contextMock->method('getRequest') |
| 50 | + ->willReturn($this->requestMock); |
| 51 | + $messageManagerMock = $this->createMock(ManagerInterface::class); |
| 52 | + $contextMock->method('getMessageManager') |
| 53 | + ->willReturn($messageManagerMock); |
| 54 | + $resultFactoryMock = $this->createMock(ResultFactory::class); |
| 55 | + $contextMock->method('getResultFactory') |
| 56 | + ->willReturn($resultFactoryMock); |
| 57 | + $resultMock = $this->createMock(Redirect::class); |
| 58 | + $resultFactoryMock->method('create') |
| 59 | + ->willReturn($resultMock); |
| 60 | + |
| 61 | + $coreRegistryMock = $this->createMock(Registry::class); |
| 62 | + $reviewFactoryMock = $this->createMock(ReviewFactory::class); |
| 63 | + $ratingFactoryMock = $this->createMock(RatingFactory::class); |
| 64 | + $this->collectionFactoryMock = $this->createMock(ReviewCollectionFactory::class); |
| 65 | + |
| 66 | + $this->massDelete = new MassDelete( |
| 67 | + $contextMock, |
| 68 | + $coreRegistryMock, |
| 69 | + $reviewFactoryMock, |
| 70 | + $ratingFactoryMock, |
| 71 | + $this->collectionFactoryMock |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + public function testExecute(): void |
| 76 | + { |
| 77 | + $this->requestMock->expects(self::atLeastOnce()) |
| 78 | + ->method('getParam') |
| 79 | + ->willReturnMap( |
| 80 | + [ |
| 81 | + ['reviews', null, [10, 20]], |
| 82 | + ['ret', 'index', 'index'], |
| 83 | + ] |
| 84 | + ); |
| 85 | + |
| 86 | + $collectionMock = $this->createMock(ReviewCollection::class); |
| 87 | + $this->collectionFactoryMock->expects(self::once()) |
| 88 | + ->method('create') |
| 89 | + ->willReturn($collectionMock); |
| 90 | + $resource = $this->createMock(ReviewResourceModel::class); |
| 91 | + $collectionMock->method('getResource') |
| 92 | + ->willReturn($resource); |
| 93 | + $resource->method('getIdFieldName') |
| 94 | + ->willReturn('id'); |
| 95 | + $collectionMock->expects(self::once()) |
| 96 | + ->method('addFieldToFilter') |
| 97 | + ->with('main_table.id', [10, 20]) |
| 98 | + ->willReturnSelf(); |
| 99 | + $collectionMock->expects(self::once()) |
| 100 | + ->method('addStoreData') |
| 101 | + ->willReturnSelf(); |
| 102 | + |
| 103 | + $this->massDelete->execute(); |
| 104 | + } |
| 105 | +} |
0 commit comments