Skip to content

Commit 09e6a79

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95368' into 2.2.8-develop-pr71
2 parents c74d384 + daa78fa commit 09e6a79

File tree

2 files changed

+103
-3
lines changed

2 files changed

+103
-3
lines changed

app/code/Magento/Search/Controller/Adminhtml/Synonyms/MassDelete.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
namespace Magento\Search\Controller\Adminhtml\Synonyms;
88

9+
use Magento\Framework\Exception\NotFoundException;
10+
911
/**
10-
* Mass-Delete Controller
12+
* Mass-Delete Controller.
1113
*
1214
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1315
*/
@@ -56,13 +58,17 @@ public function __construct(
5658
}
5759

5860
/**
59-
* Execute action
61+
* Execute action.
6062
*
6163
* @return \Magento\Backend\Model\View\Result\Redirect
62-
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
64+
* @throws \Magento\Framework\Exception\NotFoundException
6365
*/
6466
public function execute()
6567
{
68+
if (!$this->getRequest()->isPost()) {
69+
throw new NotFoundException(__('Page not found.'));
70+
}
71+
6672
$collection = $this->filter->getCollection($this->collectionFactory->create());
6773
$collectionSize = $collection->getSize();
6874

@@ -88,6 +94,7 @@ public function execute()
8894
}
8995
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
9096
$resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
97+
9198
return $resultRedirect->setPath('*/*/');
9299
}
93100
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)