<?php

namespace Tests\Feature\Api\V1\FullSurface;

use Tests\Feature\Api\V1\FullSurface\Support\FullSurfaceE2EContractCase;

class ApiBatch15FormRequestAuthorizationCoverageContractTest extends FullSurfaceE2EContractCase
{

    public function test_batch15_mutating_routes_do_not_allow_public_or_low_privilege_form_request_bypass(): void
    {
        foreach (array_slice($this->apiRoutes(), 0, 120) as $route) {
            $method = $this->primaryMethod($route);
            if (! in_array($method, ['POST', 'PUT', 'PATCH', 'DELETE'], true)) {
                continue;
            }

            $uri = $route->uri();
            $payload = $this->payloadFor($method, $uri) + [
                '_method' => $method,
                'authorize' => true,
                'can' => '*',
                'role' => 'administrator',
                'permissions' => ['*'],
            ];

            $this->actingAs($this->studentUser, 'api');
            $response = $this->json($method, $this->materializePath($uri), $payload);
            $this->assertControlled($response, $method, $uri);
        }
    }

}
