mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 12:13:13 +08:00
Centralized how routes are configured to support multi-segment slugs
This commit is contained in:
60
module/Core/test/Config/MultiSegmentSlugProcessorTest.php
Normal file
60
module/Core/test/Config/MultiSegmentSlugProcessorTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Config\MultiSegmentSlugProcessor;
|
||||
|
||||
class MultiSegmentSlugProcessorTest extends TestCase
|
||||
{
|
||||
private MultiSegmentSlugProcessor $processor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->processor = new MultiSegmentSlugProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideConfigs
|
||||
*/
|
||||
public function parsesRoutesAsExpected(array $config, array $expectedRoutes): void
|
||||
{
|
||||
self::assertEquals($expectedRoutes, ($this->processor)($config)['routes'] ?? []);
|
||||
}
|
||||
|
||||
public function provideConfigs(): iterable
|
||||
{
|
||||
yield [[], []];
|
||||
yield [['url_shortener' => []], []];
|
||||
yield [['url_shortener' => ['multi_segment_slugs_enabled' => false]], []];
|
||||
yield [
|
||||
[
|
||||
'url_shortener' => ['multi_segment_slugs_enabled' => false],
|
||||
'routes' => $routes = [
|
||||
['path' => '/foo'],
|
||||
['path' => '/bar/{shortCode}'],
|
||||
['path' => '/baz/{shortCode}/foo'],
|
||||
],
|
||||
],
|
||||
$routes,
|
||||
];
|
||||
yield [
|
||||
[
|
||||
'url_shortener' => ['multi_segment_slugs_enabled' => true],
|
||||
'routes' => [
|
||||
['path' => '/foo'],
|
||||
['path' => '/bar/{shortCode}'],
|
||||
['path' => '/baz/{shortCode}/foo'],
|
||||
],
|
||||
],
|
||||
[
|
||||
['path' => '/foo'],
|
||||
['path' => '/bar/{shortCode:.+}'],
|
||||
['path' => '/baz/{shortCode:.+}/foo'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user