|
| 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