|
11 | 11 | use Magento\Catalog\Model\ResourceModel\Product;
|
12 | 12 | use Magento\Framework\App\Request\Http as HttpRequest;
|
13 | 13 | use Magento\Framework\Message\MessageInterface;
|
14 |
| -use Magento\Store\Model\Store; |
| 14 | +use Magento\Catalog\Api\CategoryRepositoryInterface; |
| 15 | +use Magento\Framework\Exception\NoSuchEntityException; |
15 | 16 | use Magento\TestFramework\Helper\Bootstrap;
|
| 17 | +use Magento\Store\Model\Store; |
16 | 18 |
|
17 | 19 | /**
|
18 |
| - * Test class for \Magento\Catalog\Controller\Adminhtml\Category. |
| 20 | + * Test for category backend actions |
19 | 21 | *
|
20 | 22 | * @magentoAppArea adminhtml
|
21 | 23 | */
|
@@ -101,7 +103,43 @@ public function testSaveAction($inputData, $defaultAttributes, $attributesSaved
|
101 | 103 | }
|
102 | 104 |
|
103 | 105 | /**
|
104 |
| - * Test save action from product creation page. |
| 106 | + * Check default value for category url path |
| 107 | + * |
| 108 | + * @magentoDbIsolation enabled |
| 109 | + * @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories.php |
| 110 | + * @throws NoSuchEntityException |
| 111 | + */ |
| 112 | + public function testDefaultValueForCategoryUrlPath() |
| 113 | + { |
| 114 | + $repository = $this->_objectManager->get(CategoryRepositoryInterface::class); |
| 115 | + $categoryId = 3; |
| 116 | + $category = $repository->get($categoryId); |
| 117 | + $newUrlPath = 'test_url_path'; |
| 118 | + $defaultUrlPath = $category->getData('url_path'); |
| 119 | + |
| 120 | + // update url_path and check it |
| 121 | + $category->setStoreId(1); |
| 122 | + $category->setUrlKey($newUrlPath); |
| 123 | + $category->setUrlPath($newUrlPath); |
| 124 | + $repository->save($category); |
| 125 | + $this->assertEquals($newUrlPath, $category->getUrlPath()); |
| 126 | + |
| 127 | + // set default url_path and check it |
| 128 | + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); |
| 129 | + $postData = $category->getData(); |
| 130 | + $postData['use_default'] = [ |
| 131 | + 'available_sort_by' => 1, |
| 132 | + 'default_sort_by' => 1, |
| 133 | + 'url_key' => 1, |
| 134 | + ]; |
| 135 | + $this->getRequest()->setPostValue($postData); |
| 136 | + $this->dispatch('backend/catalog/category/save'); |
| 137 | + $category = $repository->get($categoryId); |
| 138 | + $this->assertEquals($defaultUrlPath, $category->getData('url_path')); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Test save action from product form page |
105 | 143 | *
|
106 | 144 | * @param array $postData
|
107 | 145 | * @dataProvider categoryCreatedFromProductCreationPageDataProvider
|
@@ -138,6 +176,8 @@ public function testSaveActionFromProductCreationPage($postData)
|
138 | 176 | }
|
139 | 177 |
|
140 | 178 | /**
|
| 179 | + * Get category post data |
| 180 | + * |
141 | 181 | * @static
|
142 | 182 | * @return array
|
143 | 183 | */
|
@@ -182,6 +222,8 @@ public function testSuggestCategoriesActionNoSuggestions()
|
182 | 222 | }
|
183 | 223 |
|
184 | 224 | /**
|
| 225 | + * Save action data provider |
| 226 | + * |
185 | 227 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
186 | 228 | * @return array
|
187 | 229 | */
|
@@ -430,6 +472,8 @@ public function testMoveAction($parentId, $childId, $childUrlKey, $grandChildId,
|
430 | 472 | }
|
431 | 473 |
|
432 | 474 | /**
|
| 475 | + * Move action data provider |
| 476 | + * |
433 | 477 | * @return array
|
434 | 478 | */
|
435 | 479 | public function moveActionDataProvider()
|
@@ -472,6 +516,8 @@ public function testSaveCategoryWithProductPosition(array $postData)
|
472 | 516 | }
|
473 | 517 |
|
474 | 518 | /**
|
| 519 | + * Save action data provider |
| 520 | + * |
475 | 521 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
476 | 522 | * @return array
|
477 | 523 | */
|
|
0 commit comments