Skip to content

Commit e436ae6

Browse files
MAGETWO-69825: [GITHUB #9891] Subcategory "liquid-hand-soap" is not opened in category "soap"
- Added integration test
1 parent 3074ff6 commit e436ae6

File tree

1 file changed

+53
-9
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml

1 file changed

+53
-9
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Controller\Adminhtml;
79

10+
use Magento\Backend\App\Area\FrontNameResolver;
11+
use Magento\Catalog\Model\ResourceModel\Product;
812
use Magento\Framework\App\Request\Http as HttpRequest;
9-
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\Framework\Message\MessageInterface;
1014
use Magento\Store\Model\Store;
11-
use Magento\Catalog\Model\ResourceModel\Product;
15+
use Magento\TestFramework\Helper\Bootstrap;
1216

1317
/**
18+
* Test class for \Magento\Catalog\Controller\Adminhtml\Category.
19+
*
1420
* @magentoAppArea adminhtml
1521
*/
1622
class CategoryTest extends \Magento\TestFramework\TestCase\AbstractBackendController
@@ -36,6 +42,8 @@ protected function setUp()
3642
}
3743

3844
/**
45+
* Test save action.
46+
*
3947
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
4048
* @magentoDbIsolation enabled
4149
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
@@ -48,7 +56,7 @@ protected function setUp()
4856
public function testSaveAction($inputData, $defaultAttributes, $attributesSaved = [], $isSuccess = true)
4957
{
5058
/** @var $store \Magento\Store\Model\Store */
51-
$store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class);
59+
$store = Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class);
5260
$store->load('fixturestore', 'code');
5361
$storeId = $store->getId();
5462

@@ -61,14 +69,12 @@ public function testSaveAction($inputData, $defaultAttributes, $attributesSaved
6169
if ($isSuccess) {
6270
$this->assertSessionMessages(
6371
$this->equalTo(['You saved the category.']),
64-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
72+
MessageInterface::TYPE_SUCCESS
6573
);
6674
}
6775

6876
/** @var $category \Magento\Catalog\Model\Category */
69-
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
70-
\Magento\Catalog\Model\Category::class
71-
);
77+
$category = Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
7278
$category->setStoreId($storeId);
7379
$category->load(2);
7480

@@ -95,6 +101,8 @@ public function testSaveAction($inputData, $defaultAttributes, $attributesSaved
95101
}
96102

97103
/**
104+
* Test save action from product creation page.
105+
*
98106
* @param array $postData
99107
* @dataProvider categoryCreatedFromProductCreationPageDataProvider
100108
* @magentoDbIsolation enabled
@@ -377,11 +385,13 @@ public function testSaveActionCategoryWithDangerRequest()
377385
$this->dispatch('backend/catalog/category/save');
378386
$this->assertSessionMessages(
379387
$this->equalTo(['The "Name" attribute value is empty. Set the attribute and try again.']),
380-
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
388+
MessageInterface::TYPE_ERROR
381389
);
382390
}
383391

384392
/**
393+
* Test move action.
394+
*
385395
* @magentoDataFixture Magento/Catalog/_files/category_tree.php
386396
* @dataProvider moveActionDataProvider
387397
*
@@ -433,6 +443,8 @@ public function moveActionDataProvider()
433443
}
434444

435445
/**
446+
* Test save category with product position.
447+
*
436448
* @magentoDataFixture Magento/Catalog/_files/products_in_different_stores.php
437449
* @magentoDbIsolation disabled
438450
* @dataProvider saveActionWithDifferentWebsitesDataProvider
@@ -541,7 +553,7 @@ public function saveActionWithDifferentWebsitesDataProvider()
541553
}
542554

543555
/**
544-
* Get items count from catalog_category_product
556+
* Get items count from catalog_category_product.
545557
*
546558
* @return int
547559
*/
@@ -555,4 +567,36 @@ private function getCategoryProductsCount(): int
555567
$this->productResource->getConnection()->fetchAll($oldCategoryProducts)
556568
);
557569
}
570+
571+
/**
572+
* Verify that the category cannot be saved if the category url matches the admin url.
573+
*
574+
* @magentoConfigFixture admin/url/use_custom_path 1
575+
* @magentoConfigFixture admin/url/custom_path backend
576+
*/
577+
public function testSaveWithCustomBackendNameAction()
578+
{
579+
$frontNameResolver = Bootstrap::getObjectManager()->create(FrontNameResolver::class);
580+
$urlKey = $frontNameResolver->getFrontName();
581+
$inputData = [
582+
'id' => '2',
583+
'url_key' => $urlKey,
584+
'use_config' => [
585+
'available_sort_by' => 1,
586+
'default_sort_by' => 1
587+
]
588+
];
589+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
590+
$this->getRequest()->setPostValue($inputData);
591+
$this->dispatch('backend/catalog/category/save');
592+
$this->assertSessionMessages(
593+
$this->equalTo(
594+
[
595+
'URL key "backend" conflicts with reserved endpoint names: '
596+
. 'admin, soap, rest, graphql, backend. Try another url key.'
597+
]
598+
),
599+
MessageInterface::TYPE_ERROR
600+
);
601+
}
558602
}

0 commit comments

Comments
 (0)