actingAs($user); BackupSet::factory()->create([ 'managed_environment_id' => (int) $tenant->getKey(), 'name' => 'Restore fixture backup set', ]); $createUrl = RestoreRunResource::getUrl('create', panel: 'admin', tenant: $tenant); $response = $this ->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id]) ->get($createUrl); $response->assertSuccessful(); $html = (string) $response->getContent(); preg_match_all('/wire:snapshot="([^"]+)"/', $html, $snapshotMatches); $snapshots = $snapshotMatches[1] ?? []; expect($snapshots)->not->toBeEmpty('No Livewire snapshot found in restore create HTML'); $expectedPath = sprintf( 'admin/workspaces/%s/environments/%s/restore-runs/create', $tenant->workspace_id, $tenant->getRouteKey(), ); $snapshotJson = null; foreach ($snapshots as $encodedSnapshot) { $candidateJson = htmlspecialchars_decode($encodedSnapshot); $candidate = json_decode($candidateJson, true); if (! is_array($candidate)) { continue; } if (($candidate['memo']['path'] ?? null) === $expectedPath) { $snapshotJson = $candidateJson; break; } } expect($snapshotJson)->toBeString("No snapshot with memo.path [$expectedPath] found."); $updatePayload = [ 'components' => [[ 'snapshot' => $snapshotJson, 'updates' => new stdClass, 'calls' => [], ]], ]; $updateUri = '/'.collect(app('router')->getRoutes()->getRoutes()) ->first(fn ($route): bool => str_contains((string) $route->getName(), 'livewire.update')) ?->uri(); expect($updateUri)->toBeString('Livewire update route must exist'); $updateResponse = $this ->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id]) ->withHeaders([ 'X-Livewire' => 'true', 'Referer' => $createUrl, ]) ->postJson($updateUri, $updatePayload); $updateResponse->assertSuccessful(); });