Separator URL miedzy parami attr-val zmieniony z "/" na "_" w generatorze feedu (ProductRepository::appendCombinationToXml). Wzorzec routingu pp_routes rozszerzony do [0-9_-]+ w Helpers::htacces (oba warianty: seo_link i fallback p-id-name). LayoutEngine konwertuje "_" -> "|" przed wywolaniem ProductRepository::findCached — format DB pozostaje "|". Partial product-attribute.php preselectuje wartosc z permutation_hash URL (forced_value_id), co poprawia UX wejscia z linka feedu. Suita: 834 -> 841 testow (+7), 2330 assertions. Wymagane akcje na produkcji po deployu: regeneracja pp_routes (Helpers::htacces), wyczyszczenie klucza pp_routes:all w Redis, regeneracja google-feed.xml, resubmit feedu w GMC. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
84 lines
2.8 KiB
PHP
84 lines
2.8 KiB
PHP
<?php
|
|
namespace Tests\Unit\Shared\Helpers;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Phase 18 — testy regex routingu pp_routes dla URL produktów z permutacją.
|
|
*
|
|
* Helpers::htacces() generuje pattern dla każdego produktu z permutacją.
|
|
* Pattern używa klasy znakowej [0-9_-]+, żeby dopasować segment "20-170_21-175"
|
|
* w jednym kawałku (separator pomiędzy parami atrybutów to "_", nie "/").
|
|
*
|
|
* Testy nie wywołują htacces() (zbyt duże zależności), tylko weryfikują:
|
|
* 1. Wzorzec literałem [0-9_-]+ występuje w generatorze pp_routes (file content)
|
|
* 2. Wzorzec przyjmuje URL z "_" i odrzuca wariant ze "/"
|
|
*/
|
|
class HelpersRoutingTest extends TestCase
|
|
{
|
|
private $helpersSource;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->helpersSource = file_get_contents(
|
|
__DIR__ . '/../../../../autoload/Shared/Helpers/Helpers.php'
|
|
);
|
|
}
|
|
|
|
public function testHelpersGeneratorUsesPermutationCharClassWithUnderscore()
|
|
{
|
|
// Liczba miejsc, gdzie pattern produktu z permutacją używa nowej klasy znaków.
|
|
$newPattern = substr_count($this->helpersSource, '/([0-9_-]+)$');
|
|
$this->assertGreaterThanOrEqual(
|
|
2,
|
|
$newPattern,
|
|
'Helpers.php musi zawierać dwa wystąpienia /([0-9_-]+)$ (gałąź seo_link i fallback p-id-name)'
|
|
);
|
|
|
|
// Stary wzorzec [0-9-]+ nie powinien już występować jako finalny segment URL.
|
|
$this->assertStringNotContainsString(
|
|
'/([0-9-]+)$',
|
|
$this->helpersSource,
|
|
'Stary wzorzec /([0-9-]+)$ został zastąpiony przez /([0-9_-]+)$ — nie powinno go już być w generatorze pp_routes'
|
|
);
|
|
}
|
|
|
|
public function testRegexMatchesUrlWithUnderscoreSeparator()
|
|
{
|
|
$pattern = '#^slug-produktu/([0-9_-]+)$#';
|
|
$matches = [];
|
|
|
|
$this->assertSame(
|
|
1,
|
|
preg_match($pattern, 'slug-produktu/20-170_21-175', $matches),
|
|
'Nowy wzorzec musi dopasować URL z "_" jako separatorem par atrybutów'
|
|
);
|
|
$this->assertSame('20-170_21-175', $matches[1]);
|
|
}
|
|
|
|
public function testRegexRejectsLegacyUrlWithSlashSeparator()
|
|
{
|
|
$pattern = '#^slug-produktu/([0-9_-]+)$#';
|
|
|
|
$this->assertSame(
|
|
0,
|
|
preg_match($pattern, 'slug-produktu/20-170/21-175'),
|
|
'Wzorzec NIE powinien dopasować starego URL ze "/" — taki URL ma trafiać do innego routingu lub 404'
|
|
);
|
|
}
|
|
|
|
public function testRegexMatchesSinglePairUrl()
|
|
{
|
|
$pattern = '#^slug-produktu/([0-9_-]+)$#';
|
|
$matches = [];
|
|
|
|
$this->assertSame(
|
|
1,
|
|
preg_match($pattern, 'slug-produktu/20-170', $matches),
|
|
'Wzorzec dopasowuje też URL z jedną parą attr-val'
|
|
);
|
|
$this->assertSame('20-170', $matches[1]);
|
|
}
|
|
}
|