1
0

SettingsPageTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Tests\Integration\Settings;
  4. use App\Auth\UserContext;
  5. use App\Tests\Integration\Support\AppTestCase;
  6. final class SettingsPageTest extends AppTestCase
  7. {
  8. protected function setUp(): void
  9. {
  10. $this->bootApp();
  11. }
  12. public function testAdminSeesConfigAndJobs(): void
  13. {
  14. $_SESSION['_user'] = (new UserContext(1, 'Admin', 'admin', null, UserContext::SOURCE_LOCAL))->toArray();
  15. $_SESSION['_last_active'] = time();
  16. $_SESSION['_authenticated_at'] = time();
  17. // First call: getConfig
  18. $this->enqueueApiResponse(200, [
  19. 'sections' => [
  20. 'app' => ['APP_ENV' => 'development', 'LOG_LEVEL' => 'Info'],
  21. 'database' => ['DB_DRIVER' => 'sqlite'],
  22. 'auth' => ['INTERNAL_JOB_TOKEN' => '***', 'UI_SERVICE_TOKEN' => 'irdb_svc...'],
  23. 'reputation' => ['SCORE_REPORT_HARD_CUTOFF_DAYS' => 365],
  24. 'jobs' => ['JOB_AUDIT_RETENTION_DAYS' => 180],
  25. 'geoip' => ['GEOIP_PROVIDER' => 'dbip', 'GEOIP_COUNTRY_DB' => '/data/geoip/country.mmdb', 'GEOIP_ASN_DB' => '/data/geoip/asn.mmdb', 'MAXMIND_LICENSE_KEY' => '', 'IPINFO_TOKEN' => ''],
  26. ],
  27. ]);
  28. // Second call: getJobsStatus
  29. $this->enqueueApiResponse(200, [
  30. 'now' => '2026-04-29T10:00:00Z',
  31. 'jobs' => [
  32. 'recompute-scores' => [
  33. 'name' => 'recompute-scores',
  34. 'default_interval_seconds' => 300,
  35. 'max_runtime_seconds' => 240,
  36. 'overdue' => false,
  37. 'lock' => null,
  38. 'last_run' => [
  39. 'id' => 1,
  40. 'status' => 'success',
  41. 'items_processed' => 0,
  42. 'triggered_by' => 'schedule',
  43. 'started_at' => '2026-04-29T09:55:00Z',
  44. 'finished_at' => '2026-04-29T09:55:01Z',
  45. 'error_message' => null,
  46. ],
  47. ],
  48. ],
  49. ]);
  50. $resp = $this->request('GET', '/app/settings');
  51. self::assertSame(200, $resp->getStatusCode());
  52. $body = (string) $resp->getBody();
  53. self::assertStringContainsString('Configuration', $body);
  54. self::assertStringContainsString('Jobs', $body);
  55. self::assertStringContainsString('GeoIP', $body);
  56. self::assertStringContainsString('recompute-scores', $body);
  57. self::assertStringContainsString('Run now', $body);
  58. self::assertStringContainsString('dbip', $body);
  59. }
  60. public function testViewerRedirectsToNoAccess(): void
  61. {
  62. $_SESSION['_user'] = (new UserContext(2, 'Viewer', 'viewer', null, UserContext::SOURCE_LOCAL))->toArray();
  63. $_SESSION['_last_active'] = time();
  64. $_SESSION['_authenticated_at'] = time();
  65. $resp = $this->request('GET', '/app/settings');
  66. self::assertSame(303, $resp->getStatusCode());
  67. self::assertSame('/no-access', $resp->getHeaderLine('Location'));
  68. }
  69. public function testAnonymousRedirectsToLogin(): void
  70. {
  71. $_SESSION = [];
  72. $resp = $this->request('GET', '/app/settings');
  73. self::assertSame(302, $resp->getStatusCode());
  74. self::assertSame('/login', $resp->getHeaderLine('Location'));
  75. }
  76. }