|
| 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\Search\Test\Unit\Controller\Adminhtml\Synonyms; |
| 9 | + |
| 10 | +/** |
| 11 | + * Unit tests for Magento\Search\Controller\Adminhtml\Synonyms\MassDelete controller. |
| 12 | + */ |
| 13 | +class MassDeleteTest extends \PHPUnit\Framework\TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var \Magento\Search\Controller\Adminhtml\Synonyms\MassDelete |
| 17 | + */ |
| 18 | + private $controller; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + private $contextMock; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject |
| 27 | + */ |
| 28 | + private $filterMock; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var \Magento\Search\Model\ResourceModel\SynonymGroup\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject |
| 32 | + */ |
| 33 | + private $collectionFactoryMock; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var \Magento\Search\Api\SynonymGroupRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
| 37 | + */ |
| 38 | + private $synGroupRepositoryMock; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject |
| 42 | + */ |
| 43 | + private $requestMock; |
| 44 | + |
| 45 | + /** |
| 46 | + * @inheritdoc |
| 47 | + */ |
| 48 | + protected function setUp() |
| 49 | + { |
| 50 | + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 51 | + |
| 52 | + $this->requestMock = $this->getMockForAbstractClass( |
| 53 | + \Magento\Framework\App\RequestInterface::class, |
| 54 | + [], |
| 55 | + '', |
| 56 | + false, |
| 57 | + true, |
| 58 | + true, |
| 59 | + ['isPost'] |
| 60 | + ); |
| 61 | + $this->contextMock = $this->createMock(\Magento\Backend\App\Action\Context::class); |
| 62 | + $this->filterMock = $this->createMock(\Magento\Ui\Component\MassAction\Filter::class); |
| 63 | + $this->collectionFactoryMock = $this->createMock( |
| 64 | + \Magento\Search\Model\ResourceModel\SynonymGroup\CollectionFactory::class |
| 65 | + ); |
| 66 | + $this->synGroupRepositoryMock = $this->createMock(\Magento\Search\Api\SynonymGroupRepositoryInterface::class); |
| 67 | + |
| 68 | + $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); |
| 69 | + |
| 70 | + $this->controller = $objectManagerHelper->getObject( |
| 71 | + \Magento\Search\Controller\Adminhtml\Synonyms\MassDelete::class, |
| 72 | + [ |
| 73 | + 'context' => $this->contextMock, |
| 74 | + 'filter' => $this->filterMock, |
| 75 | + 'collectionFactory' => $this->collectionFactoryMock, |
| 76 | + 'synGroupRepository' => $this->synGroupRepositoryMock, |
| 77 | + ] |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Check that error throws when request is not POST. |
| 83 | + * |
| 84 | + * @return void |
| 85 | + * @expectedException \Magento\Framework\Exception\NotFoundException |
| 86 | + */ |
| 87 | + public function testExecuteWithNotPostRequest() |
| 88 | + { |
| 89 | + $this->requestMock->expects($this->once())->method('isPost')->willReturn(false); |
| 90 | + |
| 91 | + $this->controller->execute(); |
| 92 | + } |
| 93 | +} |
0 commit comments