string, 'response' => array]. */ function create_hc(string $siteKey, array $overrides = []): array { static $n = 0; $payload = array_merge([ // Dotted, like the plugin's uniqid() ids — also exercises the dev-router // path handling that plain `php -S -t public` gets wrong. 'id' => 'att_hc_test_' . (++$n) . '.' . bin2hex(random_bytes(3)), 'site_key' => $siteKey, 'started_at' => next_started_at(), 'reporting_url' => 'https://' . $siteKey, 'technician_id' => 1, 'wp_version' => '6.6', 'php_version' => '8.2', ], $overrides); $res = api('POST', '/healthchecks', $payload); return ['id' => (string) $payload['id'], 'response' => $res]; } /** * Read a field, distinguishing "present and null" from "absent". * * `$row['k'] ?? null` collapses those two cases, which would make every * "the date was cleared" assertion pass even if the field vanished entirely. */ function field(?array $row, string $key) { if ($row === null) return '<>'; return array_key_exists($key, $row) ? $row[$key] : '<>'; } function get_hc(string $id): array { return api('GET', '/healthchecks/' . rawurlencode($id)); } /** The authenticated dashboard session cookie (key → cookie handshake done once). */ function dash_cookie(): string { static $cookie = null; if ($cookie === null) { $login = api('GET', '/dashboard?key=' . rawurlencode(TestServer::API_KEY), null, null); $cookie = session_cookie($login) ?? ''; } return $cookie; } /** Authenticated dashboard GET. */ function dash(string $path): array { return api('GET', $path, null, null, ['Cookie: ' . dash_cookie()]); } /** The per-session CSRF token, scraped from a form on the given dashboard page. */ function dash_csrf(string $path): string { if (preg_match('/name="csrf"\s+value="([^"]+)"/', dash($path)['body'], $m)) { return $m[1]; } return ''; } /** * Form-encoded dashboard POST on the same session as dash() — that's what the * archive/reopen buttons submit, and what populates $_POST server-side (a JSON * body would not). Redirects are not followed, so the 302 is observable. */ function dash_post(string $path, array $fields): array { $http = [ 'method' => 'POST', 'ignore_errors' => true, 'follow_location' => 0, 'max_redirects' => 1, 'timeout' => 10, 'header' => implode("\r\n", [ 'Content-Type: application/x-www-form-urlencoded', 'Cookie: ' . dash_cookie(), ]), 'content' => http_build_query($fields), ]; $raw = @file_get_contents($GLOBALS['att_hc_base_url'] . $path, false, stream_context_create(['http' => $http])); $headers = $http_response_header ?? []; $status = 0; foreach ($headers as $h) { if (preg_match('#^HTTP/\S+\s+(\d{3})#', $h, $m)) $status = (int) $m[1]; } return ['status' => $status, 'body' => $raw === false ? '' : $raw, 'headers' => $headers]; } /** POST to the archive endpoint for a healthcheck id. */ function archive_hc(string $id, bool $archived, string $csrf): array { return dash_post( '/dashboard/healthchecks/' . rawurlencode($id) . '/archive', ['archived' => $archived ? '1' : '0', 'csrf' => $csrf] ); } /** * The home page's "Archived" section only (from its heading to the end). * Anchored on the

tag, not the bare class name — the latter also appears * in the page's