-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes are covered by the integration test
- Loading branch information
1 parent
acb8642
commit 97258e1
Showing
3 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...ation/testsuite/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGeneratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogUrlRewrite\Model\Product; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Category; | ||
use Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Store\Model\Store; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/**3 | ||
* Verify generate url rewrites for anchor categories. | ||
*/ | ||
class AnchorUrlRewriteGeneratorTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var ProductRepositoryInterface | ||
*/ | ||
private $productRepository; | ||
|
||
/** | ||
* @var Category | ||
*/ | ||
private $collectionCategory; | ||
|
||
/** | ||
* @var ObjectRegistryFactory | ||
*/ | ||
private $objectRegistryFactory; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); // TODO: Change the autogenerated stub | ||
|
||
$this->objectManager = Bootstrap::getObjectManager(); | ||
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class); | ||
$this->collectionCategory = $this->objectManager->create(Category::class); | ||
$this->objectRegistryFactory = $this->objectManager->create(ObjectRegistryFactory::class); | ||
} | ||
|
||
/** | ||
* Verify correct generate of the relative "StoreId" | ||
* | ||
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_with_stores.php | ||
* @magentoDbIsolation disabled | ||
* | ||
* @return void | ||
*/ | ||
public function testGenerate(): void | ||
{ | ||
$product = $this->productRepository->get('simple'); | ||
$categories = $product->getCategoryCollection(); | ||
$productCategories = $this->objectRegistryFactory->create(['entities' => $categories]); | ||
|
||
/** @var Store $store */ | ||
$store = Bootstrap::getObjectManager()->get(Store::class); | ||
$store->load('fixture_second_store', 'code'); | ||
|
||
/** @var AnchorUrlRewriteGenerator $generator */ | ||
$generator = $this->objectManager->get(AnchorUrlRewriteGenerator::class); | ||
|
||
$this->assertEquals([], $generator->generate(1, $product, $productCategories)); | ||
$this->assertNotEquals([], $generator->generate($store->getId(), $product, $productCategories)); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/categories_with_stores.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Backend\App\Area\FrontNameResolver; | ||
use Magento\Catalog\Model\Category; | ||
use Magento\Store\Model\Store; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
require __DIR__ . '/../../../Magento/Store/_files/second_store.php'; | ||
Bootstrap::getInstance() | ||
->loadArea(FrontNameResolver::AREA_CODE); | ||
|
||
/** | ||
* After installation system has categories: | ||
* | ||
* root one with ID:1 and Default category with ID:3 both with StoreId:1, | ||
* | ||
* root one with ID:1 and Default category with ID:2 both with StoreId:2 | ||
*/ | ||
|
||
$store = Bootstrap::getObjectManager()->get(Store::class); | ||
$store->load('fixture_second_store', 'code'); | ||
|
||
/** @var $category Category */ | ||
$category = Bootstrap::getObjectManager()->create(Category::class); | ||
$category->isObjectNew(true); | ||
$category->setId(3) | ||
->setName('Category 1') | ||
->setParentId(1) | ||
->setPath('1/2') | ||
->setLevel(1) | ||
->setAvailableSortBy('name') | ||
->setDefaultSortBy('name') | ||
->setIsActive(true) | ||
->setPosition(1) | ||
->save(); | ||
|
||
$category = Bootstrap::getObjectManager()->create(Category::class); | ||
$category->isObjectNew(true); | ||
$category->setId(4) | ||
->setName('Category 1.1') | ||
->setParentId(3) | ||
->setPath('1/2/3') | ||
->setLevel(2) | ||
->setAvailableSortBy('name') | ||
->setDefaultSortBy('name') | ||
->setIsActive(true) | ||
->setPosition(1) | ||
->save(); | ||
|
||
$category = Bootstrap::getObjectManager()->create(Category::class); | ||
$category->isObjectNew(true); | ||
$category->setId(3) | ||
->setName('Category 1') | ||
->setParentId(2) | ||
->setPath('1/2/3') | ||
->setLevel(2) | ||
->setAvailableSortBy('name') | ||
->setDefaultSortBy('name') | ||
->setStoreId($store->getId()) | ||
->setIsActive(true) | ||
->setPosition(1) | ||
->save(); | ||
|
||
$category = Bootstrap::getObjectManager()->create(Category::class); | ||
$category->isObjectNew(true); | ||
$category->setId(4) | ||
->setName('Category 1.1') | ||
->setParentId(3) | ||
->setPath('1/2/3/4') | ||
->setLevel(3) | ||
->setAvailableSortBy('name') | ||
->setDefaultSortBy('name') | ||
->setStoreId($store->getId()) | ||
->setIsActive(true) | ||
->setPosition(1) | ||
->save(); |
46 changes: 46 additions & 0 deletions
46
dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/_files/product_with_stores.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
/** @var \Magento\Catalog\Setup\CategorySetup $installer */ | ||
$installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( | ||
\Magento\Catalog\Setup\CategorySetup::class | ||
); | ||
require __DIR__ . '/categories_with_stores.php'; | ||
|
||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); | ||
$categoryLinkRepository = $objectManager->create( | ||
\Magento\Catalog\Api\CategoryLinkRepositoryInterface::class, | ||
[ | ||
'productRepository' => $productRepository | ||
] | ||
); | ||
|
||
/** @var Magento\Catalog\Api\CategoryLinkManagementInterface $linkManagement */ | ||
$categoryLinkManagement = $objectManager->create( | ||
\Magento\Catalog\Api\CategoryLinkManagementInterface::class, | ||
[ | ||
'productRepository' => $productRepository, | ||
'categoryLinkRepository' => $categoryLinkRepository | ||
] | ||
); | ||
|
||
/** @var $product \Magento\Catalog\Model\Product */ | ||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class); | ||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) | ||
->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default')) | ||
->setStoreId(1) | ||
->setWebsiteIds([1]) | ||
->setName('Simple Product') | ||
->setSku('simple') | ||
->setPrice(10) | ||
->setWeight(18) | ||
->setStockData(['use_config_manage_stock' => 0]) | ||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) | ||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) | ||
->save(); | ||
$categoryLinkManagement->assignProductToCategories($product->getSku(), [4]); |