Skip to content

Commit 62411cf

Browse files
author
Ihor Kh
committed
#35371: Product page gives error because of url rewrites
- added test data for fix
1 parent 260e872 commit 62411cf

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Storage/DynamicStorageTest.php

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
3+
* Copyright 2021 Adobe. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
@@ -80,6 +80,11 @@ class DynamicStorageTest extends TestCase
8080
*/
8181
private $logger;
8282

83+
/**
84+
* @var string
85+
*/
86+
private $requestPath;
87+
8388
/**
8489
* @inheritdoc
8590
*/
@@ -169,9 +174,7 @@ public function testFindProductRewriteByRequestPath(
169174
bool $canBeShownInCategory,
170175
?array $expectedProductRewrite
171176
): void {
172-
$this->connectionMock->expects($this->any())
173-
->method('fetchRow')
174-
->will($this->onConsecutiveCalls($productFromDb, $categoryFromDb));
177+
$this->fetchDataMock($productFromDb, $categoryFromDb);
175178

176179
$scopeConfigMap = [
177180
[
@@ -347,6 +350,67 @@ public static function findProductRewriteByRequestPathDataProvider(): array
347350
'redirect_type' => OptionProvider::PERMANENT,
348351
]
349352
],
353+
[
354+
// Category has product url key at the beginning of its url key
355+
[
356+
'request_path' => 'test-category/test-sub-category/test',
357+
'store_id' => 1
358+
],
359+
[
360+
'entity_type' => 'product',
361+
'entity_id' => '1',
362+
'request_path' => 'test',
363+
'target_path' => 'catalog/product/view/id/1',
364+
'redirect_type' => '0',
365+
],
366+
'',
367+
[
368+
'entity_type' => 'category',
369+
'entity_id' => '38',
370+
'request_path' => 'test-category/test-sub-category',
371+
'target_path' => 'catalog/category/view/id/38',
372+
'redirect_type' => '0',
373+
],
374+
true,
375+
[
376+
'entity_type' => 'product',
377+
'entity_id' => '1',
378+
'request_path' => 'test-category/test-sub-category/test',
379+
'target_path' => 'catalog/product/view/id/1/category/38',
380+
'redirect_type' => '0',
381+
]
382+
],
350383
];
351384
}
385+
386+
/**
387+
* @param array|false $productFromDb
388+
* @param array|false $categoryFromDb
389+
*
390+
* @return void
391+
*/
392+
private function fetchDataMock($productFromDb, $categoryFromDb): void
393+
{
394+
$selectMock = $this->selectMock;
395+
$this->selectMock->expects($this->any())->method('where')
396+
->willReturnCallback(function ($string, $value) use ($selectMock) {
397+
if($string == 'url_rewrite.request_path IN (?)')
398+
$this->requestPath = array_shift($value);
399+
400+
return $selectMock;
401+
});
402+
$this->connectionMock->expects($this->any())
403+
->method('fetchRow')
404+
->willReturnCallback(function ($select) use ($productFromDb, $categoryFromDb) {
405+
switch (true){
406+
case $productFromDb && $productFromDb['request_path'] == $this->requestPath:
407+
return $productFromDb;
408+
case $categoryFromDb && $categoryFromDb['request_path'] == $this->requestPath:
409+
return $categoryFromDb;
410+
default:
411+
return false;
412+
}
413+
})
414+
;
415+
}
352416
}

0 commit comments

Comments
 (0)