|
| 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\Widget\Controller\Adminhtml\Widget\Instance; |
| 9 | + |
| 10 | +use Magento\Framework\App\Request\Http; |
| 11 | +use Magento\Framework\Message\MessageInterface; |
| 12 | +use Magento\TestFramework\TestCase\AbstractBackendController; |
| 13 | +use Magento\Widget\Model\ResourceModel\Widget\Instance\CollectionFactory; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test for delete widget controller |
| 17 | + * |
| 18 | + * @see \Magento\Widget\Controller\Adminhtml\Widget\Instance\Delete |
| 19 | + * @magentoAppArea adminhtml |
| 20 | + * @magentoDbIsolation enabled |
| 21 | + */ |
| 22 | +class DeleteTest extends AbstractBackendController |
| 23 | +{ |
| 24 | + /** @var CollectionFactory */ |
| 25 | + private $collectionFactory; |
| 26 | + |
| 27 | + /** |
| 28 | + * @inheritdoc |
| 29 | + */ |
| 30 | + protected function setUp(): void |
| 31 | + { |
| 32 | + parent::setUp(); |
| 33 | + |
| 34 | + $this->collectionFactory = $this->_objectManager->get(CollectionFactory::class); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @magentoDataFixture Magento/Widget/_files/new_widget.php |
| 39 | + * |
| 40 | + * @return void |
| 41 | + */ |
| 42 | + public function testDeleteWidget(): void |
| 43 | + { |
| 44 | + $widget = $this->collectionFactory->create() |
| 45 | + ->addFieldToFilter('title', 'New Sample widget title')->getFirstItem(); |
| 46 | + $this->assertNotNull($widget->getInstanceId()); |
| 47 | + $this->getRequest()->setMethod(Http::METHOD_POST); |
| 48 | + $this->getRequest()->setParams(['instance_id' => $widget->getInstanceId()]); |
| 49 | + $this->dispatch('backend/admin/widget_instance/delete'); |
| 50 | + $this->assertSessionMessages( |
| 51 | + $this->containsEqual((string)__('The widget instance has been deleted.')), |
| 52 | + MessageInterface::TYPE_SUCCESS |
| 53 | + ); |
| 54 | + $this->assertRedirect($this->stringContains('admin/widget_instance/index')); |
| 55 | + } |
| 56 | +} |
0 commit comments