59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Routing\RouteCollection;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Tests\TestCase;
|
|
|
|
class ReleaseGatingTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->actingAs(User::factory()->create(['must_change_password' => false]));
|
|
}
|
|
|
|
/**
|
|
* Set the release flag and re-evaluate routes/web.php so the conditional `/release`
|
|
* registration reflects it. The route file is read once at boot (flag default off), so a
|
|
* runtime config()->set() alone cannot register the route — re-loading the file mirrors a
|
|
* fresh request that re-includes routes/web.php with the flag now set.
|
|
*/
|
|
private function withReleaseFlag(bool $on): void
|
|
{
|
|
config()->set('clusev.release_controls', $on);
|
|
Route::setRoutes(new RouteCollection);
|
|
require base_path('routes/web.php');
|
|
$this->app['router']->getRoutes()->refreshNameLookups();
|
|
}
|
|
|
|
public function test_release_route_is_404_when_the_flag_is_off(): void
|
|
{
|
|
$this->withReleaseFlag(false);
|
|
$this->get('/release')->assertNotFound();
|
|
}
|
|
|
|
public function test_release_route_loads_when_the_flag_is_on(): void
|
|
{
|
|
$this->withReleaseFlag(true);
|
|
$this->get('/release')->assertOk();
|
|
}
|
|
|
|
public function test_sidebar_hides_the_release_item_when_the_flag_is_off(): void
|
|
{
|
|
$this->withReleaseFlag(false);
|
|
$this->get('/audit')->assertOk()->assertDontSee(__('release.nav'));
|
|
}
|
|
|
|
public function test_sidebar_shows_the_release_item_when_the_flag_is_on(): void
|
|
{
|
|
$this->withReleaseFlag(true);
|
|
$this->get('/audit')->assertOk()->assertSee(__('release.nav'));
|
|
}
|
|
}
|