Skip to content

Commit bf514b0

Browse files
committed
Refactoring test and add rollback for fixture
1 parent 28fa345 commit bf514b0

File tree

8 files changed

+101
-40
lines changed

8 files changed

+101
-40
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11-
<actionGroup name="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" extends="ChangeSeoUrlKeyForSubCategoryActionGroup">
11+
<actionGroup name="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" extends="ChangeSeoUrlKeyForSubCategoryActionGroup">
1212
<annotations>
1313
<description>Requires navigation to subcategory creation/edit. Updates the Search Engine Optimization with uncheck Redirect Checkbox .</description>
1414
</annotations>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
9-
<actionGroup name="StorefrontAssertProductRewriteUrlSubCategoryActionGroup">
9+
<actionGroup name="AssertStorefrontProductRewriteUrlSubCategoryActionGroup">
1010
<annotations>
1111
<description>Validates that the provided Product Title is present on the Rewrite URL with a subcategory page.</description>
1212
</annotations>

app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminRewriteProductWithTwoStoreTest.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
<actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchDefaultStoreViewForDefaultCategory">
4444
<argument name="storeView" value="_defaultStore.name"/>
4545
</actionGroup>
46-
<actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryDefaultStore">
46+
<actionGroup ref="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryDefaultStore">
4747
<argument name="value" value="{{_defaultCategoryDifferentUrlStore.url_key_default_store}}"/>
4848
</actionGroup>
4949
<actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchCustomStoreViewForDefaultCategory">
5050
<argument name="storeView" value="customStore.name"/>
5151
</actionGroup>
52-
<actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryCustomStore">
52+
<actionGroup ref="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForDefaultCategoryCustomStore">
5353
<argument name="value" value="{{_defaultCategoryDifferentUrlStore.url_key_custom_store}}"/>
5454
</actionGroup>
5555

@@ -59,26 +59,25 @@
5959
<actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchDefaultStoreViewForSubCategory">
6060
<argument name="storeView" value="_defaultStore.name"/>
6161
</actionGroup>
62-
<actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryDefaultStore">
62+
<actionGroup ref="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryDefaultStore">
6363
<argument name="value" value="{{SimpleSubCategoryDifferentUrlStore.url_key_default_store}}"/>
6464
</actionGroup>
6565
<actionGroup ref="AdminSwitchStoreViewActionGroup" stepKey="AdminSwitchCustomStoreViewForSubCategory">
6666
<argument name="storeView" value="customStore.name"/>
6767
</actionGroup>
68-
<actionGroup ref="ChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryCustomStore">
68+
69+
<actionGroup ref="AdminChangeSeoUrlKeyForSubCategoryWithoutRedirectActionGroup" stepKey="changeSeoUrlKeyForSubCategoryCustomStore">
6970
<argument name="value" value="{{SimpleSubCategoryDifferentUrlStore.url_key_custom_store}}"/>
7071
</actionGroup>
71-
72-
<actionGroup ref="StorefrontAssertProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlDefaultStore">
72+
<actionGroup ref="AssertStorefrontProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlDefaultStore">
7373
<argument name="category" value="{{_defaultCategoryDifferentUrlStore.url_key_default_store}}"/>
7474
<argument name="product" value="SimpleProduct" />
7575
</actionGroup>
7676

7777
<actionGroup ref="StorefrontSwitchStoreViewActionGroup" stepKey="switchStore">
7878
<argument name="storeView" value="customStore" />
7979
</actionGroup>
80-
81-
<actionGroup ref="StorefrontAssertProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlCustomStore">
80+
<actionGroup ref="AssertStorefrontProductRewriteUrlSubCategoryActionGroup" stepKey="validatesRewriteUrlCustomStore">
8281
<argument name="category" value="{{_defaultCategoryDifferentUrlStore.url_key_custom_store}}"/>
8382
<argument name="product" value="SimpleProduct" />
8483
</actionGroup>

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\CatalogUrlRewrite\Model\Product;
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
11-
use Magento\Catalog\Model\Category;
1211
use Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory;
1312
use Magento\Framework\ObjectManagerInterface;
1413
use Magento\Store\Model\Store;
@@ -31,11 +30,6 @@ class AnchorUrlRewriteGeneratorTest extends TestCase
3130
*/
3231
private $productRepository;
3332

34-
/**
35-
* @var Category
36-
*/
37-
private $collectionCategory;
38-
3933
/**
4034
* @var ObjectRegistryFactory
4135
*/
@@ -50,32 +44,49 @@ public function setUp()
5044

5145
$this->objectManager = Bootstrap::getObjectManager();
5246
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
53-
$this->collectionCategory = $this->objectManager->create(Category::class);
5447
$this->objectRegistryFactory = $this->objectManager->create(ObjectRegistryFactory::class);
5548
}
5649

