httpUtilTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. use PHPUnit\Framework\Attributes\DataProvider;
  4. /**
  5. * Tests for FreshRSS_http_Util
  6. */
  7. class httpUtilTest extends \PHPUnit\Framework\TestCase {
  8. #[DataProvider('provideUrlsIgnoringHttps')]
  9. public function test_compareUrlIgnoringHttps(string $url1, string $url2, bool $expected): void {
  10. self::assertEquals($expected, FreshRSS_http_Util::compareUrlIgnoringHttps($url1, $url2) === 0);
  11. }
  12. /** @return list<array{string,string,bool}> */
  13. public static function provideUrlsIgnoringHttps(): array {
  14. return [
  15. // Only the scheme differs → equal
  16. ['http://www.blogger.com/feeds/1/posts', 'https://www.blogger.com/feeds/1/posts', true],
  17. ['https://example.net/feed.xml?a=1&b=2', 'http://example.net/feed.xml?a=1&b=2', true],
  18. ['HTTP://Example.net/Feed', 'https://Example.net/Feed', true],
  19. ['HTTPS://Example.net/Feed', 'http://Example.net/Feed', true],
  20. // Fully identical → equal
  21. ['https://example.net/feed', 'https://example.net/feed', true],
  22. ['', '', true],
  23. // Path differs → not equal (scheme-only tolerance must not hide real mismatches)
  24. ['http://example.net/a', 'https://example.net/b', false],
  25. // Trailing slash is a path difference → not equal
  26. ['http://example.net/', 'https://example.net', false],
  27. // Host differs → not equal
  28. ['http://a.example.net/feed', 'https://b.example.net/feed', false],
  29. // Query differs → not equal
  30. ['https://example.net/feed?a=1', 'http://example.net/feed?a=2', false],
  31. // Non-http(s) schemes are compared as-is
  32. ['ftp://example.net/feed', 'https://example.net/feed', false],
  33. ];
  34. }
  35. }