Skip to content

Commit 58ad4b0

Browse files
committed
MC-37564: Create automated test for "Delete CMS Block"
1 parent edfbc39 commit 58ad4b0

File tree

1 file changed

+67
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Block

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\Cms\Controller\Adminhtml\Block;
9+
10+
use Magento\Cms\Api\Data\BlockInterface;
11+
use Magento\Cms\Api\GetBlockByIdentifierInterface;
12+
use Magento\Framework\App\Request\Http;
13+
use Magento\Framework\Message\MessageInterface;
14+
use Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\TestFramework\TestCase\AbstractBackendController;
17+
18+
/**
19+
* Checks that cms block can be successfully deleted
20+
*
21+
* @magentoAppArea adminhtml
22+
* @magentoDbIsolation disabled
23+
*/
24+
class DeleteTest extends AbstractBackendController
25+
{
26+
/** @var GetBlockByIdentifierInterface */
27+
private $getBlockByIdentifierInterface;
28+
29+
/** @var StoreManagerInterface */
30+
private $storeManager;
31+
32+
/** @var CollectionFactory */
33+
private $collectionFactory;
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
protected function setUp(): void
39+
{
40+
parent::setUp();
41+
42+
$this->getBlockByIdentifierInterface = $this->_objectManager->get(GetBlockByIdentifierInterface::class);
43+
$this->storeManager = $this->_objectManager->get(StoreManagerInterface::class);
44+
$this->collectionFactory = $this->_objectManager->get(CollectionFactory::class);
45+
}
46+
47+
/**
48+
* @magentoDataFixture Magento/Cms/_files/block_default_store.php
49+
*
50+
* @return void
51+
*/
52+
public function testDeleteBlock(): void
53+
{
54+
$defaultStoreId = (int)$this->storeManager->getStore('default')->getId();
55+
$blockId = $this->getBlockByIdentifierInterface->execute('default_store_block', $defaultStoreId)->getId();
56+
$this->getRequest()->setMethod(Http::METHOD_POST)
57+
->setParams(['block_id' => $blockId]);
58+
$this->dispatch('backend/cms/block/delete');
59+
$this->assertSessionMessages(
60+
$this->containsEqual((string)__('You deleted the block.')),
61+
MessageInterface::TYPE_SUCCESS
62+
);
63+
$this->assertRedirect($this->stringContains('cms/block/index'));
64+
$collection = $this->collectionFactory->getReport('cms_block_listing_data_source');
65+
$this->assertNull($collection->getItemByColumnValue(BlockInterface::IDENTIFIER, 'default_store_block'));
66+
}
67+
}

0 commit comments

Comments
 (0)