streamFooterTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare(strict_types=1);
  3. use PHPUnit\Framework\Attributes\DataProvider;
  4. use PHPUnit\Framework\Attributes\PreserveGlobalState;
  5. use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
  6. #[RunTestsInSeparateProcesses]
  7. #[PreserveGlobalState(false)]
  8. final class streamFooterTest extends \PHPUnit\Framework\TestCase {
  9. /** @return Traversable<string,array{array<string,string>,int,string}> */
  10. public static function providePaginationStates(): Traversable {
  11. yield 'automatic first page' => [[], 2, '0'];
  12. yield 'explicit unread first page' => [['state' => '2'], 2, '2'];
  13. yield 'explicit favourite first page' => [['state' => '4'], 4, '4'];
  14. yield 'automatic unread next page' => [['state' => '2', 'stateForRedirect' => '0'], 2, '0'];
  15. yield 'automatic all next page' => [['state' => '3', 'stateForRedirect' => '0'], 3, '0'];
  16. yield 'explicit favourite next page' => [['state' => '4', 'stateForRedirect' => '4'], 4, '4'];
  17. }
  18. /** @param array<string,string> $request */
  19. #[DataProvider('providePaginationStates')]
  20. public function testPaginationKeepsTheRequestedState(array $request, int $resolvedState, string $requestedState): void {
  21. FreshRSS_Context::initSystem();
  22. Minz_Translate::init('en');
  23. FreshRSS_Context::$state = $resolvedState;
  24. FreshRSS_Context::$continuation_id = '123';
  25. FreshRSS_Context::$search = new FreshRSS_BooleanSearch('needle');
  26. Minz_Request::_params($request + ['search' => 'needle']);
  27. $view = new FreshRSS_View();
  28. $view->_path('helpers/stream-footer.phtml');
  29. $html = new DOMDocument();
  30. self::assertTrue($html->loadHTML($view->renderToString(), LIBXML_NONET));
  31. $button = $html->getElementById('load_more');
  32. self::assertInstanceOf(DOMElement::class, $button);
  33. $query = parse_url($button->getAttribute('formaction'), PHP_URL_QUERY);
  34. self::assertIsString($query);
  35. parse_str($query, $params);
  36. self::assertSame((string)$resolvedState, $params['state'] ?? null);
  37. self::assertSame($requestedState, $params['stateForRedirect'] ?? null);
  38. self::assertSame('needle', $params['search'] ?? null);
  39. self::assertSame('123', $params['cid'] ?? null);
  40. self::assertSame('1', $params['ajax'] ?? null);
  41. }
  42. }