extend(TestCase::class)->in('Feature', 'Browser'); /** * The element name (under `<`) and the attributes of the first tag in a rendered component, by * name; a boolean attribute Blade renders as `name="name"`. For the layout components' render * tests, which assert what their root carries. * * @return array */ function layoutRoot(string $html): array { preg_match('/^\s*<([a-z]+)\b([^>]*)>/s', $html, $tag); preg_match_all('/([\w:.@-]+)(?:="([^"]*)")?/', $tag[2] ?? '', $pairs, PREG_SET_ORDER); return ['<' => $tag[1] ?? ''] + collect($pairs)->mapWithKeys(fn (array $pair): array => [$pair[1] => $pair[2] ?? ''])->all(); } // A shared CI runner is slower than a workstation: an animation or a smooth scroll can take longer // than the default five seconds to settle there. BROWSER_TIMEOUT (milliseconds) raises the limit. if (($timeout = (int) getenv('BROWSER_TIMEOUT')) > 0) { pest()->browser()->timeout($timeout); } /** * The named block of resources/css/all.css — the content between its `/* Heading *\/` comment and * the next one, or the end of the file for the last block ("Navigation"). components.css and * layout.css grouped their imports the same way before plan step 37 folded both into all.css; this * is the one place that block lookup lives now, so a stylesheet test asks "is this imported from * the Containment block" without repeating the search in every file that needs it. It is here, * rather than in tests/Feature/StylesheetsTest.php, because Pest.php is always loaded, whichever * test file or path is run. */ function allCssBlock(string $heading): string { $all = File::get(__DIR__.'/../resources/css/all.css'); $marker = "/* {$heading} */"; $start = strpos($all, $marker); if ($start === false) { throw new RuntimeException("all.css has no `{$marker}` block."); } $next = strpos($all, '/*', $start + strlen($marker)); return $next === false ? substr($all, $start) : substr($all, $start, $next - $start); }