Skip to content

Commit 0ef20cf

Browse files
committed
MC-22031: Admin: Product URL Management
1 parent f0ed1c4 commit 0ef20cf

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Catalog\Api\CategoryRepositoryInterface;
1212
use Magento\Catalog\Api\Data\CategoryInterface;
1313
use Magento\Catalog\Model\CategoryFactory;
14-
use Magento\Catalog\Model\ResourceModel\CategoryFactory as CategoryResourceFactory;
14+
use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
1515
use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteDatabaseMap;
1616
use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
1717
use Magento\CatalogUrlRewrite\Model\ResourceModel\Category\Product;
@@ -32,8 +32,8 @@ class CategoryUrlRewriteTest extends AbstractUrlRewriteTest
3232
/** @var CategoryRepositoryInterface */
3333
private $categoryRepository;
3434

35-
/** @var CategoryResourceFactory */
36-
private $categoryResourceFactory;
35+
/** @var CategoryResource */
36+
private $categoryResource;
3737

3838
/** @var CategoryLinkManagementInterface */
3939
private $categoryLinkManagement;
@@ -52,7 +52,7 @@ protected function setUp()
5252
parent::setUp();
5353

5454
$this->categoryRepository = $this->objectManager->create(CategoryRepositoryInterface::class);
55-
$this->categoryResourceFactory = $this->objectManager->get(CategoryResourceFactory::class);
55+
$this->categoryResource = $this->objectManager->get(CategoryResource::class);
5656
$this->categoryLinkManagement = $this->objectManager->create(CategoryLinkManagementInterface::class);
5757
$this->categoryFactory = $this->objectManager->get(CategoryFactory::class);
5858
$this->suffix = $this->config->getValue(
@@ -69,7 +69,7 @@ protected function setUp()
6969
*/
7070
public function testUrlRewriteOnCategorySave(array $data): void
7171
{
72-
$categoryModel = $this->resourceSaveCategoryWithData($data['data']);
72+
$categoryModel = $this->saveCategory($data['data']);
7373
$this->assertNotNull($categoryModel->getId(), 'The category was not created');
7474
$urlRewriteCollection = $this->getEntityRewriteCollection($categoryModel->getId());
7575
$this->assertRewrites(
@@ -174,7 +174,7 @@ public function testUrlRewriteOnCategorySaveWithExistingUrlKey(array $data): voi
174174
{
175175
$this->expectException(UrlAlreadyExistsException::class);
176176
$this->expectExceptionMessage((string)__('URL key for specified store already exists.'));
177-
$this->resourceSaveCategoryWithData($data);
177+
$this->saveCategory($data);
178178
}
179179

180180
/**
@@ -339,7 +339,7 @@ public function testCategoryUrlRewritePerStoreViews(): void
339339
$categoryId = 333;
340340
$category = $this->categoryRepository->get($categoryId);
341341
$urlKeyFirstStore = $category->getUrlKey();
342-
$this->resourceSaveCategoryWithData(
342+
$this->saveCategory(
343343
['store_id' => $secondStoreId, 'url_key' => $urlKeySecondStore],
344344
$category
345345
);
@@ -383,12 +383,11 @@ protected function getEntityFactory()
383383
* @param CategoryInterface|null $category
384384
* @return CategoryInterface
385385
*/
386-
private function resourceSaveCategoryWithData(array $data, $category = null): CategoryInterface
386+
private function saveCategory(array $data, $category = null): CategoryInterface
387387
{
388388
$category = $category ?: $this->categoryFactory->create();
389389
$category->addData($data);
390-
$categoryResource = $this->categoryResourceFactory->create();
391-
$categoryResource->save($category);
390+
$this->categoryResource->save($category);
392391

393392
return $category;
394393
}
@@ -405,7 +404,7 @@ private function getCategoryProductRewriteCollection($categoryId): UrlRewriteCol
405404
$productRewriteCollection = $this->urlRewriteCollectionFactory->create();
406405
$productRewriteCollection
407406
->join(
408-
['p' => Product::TABLE_NAME],
407+
['p' => $this->categoryResource->getTable(Product::TABLE_NAME)],
409408
'main_table.url_rewrite_id = p.url_rewrite_id',
410409
'category_id'
411410
)

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Catalog\Model\Product\Type;
1313
use Magento\Catalog\Model\Product\Visibility;
1414
use Magento\Catalog\Model\ProductFactory;
15-
use Magento\Catalog\Model\ResourceModel\ProductFactory as ProductResourceFactory;
15+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1616
use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
1717
use Magento\Store\Model\ScopeInterface;
1818
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
@@ -32,8 +32,8 @@ class ProductUrlRewriteTest extends AbstractUrlRewriteTest
3232
/** @var string */
3333
private $suffix;
3434

35-
/** @var ProductResourceFactory */
36-
private $productResourceFactory;
35+
/** @var ProductResource */
36+
private $productResource;
3737

3838
/** @var ProductRepositoryInterface */
3939
private $productRepository;
@@ -45,7 +45,7 @@ protected function setUp()
4545
{
4646
parent::setUp();
4747

48-
$this->productResourceFactory = $this->objectManager->create(ProductResourceFactory::class);
48+
$this->productResource = $this->objectManager->create(ProductResource::class);
4949
$this->productFactory = $this->objectManager->get(ProductFactory::class);
5050
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
5151
$this->suffix = $this->config->getValue(
@@ -61,7 +61,7 @@ protected function setUp()
6161
*/
6262
public function testUrlRewriteOnProductSave(array $data): void
6363
{
64-
$product = $this->resourceSaveProductWithData($data['data']);
64+
$product = $this->saveProduct($data['data']);
6565
$this->assertNotNull($product->getId(), 'The product was not created');
6666
$productUrlRewriteCollection = $this->getEntityRewriteCollection($product->getId());
6767
$this->assertRewrites(
@@ -144,7 +144,7 @@ public function testUrlRewriteOnProductEdit(array $expectedData): void
144144
'url_key_create_redirect' => $product->getUrlKey(),
145145
'save_rewrites_history' => true,
146146
];
147-
$product = $this->resourceSaveProductWithData($data, $product);
147+
$product = $this->saveProduct($data, $product);
148148
$productRewriteCollection = $this->getEntityRewriteCollection($product->getId());
149149
$this->assertRewrites(
150150
$productRewriteCollection,
@@ -184,7 +184,7 @@ public function testUrlRewriteOnProductSaveWithExistingUrlKey(array $data): void
184184
{
185185
$this->expectException(UrlAlreadyExistsException::class);
186186
$this->expectExceptionMessage((string)__('URL key for specified store already exists.'));
187-
$this->resourceSaveProductWithData($data);
187+
$this->saveProduct($data);
188188
}
189189

190190
/**
@@ -255,7 +255,7 @@ public function testProductUrlRewritePerStoreViews(): void
255255
$secondStoreId = $this->storeRepository->get('fixture_second_store')->getId();
256256
$product = $this->productRepository->get('simple2');
257257
$urlKeyFirstStore = $product->getUrlKey();
258-
$product = $this->resourceSaveProductWithData(
258+
$product = $this->saveProduct(
259259
['store_id' => $secondStoreId, 'url_key' => $urlKeySecondStore],
260260
$product
261261
);
@@ -275,12 +275,11 @@ public function testProductUrlRewritePerStoreViews(): void
275275
* @param ProductInterface|null $product
276276
* @return ProductInterface
277277
*/
278-
protected function resourceSaveProductWithData(array $data, $product = null): ProductInterface
278+
protected function saveProduct(array $data, $product = null): ProductInterface
279279
{
280280
$product = $product ?: $this->productFactory->create();
281281
$product->addData($data);
282-
$productResource = $this->productResourceFactory->create();
283-
$productResource->save($product);
282+
$this->productResource->save($product);
284283

285284
return $product;
286285
}

0 commit comments

Comments
 (0)