|
| 1 | +<?php |
| 2 | +declare(strict_types = 1); |
| 3 | + |
| 4 | +namespace Embed\Tests; |
| 5 | + |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | + |
| 8 | +/** |
| 9 | + * Test that AuthorUrl detectors handle empty and zero strings correctly. |
| 10 | + * |
| 11 | + * Verifies that empty username/owner values and '0' do not generate invalid URLs |
| 12 | + * like "https://twitter.com/" or "https://twitter.com/0" but instead fallback to parent detector. |
| 13 | + */ |
| 14 | +class AuthorUrlEmptyStringTest extends TestCase |
| 15 | +{ |
| 16 | + public function testEmptyUsernameDoesNotCreateInvalidUrl() |
| 17 | + { |
| 18 | + // Test implementation: Verify the code pattern in AuthorUrl detectors |
| 19 | + // The actual check is: if (is_string($username) && $username !== '' && $username !== '0') |
| 20 | + // This ensures empty strings and '0' don't create invalid URLs |
| 21 | + |
| 22 | + $files = [ |
| 23 | + 'src/Adapters/Twitter/Detectors/AuthorUrl.php', |
| 24 | + 'src/Adapters/Gist/Detectors/AuthorUrl.php', |
| 25 | + 'src/Adapters/ImageShack/Detectors/AuthorUrl.php', |
| 26 | + ]; |
| 27 | + |
| 28 | + foreach ($files as $file) { |
| 29 | + $content = file_get_contents(__DIR__ . '/../' . $file); |
| 30 | + $this->assertNotFalse($content, "File $file should exist"); |
| 31 | + |
| 32 | + // Verify the pattern includes type, empty string, and '0' check |
| 33 | + $hasTypeCheck = str_contains($content, 'is_string('); |
| 34 | + $hasEmptyCheck = str_contains($content, "!== ''"); |
| 35 | + $hasZeroCheck = str_contains($content, "!== '0'"); |
| 36 | + |
| 37 | + $this->assertTrue( |
| 38 | + $hasTypeCheck && $hasEmptyCheck && $hasZeroCheck, |
| 39 | + "File $file should check type (is_string), empty string, and '0'" |
| 40 | + ); |
| 41 | + } |
| 42 | + } |
| 43 | +} |
0 commit comments