|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2021 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 | declare(strict_types=1);
|
7 | 7 |
|
@@ -80,6 +80,11 @@ class DynamicStorageTest extends TestCase
|
80 | 80 | */
|
81 | 81 | private $logger;
|
82 | 82 |
|
| 83 | + /** |
| 84 | + * @var string |
| 85 | + */ |
| 86 | + private $requestPath; |
| 87 | + |
83 | 88 | /**
|
84 | 89 | * @inheritdoc
|
85 | 90 | */
|
@@ -169,9 +174,7 @@ public function testFindProductRewriteByRequestPath(
|
169 | 174 | bool $canBeShownInCategory,
|
170 | 175 | ?array $expectedProductRewrite
|
171 | 176 | ): void {
|
172 |
| - $this->connectionMock->expects($this->any()) |
173 |
| - ->method('fetchRow') |
174 |
| - ->will($this->onConsecutiveCalls($productFromDb, $categoryFromDb)); |
| 177 | + $this->fetchDataMock($productFromDb, $categoryFromDb); |
175 | 178 |
|
176 | 179 | $scopeConfigMap = [
|
177 | 180 | [
|
@@ -347,6 +350,68 @@ public static function findProductRewriteByRequestPathDataProvider(): array
|
347 | 350 | 'redirect_type' => OptionProvider::PERMANENT,
|
348 | 351 | ]
|
349 | 352 | ],
|
| 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 | + ], |
350 | 383 | ];
|
351 | 384 | }
|
| 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()) |
| 396 | + ->method('where') |
| 397 | + ->willReturnCallback(function ($string, $value) use ($selectMock) { |
| 398 | + if ($string == 'url_rewrite.request_path IN (?)') { |
| 399 | + $this->requestPath = array_shift($value); |
| 400 | + } |
| 401 | + return $selectMock; |
| 402 | + }); |
| 403 | + $this->connectionMock->expects($this->any()) |
| 404 | + ->method('fetchRow') |
| 405 | + ->willReturnCallback(function () use ($productFromDb, $categoryFromDb) { |
| 406 | + switch (true) { |
| 407 | + case $productFromDb && $productFromDb['request_path'] == $this->requestPath: |
| 408 | + return $productFromDb; |
| 409 | + case $categoryFromDb && $categoryFromDb['request_path'] == $this->requestPath: |
| 410 | + return $categoryFromDb; |
| 411 | + default: |
| 412 | + return false; |
| 413 | + } |
| 414 | + }) |
| 415 | + ; |
| 416 | + } |
352 | 417 | }
|
0 commit comments