Skip to content

Commit 0aa60f2

Browse files
Merge remote-tracking branch '36323/2.4-develop' into comm_voted_v2
2 parents 186feb7 + 6fe3a11 commit 0aa60f2

File tree

3 files changed

+164
-3
lines changed

3 files changed

+164
-3
lines changed

app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(
5151
*/
5252
public function execute()
5353
{
54-
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
54+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::PUB);
5555
// check if we know what should be deleted
5656
$id = $this->getRequest()->getParam('sitemap_id');
5757
if ($id) {

app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Save.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Save extends Sitemap implements HttpPostActionInterface
2828
/**
2929
* Maximum length of sitemap filename
3030
*/
31-
const MAX_FILENAME_LENGTH = 32;
31+
public const MAX_FILENAME_LENGTH = 32;
3232

3333
/**
3434
* @var StringLength
@@ -128,7 +128,7 @@ protected function validatePath(array $data)
128128
protected function clearSiteMap(\Magento\Sitemap\Model\Sitemap $model)
129129
{
130130
/** @var Filesystem $directory */
131-
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
131+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::PUB);
132132

133133
if ($this->getRequest()->getParam('sitemap_id')) {
134134
$model->load($this->getRequest()->getParam('sitemap_id'));
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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\Sitemap\Test\Unit\Controller\Adminhtml\Sitemap;
9+
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Backend\Helper\Data;
12+
use Magento\Backend\Model\Session;
13+
use Magento\Framework\App\ActionFlag;
14+
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\App\ResponseInterface;
16+
use Magento\Framework\Filesystem;
17+
use Magento\Framework\HTTP\PhpEnvironment\Request;
18+
use Magento\Framework\Message\ManagerInterface;
19+
use Magento\Framework\ObjectManagerInterface;
20+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
21+
use Magento\Sitemap\Controller\Adminhtml\Sitemap\Delete;
22+
use Magento\Sitemap\Model\SitemapFactory;
23+
use PHPUnit\Framework\TestCase;
24+
25+
/**
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
*/
28+
class DeleteTest extends TestCase
29+
{
30+
/**
31+
* @var Context
32+
*/
33+
private $contextMock;
34+
35+
/**
36+
* @var Request
37+
*/
38+
private $requestMock;
39+
40+
/**
41+
* @var ObjectManagerInterface
42+
*/
43+
private $objectManagerMock;
44+
45+
/**
46+
* @var ManagerInterface
47+
*/
48+
private $messageManagerMock;
49+
50+
/**
51+
* @var Filesystem
52+
*/
53+
private $fileSystem;
54+
55+
/**
56+
* @var SitemapFactory
57+
*/
58+
private $siteMapFactory;
59+
60+
/**
61+
* @var Delete
62+
*/
63+
private $deleteController;
64+
65+
/**
66+
* @var Session
67+
*/
68+
private $sessionMock;
69+
70+
/**
71+
* @var ActionFlag
72+
*/
73+
private $actionFlag;
74+
75+
/**
76+
* @var ObjectManager
77+
*/
78+
private $objectManager;
79+
80+
/**
81+
* @var ResponseInterface
82+
*/
83+
private $response;
84+
85+
/**
86+
* @var Data
87+
*/
88+
private $helperMock;
89+
90+
protected function setUp(): void
91+
{
92+
$this->contextMock = $this->getMockBuilder(Context::class)
93+
->disableOriginalConstructor()
94+
->getMock();
95+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
96+
->disableOriginalConstructor()
97+
->setMethods(['getParam'])
98+
->getMockForAbstractClass();
99+
$this->sessionMock = $this->getMockBuilder(Session::class)
100+
->disableOriginalConstructor()
101+
->addMethods(['setIsUrlNotice'])
102+
->getMock();
103+
$this->response = $this->getMockBuilder(ResponseInterface::class)
104+
->addMethods(['setRedirect'])
105+
->onlyMethods(['sendResponse'])
106+
->getMockForAbstractClass();
107+
$this->response->expects($this->once())->method('setRedirect');
108+
$this->sessionMock->expects($this->any())->method('setIsUrlNotice')->willReturn($this->objectManager);
109+
$this->actionFlag = $this->createPartialMock(ActionFlag::class, ['get']);
110+
$this->actionFlag->expects($this->any())->method("get")->willReturn($this->objectManager);
111+
$this->objectManager = $this->getMockBuilder(ObjectManager::class)
112+
->addMethods(['get'])
113+
->disableOriginalConstructor()
114+
->getMock();
115+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
116+
->getMock();
117+
$this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)
118+
->getMock();
119+
$this->helperMock = $this->getMockBuilder(Data::class)
120+
->disableOriginalConstructor()
121+
->onlyMethods(['getUrl'])
122+
->getMock();
123+
$this->helperMock->expects($this->any())
124+
->method('getUrl')
125+
->willReturn('adminhtml/*/');
126+
$this->contextMock->expects($this->any())
127+
->method('getSession')
128+
->willReturn($this->sessionMock);
129+
$this->contextMock->expects($this->once())
130+
->method('getMessageManager')
131+
->willReturn($this->messageManagerMock);
132+
$this->contextMock->expects($this->once())
133+
->method('getRequest')
134+
->willReturn($this->requestMock);
135+
$this->contextMock->expects($this->once())
136+
->method('getResponse')
137+
->willReturn($this->response);
138+
$this->contextMock->expects($this->any())
139+
->method('getHelper')
140+
->willReturn($this->helperMock);
141+
$this->contextMock->expects($this->any())->method("getActionFlag")->willReturn($this->actionFlag);
142+
$this->fileSystem = $this->createMock(Filesystem::class);
143+
$this->siteMapFactory = $this->createMock(SitemapFactory::class);
144+
$this->deleteController = new Delete(
145+
$this->contextMock,
146+
$this->siteMapFactory,
147+
$this->fileSystem
148+
);
149+
}
150+
151+
public function testDelete()
152+
{
153+
$this->requestMock->expects($this->once())
154+
->method('getParam')
155+
->willReturn(null);
156+
157+
$this->messageManagerMock->expects($this->never())
158+
->method('addSuccessMessage');
159+
$this->deleteController->execute();
160+
}
161+
}

0 commit comments

Comments
 (0)