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]); } }