3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Catalog \Controller \Adminhtml ;
7
9
10
+ use Magento \Backend \App \Area \FrontNameResolver ;
11
+ use Magento \Catalog \Model \ResourceModel \Product ;
8
12
use Magento \Framework \App \Request \Http as HttpRequest ;
9
- use Magento \TestFramework \ Helper \ Bootstrap ;
13
+ use Magento \Framework \ Message \ MessageInterface ;
10
14
use Magento \Store \Model \Store ;
11
- use Magento \Catalog \ Model \ ResourceModel \ Product ;
15
+ use Magento \TestFramework \ Helper \ Bootstrap ;
12
16
13
17
/**
18
+ * Test class for \Magento\Catalog\Controller\Adminhtml\Category.
19
+ *
14
20
* @magentoAppArea adminhtml
15
21
*/
16
22
class CategoryTest extends \Magento \TestFramework \TestCase \AbstractBackendController
@@ -36,6 +42,8 @@ protected function setUp()
36
42
}
37
43
38
44
/**
45
+ * Test save action.
46
+ *
39
47
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
40
48
* @magentoDbIsolation enabled
41
49
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
@@ -48,7 +56,7 @@ protected function setUp()
48
56
public function testSaveAction ($ inputData , $ defaultAttributes , $ attributesSaved = [], $ isSuccess = true )
49
57
{
50
58
/** @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);
52
60
$ store ->load ('fixturestore ' , 'code ' );
53
61
$ storeId = $ store ->getId ();
54
62
@@ -61,14 +69,12 @@ public function testSaveAction($inputData, $defaultAttributes, $attributesSaved
61
69
if ($ isSuccess ) {
62
70
$ this ->assertSessionMessages (
63
71
$ this ->equalTo (['You saved the category. ' ]),
64
- \ Magento \ Framework \ Message \ MessageInterface::TYPE_SUCCESS
72
+ MessageInterface::TYPE_SUCCESS
65
73
);
66
74
}
67
75
68
76
/** @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);
72
78
$ category ->setStoreId ($ storeId );
73
79
$ category ->load (2 );
74
80
@@ -95,6 +101,8 @@ public function testSaveAction($inputData, $defaultAttributes, $attributesSaved
95
101
}
96
102
97
103
/**
104
+ * Test save action from product creation page.
105
+ *
98
106
* @param array $postData
99
107
* @dataProvider categoryCreatedFromProductCreationPageDataProvider
100
108
* @magentoDbIsolation enabled
@@ -377,11 +385,13 @@ public function testSaveActionCategoryWithDangerRequest()
377
385
$ this ->dispatch ('backend/catalog/category/save ' );
378
386
$ this ->assertSessionMessages (
379
387
$ 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
381
389
);
382
390
}
383
391
384
392
/**
393
+ * Test move action.
394
+ *
385
395
* @magentoDataFixture Magento/Catalog/_files/category_tree.php
386
396
* @dataProvider moveActionDataProvider
387
397
*
@@ -433,6 +443,8 @@ public function moveActionDataProvider()
433
443
}
434
444
435
445
/**
446
+ * Test save category with product position.
447
+ *
436
448
* @magentoDataFixture Magento/Catalog/_files/products_in_different_stores.php
437
449
* @magentoDbIsolation disabled
438
450
* @dataProvider saveActionWithDifferentWebsitesDataProvider
@@ -541,7 +553,7 @@ public function saveActionWithDifferentWebsitesDataProvider()
541
553
}
542
554
543
555
/**
544
- * Get items count from catalog_category_product
556
+ * Get items count from catalog_category_product.
545
557
*
546
558
* @return int
547
559
*/
@@ -555,4 +567,36 @@ private function getCategoryProductsCount(): int
555
567
$ this ->productResource ->getConnection ()->fetchAll ($ oldCategoryProducts )
556
568
);
557
569
}
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
+ }
558
602
}
0 commit comments