Skip to content

Commit f6d2af3

Browse files
committed
MC-22985: Fix integration test \Magento\UrlRewrite\Controller\UrlRewriteTest::testCategoryUrlRewrite
1 parent 3efbe15 commit f6d2af3

File tree

2 files changed

+90
-33
lines changed

2 files changed

+90
-33
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
namespace Magento\Catalog\Controller\Category;
9+
10+
use Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\Registry;
13+
use Magento\Store\Model\ScopeInterface;
14+
use Magento\TestFramework\TestCase\AbstractController;
15+
use Zend\Http\Response;
16+
17+
/**
18+
* Checks category availability on storefront by url rewrite
19+
*
20+
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
21+
* @magentoDbIsolation enabled
22+
*/
23+
class CategoryUrlRewriteTest extends AbstractController
24+
{
25+
/** @var Registry */
26+
private $registry;
27+
28+
/** @var ScopeConfigInterface */
29+
private $config;
30+
31+
/** @var string */
32+
private $categoryUrlSuffix;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp()
38+
{
39+
parent::setUp();
40+
41+
$this->config = $this->_objectManager->get(ScopeConfigInterface::class);
42+
$this->registry = $this->_objectManager->get(Registry::class);
43+
$this->categoryUrlSuffix = $this->config->getValue(
44+
CategoryUrlPathGenerator::XML_PATH_CATEGORY_URL_SUFFIX,
45+
ScopeInterface::SCOPE_STORE
46+
);
47+
}
48+
49+
/**
50+
* @magentoDataFixture Magento/Catalog/_files/category_tree.php
51+
* @dataProvider categoryRewriteProvider
52+
* @param int $categoryId
53+
* @param string $urlPath
54+
* @return void
55+
*/
56+
public function testCategoryUrlRewrite(int $categoryId, string $urlPath): void
57+
{
58+
$this->dispatch(sprintf($urlPath, $this->categoryUrlSuffix));
59+
$currentCategory = $this->registry->registry('current_category');
60+
$response = $this->getResponse();
61+
$this->assertEquals(
62+
Response::STATUS_CODE_200,
63+
$response->getHttpResponseCode(),
64+
'Response code does not match expected value'
65+
);
66+
$this->assertNotNull($currentCategory);
67+
$this->assertEquals($categoryId, $currentCategory->getId());
68+
}
69+
70+
/**
71+
* @return array
72+
*/
73+
public function categoryRewriteProvider(): array
74+
{
75+
return [
76+
[
77+
'category_id' => 400,
78+
'url_path' => '/category-1%s',
79+
],
80+
[
81+
'category_id' => 401,
82+
'url_path' => '/category-1/category-1-1%s',
83+
],
84+
[
85+
'category_id' => 402,
86+
'url_path' => '/category-1/category-1-1/category-1-1-1%s',
87+
],
88+
];
89+
}
90+
}

dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/UrlRewriteTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,37 +82,4 @@ public function requestDataProvider(): array
8282
],
8383
];
8484
}
85-
86-
/**
87-
* @magentoDbIsolation enabled
88-
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
89-
* @magentoDataFixture Magento/Catalog/_files/category_tree.php
90-
* @dataProvider categoryRewriteProvider
91-
* @param string $request
92-
* @return void
93-
*/
94-
public function testCategoryUrlRewrite(string $request): void
95-
{
96-
$this->dispatch($request);
97-
$response = $this->getResponse();
98-
$this->assertEquals(
99-
HttpResponse::STATUS_CODE_200,
100-
$response->getHttpResponseCode(),
101-
'Response code does not match expected value'
102-
);
103-
}
104-
105-
/**
106-
* @return array
107-
*/
108-
public function categoryRewriteProvider(): array
109-
{
110-
return [
111-
[
112-
'category-1.html',
113-
'category-1/category-1-1.html',
114-
'category-1/category-1-1/category-1-1-1.html',
115-
],
116-
];
117-
}
11885
}

0 commit comments

Comments
 (0)