4
0

FeedTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. use PHPUnit\Framework\Attributes\DataProvider;
  4. final class FeedTest extends \PHPUnit\Framework\TestCase {
  5. #[\Override]
  6. protected function setUp(): void {
  7. FreshRSS_Context::initSystem(reload: true);
  8. }
  9. #[\Override]
  10. protected function tearDown(): void {
  11. FreshRSS_Context::initSystem(reload: true); // Restore the default curl_options
  12. }
  13. #[DataProvider('provideStoredAndRequestedUrls')]
  14. public function test_load_obeysRetryAfter(string $storedUrl, string $requestedUrl, string $systemProxy = ''): void {
  15. if ($systemProxy !== '') {
  16. FreshRSS_Context::systemConf()->_attribute('curl_options', [CURLOPT_PROXY => $systemProxy]);
  17. }
  18. $getRetryAfterFile = new ReflectionMethod(FreshRSS_http_Util::class, 'getRetryAfterFile');
  19. $file = $getRetryAfterFile->invoke(null, $requestedUrl, $systemProxy);
  20. self::assertIsString($file);
  21. self::assertTrue(touch($file, time() + 600));
  22. try {
  23. (new FreshRSS_Feed($storedUrl, validate: false))->load();
  24. self::fail('The feed was loaded during its Retry-After');
  25. } catch (FreshRSS_Feed_Exception $e) {
  26. self::assertStringContainsString('will first retry after', $e->getMessage());
  27. } finally {
  28. unlink($file);
  29. }
  30. }
  31. /** @return array<string,array{0:string,1:string,2?:string}> */
  32. public static function provideStoredAndRequestedUrls(): array {
  33. // On a local network, where Retry-After is per URL
  34. return [
  35. 'HTML-encoded' => ['http://192.168.1.2/?action=display&amp;bridge=Example', 'http://192.168.1.2/?action=display&bridge=Example'],
  36. 'force_feed' => ['http://192.168.1.2/feed#force_feed', 'http://192.168.1.2/feed'],
  37. 'system proxy' => ['http://192.168.1.2/feed', 'http://192.168.1.2/feed', 'proxy.example.test:3128'],
  38. ];
  39. }
  40. }