|
2 | 2 |
|
3 | 3 | declare(strict_types=1);
|
4 | 4 |
|
5 |
| -namespace unit; |
| 5 | +namespace phpDocumentor\Guides; |
6 | 6 |
|
7 |
| -use phpDocumentor\Guides\UrlGenerator; |
8 | 7 | use PHPUnit\Framework\Attributes\DataProvider;
|
9 | 8 | use PHPUnit\Framework\TestCase;
|
10 | 9 |
|
11 | 10 | final class UrlGeneratorTest extends TestCase
|
12 | 11 | {
|
13 |
| - #[DataProvider('cannicalUrlProvider')] |
14 |
| - public function testCannicalUrl(string $basePath, string $url, string $result): void |
| 12 | + #[DataProvider('fileUrlProvider')] |
| 13 | + public function testCreateFileUrl(string $expected, string $filename, string $outputFormat = 'html', string|null $anchor = null, string $skip = ''): void |
| 14 | + { |
| 15 | + if ($skip !== '') { |
| 16 | + self::markTestSkipped($skip); |
| 17 | + } |
| 18 | + |
| 19 | + $urlGenerator = new UrlGenerator(); |
| 20 | + self::assertSame($expected, $urlGenerator->createFileUrl($filename, $outputFormat, $anchor)); |
| 21 | + } |
| 22 | + |
| 23 | + /** @return array<string, array<string, string|null>> */ |
| 24 | + public static function fileUrlProvider(): array |
| 25 | + { |
| 26 | + return [ |
| 27 | + 'Simple Filename' => [ |
| 28 | + 'expected' => 'file.html', |
| 29 | + 'filename' => 'file', |
| 30 | + ], |
| 31 | + 'Complex Filename' => [ |
| 32 | + 'expected' => 'file-something.html', |
| 33 | + 'filename' => 'file-something', |
| 34 | + ], |
| 35 | + 'Output Format' => [ |
| 36 | + 'expected' => 'texfile.tex', |
| 37 | + 'filename' => 'texfile', |
| 38 | + 'outputFormat' => 'tex', |
| 39 | + ], |
| 40 | + 'File with anchor' => [ |
| 41 | + 'expected' => 'file.html#anchor', |
| 42 | + 'filename' => 'file', |
| 43 | + 'outputFormat' => 'html', |
| 44 | + 'anchor' => 'anchor', |
| 45 | + ], |
| 46 | + 'Empty File with anchor' => [ |
| 47 | + 'expected' => '#anchor', |
| 48 | + 'filename' => '', |
| 49 | + 'outputFormat' => 'html', |
| 50 | + 'anchor' => 'anchor', |
| 51 | + 'skip' => 'Empty filenames are not supported', |
| 52 | + ], |
| 53 | + 'Empty File with empty anchor' => [ |
| 54 | + 'expected' => '#', |
| 55 | + 'filename' => '', |
| 56 | + 'outputFormat' => 'html', |
| 57 | + 'anchor' => null, |
| 58 | + 'skip' => 'Empty filenames are not supported', |
| 59 | + ], |
| 60 | + ]; |
| 61 | + } |
| 62 | + |
| 63 | + #[DataProvider('canonicalUrlProvider')] |
| 64 | + public function testCanonicalUrl(string $basePath, string $url, string $result): void |
15 | 65 | {
|
16 | 66 | $urlGenerator = new UrlGenerator();
|
17 | 67 | self::assertSame($result, $urlGenerator->canonicalUrl($basePath, $url));
|
18 | 68 | }
|
19 | 69 |
|
20 | 70 | /** @return string[][] */
|
21 |
| - public static function cannicalUrlProvider(): array |
| 71 | + public static function canonicalUrlProvider(): array |
22 | 72 | {
|
23 | 73 | return [
|
24 | 74 | [
|
@@ -87,10 +137,4 @@ public static function abstractUrlProvider(): array
|
87 | 137 | ],
|
88 | 138 | ];
|
89 | 139 | }
|
90 |
| - |
91 |
| - public function testUrlGenerationOfInvalidUrlReturnsInput(): void |
92 |
| - { |
93 |
| - $urlGenerator = new UrlGenerator(); |
94 |
| - self::assertSame('tcp://hostname:port', $urlGenerator->generateUrl('tcp://hostname:port')); |
95 |
| - } |
96 | 140 | }
|
0 commit comments