Skip to content

Commit d3c9715

Browse files
committed
MC-20703: Admin: Delete a category
1 parent 50de44e commit d3c9715

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/DeleteTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,33 @@
1515
* Test for class \Magento\Catalog\Controller\Adminhtml\Category\Delete
1616
*
1717
* @magentoAppArea adminhtml
18-
* @magentoDbIsolation enabled
1918
*/
2019
class DeleteTest extends AbstractBackendController
2120
{
2221
/**
2322
* @return void
2423
*/
25-
public function testWithError(): void
24+
public function testDeleteMissingCategory(): void
2625
{
2726
$incorrectId = 825852;
28-
$postData = ['id' => $incorrectId];
2927
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
30-
$this->getRequest()->setPostValue($postData);
28+
$this->getRequest()->setPostValue(['id' => $incorrectId]);
3129
$this->dispatch('backend/catalog/category/delete');
3230
$this->assertSessionMessages(
3331
$this->equalTo([(string)__(sprintf('No such entity with id = %s', $incorrectId))]),
3432
MessageInterface::TYPE_ERROR
3533
);
3634
}
35+
36+
/**
37+
* @magentoDbIsolation enabled
38+
* @magentoDataFixture Magento/Catalog/_files/category.php
39+
*/
40+
public function testDeleteCategory(): void
41+
{
42+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
43+
$this->getRequest()->setPostValue(['id' => 333]);
44+
$this->dispatch('backend/catalog/category/delete');
45+
$this->assertSessionMessages($this->equalTo([(string)__('You deleted the category.')]));
46+
}
3747
}

dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryRepositoryTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Api\CategoryRepositoryInterface;
1212
use Magento\Catalog\Api\Data\CategoryInterface;
1313
use Magento\Catalog\Api\Data\CategoryInterfaceFactory;
14+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
1415
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1516
use Magento\Framework\Acl\Builder;
1617
use Magento\Framework\ObjectManagerInterface;
@@ -51,6 +52,9 @@ class CategoryRepositoryTest extends TestCase
5152
/** @var ObjectManagerInterface */
5253
private $objectManager;
5354

55+
/** @var CategoryCollectionFactory */
56+
private $categoryCollectionFactory;
57+
5458
/**
5559
* Sets up common objects.
5660
*
@@ -64,6 +68,7 @@ protected function setUp()
6468
$this->aclBuilder = $this->objectManager->get(Builder::class);
6569
$this->categoryFactory = $this->objectManager->get(CategoryInterfaceFactory::class);
6670
$this->productCollectionFactory = $this->objectManager->get(CollectionFactory::class);
71+
$this->categoryCollectionFactory = $this->objectManager->create(CategoryCollectionFactory::class);
6772
}
6873

6974
/**
@@ -127,20 +132,23 @@ public function testSaveDesign(): void
127132
* @magentoAppArea adminhtml
128133
* @return void
129134
*/
130-
public function testDeleteCategory(): void
135+
public function testCheckCategoryBehaviourAfterDelete(): void
131136
{
132137
$productCollection = $this->productCollectionFactory->create();
133-
$deletedCategories = [3, 4, 5, 13];
134-
$categoryCollection = $this->categoryFactory->create()->getCollection()->toArray();
138+
$deletedCategories = ['3', '4', '5', '13'];
139+
$categoryCollectionIds = $this->categoryCollectionFactory->create()->getAllIds();
135140
$this->repo->deleteByIdentifier(3);
136-
$this->assertEmpty(
137-
$productCollection->addCategoriesFilter(['in' => $deletedCategories])->getItems(),
141+
$this->assertEquals(
142+
0,
143+
$productCollection->addCategoriesFilter(['in' => $deletedCategories])->getSize(),
138144
'The category-products relations was not deleted after category delete'
139145
);
140-
$newCategoryCollection = $this->categoryFactory->create()->getCollection()->toArray();
146+
$newCategoryCollectionIds = $this->categoryCollectionFactory->create()->getAllIds();
147+
$difference = array_diff($categoryCollectionIds, $newCategoryCollectionIds);
148+
sort($difference);
141149
$this->assertEquals(
142150
$deletedCategories,
143-
array_keys(array_diff_key($categoryCollection, $newCategoryCollection)),
151+
$difference,
144152
'Wrong categories was deleted'
145153
);
146154
}

0 commit comments

Comments
 (0)