5750
/**
5851
* Verify correct generate of the relative "StoreId"
5952
*
53+
* @param string $expect
54+
* @return void
55+
* @throws \Magento\Framework\Exception\LocalizedException
56+
* @throws \Magento\Framework\Exception\NoSuchEntityException
6057
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_with_stores.php
6158
* @magentoDbIsolation disabled
62-
*
63-
* @return void
59+
* @dataProvider getConfigGenerate
6460
*/
65-
public function testGenerate(): void
61+
public function testGenerate(string $expect): void
6662
{
6763
$product = $this->productRepository->get('simple');
6864
$categories = $product->getCategoryCollection();
6965
$productCategories = $this->objectRegistryFactory->create(['entities' => $categories]);
7066

71-
/** @var Store $store */
67+
/** @var AnchorUrlRewriteGenerator $generator */
68+
$generator = $this->objectManager->get(AnchorUrlRewriteGenerator::class);
69+
70+
/** @var $store Store */
7271
$store = Bootstrap::getObjectManager()->get(Store::class);
7372
$store->load('fixture_second_store', 'code');
7473

75-
/** @var AnchorUrlRewriteGenerator $generator */
76-
$generator = $this->objectManager->get(AnchorUrlRewriteGenerator::class);
74+
$urls = $generator->generate($store->getId(), $product, $productCategories);
75+
76+
$this->assertEquals($expect, $urls[0]->getRequestPath());
77+
}
7778

78-
$this->assertEquals([], $generator->generate(1, $product, $productCategories));
79-
$this->assertNotEquals([], $generator->generate($store->getId(), $product, $productCategories));
79+
/**
80+
* Data provider for testGenerate
81+
*
82+
* @return array
83+
*/
84+
public function getConfigGenerate(): array
85+
{
86+
return [
87+
[
88+
'expect' => 'category-1-custom/simple-product.html'
89+
]
90+
];
8091
}
8192
}

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
require __DIR__ . '/../../../Magento/Store/_files/second_store.php';
1414
Bootstrap::getInstance()->loadArea(FrontNameResolver::AREA_CODE);
1515

16-
/**
17-
* After installation system has categories:
18-
*
19-
* root one with ID:1 and Default category with ID:3 both with StoreId:1,
20-
*
21-
* root one with ID:1 and Default category with ID:2 both with StoreId:2
22-
*/
23-
2416
$store = Bootstrap::getObjectManager()->get(Store::class);
2517
$store->load('fixture_second_store', 'code');
2618

@@ -29,11 +21,13 @@
2921
$category->isObjectNew(true);
3022
$category->setId(3)
3123
->setName('Category 1')
32-
->setParentId(1)
33-
->setPath('1/2')
34-
->setLevel(1)
24+
->setParentId(2)
25+
->setPath('1/2/3')
26+
->setLevel(2)
3527
->setAvailableSortBy('name')
3628
->setDefaultSortBy('name')
29+
->setUrlPath('category-1-default')
30+
->setUrlKey('category-1-default')
3731
->setIsActive(true)
3832
->setPosition(1)
3933
->save();
@@ -43,10 +37,12 @@
4337
$category->setId(4)
4438
->setName('Category 1.1')
4539
->setParentId(3)
46-
->setPath('1/2/3')
47-
->setLevel(2)
40+
->setPath('1/2/3/4')
41+
->setLevel(3)
4842
->setAvailableSortBy('name')
4943
->setDefaultSortBy('name')
44+
->setUrlPath('category-1-1-default')
45+
->setUrlKey('category-1-1-default')
5046
->setIsActive(true)
5147
->setPosition(1)
5248
->save();
@@ -61,6 +57,8 @@
6157
->setAvailableSortBy('name')
6258
->setDefaultSortBy('name')
6359
->setStoreId($store->getId())
60+
->setUrlPath('category-1-custom')
61+
->setUrlKey('category-1-custom')
6462
->setIsActive(true)
6563
->setPosition(1)
6664
->save();
@@ -75,6 +73,8 @@
7573
->setAvailableSortBy('name')
7674
->setDefaultSortBy('name')
7775
->setStoreId($store->getId())
76+
->setUrlPath('category-1-1-custom')
77+
->setUrlKey('category-1-1-custom')
7878
->setIsActive(true)
7979
->setPosition(1)
8080
->save();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
/** @var \Magento\Framework\Registry $registry */
9+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
10+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
11+
12+
$registry->unregister('isSecureArea');
13+
$registry->register('isSecureArea', true);
14+
15+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
16+
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Category\Collection::class);
17+
$collection
18+
->addAttributeToFilter('level', 2)
19+
->load()
20+
->delete();
21+
22+
$registry->unregister('isSecureArea');
23+
$registry->register('isSecureArea', false);

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
$installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
1010
\Magento\Catalog\Setup\CategorySetup::class
1111
);
12+
1213
require __DIR__ . '/categories_with_stores.php';
1314

1415
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -33,8 +34,6 @@
3334
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
3435
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
3536
->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))
36-
->setStoreId(1)
37-
->setWebsiteIds([1])
3837
->setName('Simple Product')
3938
->setSku('simple')
4039
->setPrice(10)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Framework\Exception\NoSuchEntityException;
9+
10+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize();
11+
12+
/** @var \Magento\Framework\Registry $registry */
13+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
14+
15+
$registry->unregister('isSecureArea');
16+
$registry->register('isSecureArea', true);
17+
18+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
19+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
20+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
21+
try {
22+
$product = $productRepository->get('simple', true);
23+
if ($product->getId()) {
24+
$productRepository->delete($product);
25+
}
26+
} catch (NoSuchEntityException $e) {
27+
}
28+
$registry->unregister('isSecureArea');
29+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)