PR CI / ledger (pull_request) Successful in 4s
PR CI / flow (pull_request) Successful in 4s
PR CI / ui (pull_request) Successful in 17s
PR CI / test (stable) (pull_request) Successful in 47s
PR CI / test (lowest) (pull_request) Successful in 50s
PR CI / security (pull_request) Successful in 51s
PR CI / pr-ci (pull_request) Successful in 1s
PR CI / release-automerge (pull_request) Successful in 4s
97 lines
3.5 KiB
PHP
97 lines
3.5 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use IriksIT\Manager\Support\ModuleRegistry;
|
|
use IriksIT\Manager\Tests\TestCase;
|
|
|
|
uses(TestCase::class);
|
|
|
|
// The installer publishes the config into the app, here the skeleton in vendor/: leave it as it was.
|
|
beforeEach(function () {
|
|
$this->hadConfig = file_exists(config_path('manager.php'));
|
|
$this->env = file_exists(base_path('.env')) ? file_get_contents(base_path('.env')) : null;
|
|
});
|
|
afterEach(function () {
|
|
$this->hadConfig || @unlink(config_path('manager.php'));
|
|
$this->env === null ? @unlink(base_path('.env')) : file_put_contents(base_path('.env'), $this->env);
|
|
});
|
|
|
|
function doctorReport(): array
|
|
{
|
|
Artisan::call('manager:doctor', ['--json' => true]);
|
|
|
|
return json_decode(Artisan::output(), true);
|
|
}
|
|
|
|
it('reports a healthy setup as JSON with exit code 0', function () {
|
|
$report = doctorReport();
|
|
$status = collect($report['checks'])->pluck('status', 'check');
|
|
|
|
expect($status['user_trait'])->toBe('ok')
|
|
->and($status['tables'])->toBe('ok')
|
|
->and($status['routes'])->toBe('ok')
|
|
->and($report['ok'])->toBeTrue();
|
|
});
|
|
|
|
it('fails with a fix when the user model is not a class', function () {
|
|
config(['manager.user_model' => 'Nope\\User']);
|
|
|
|
$check = collect(doctorReport()['checks'])->firstWhere('check', 'user_model');
|
|
|
|
expect($check['status'])->toBe('fail')->and($check['fix'])->toContain('MANAGER_USER_MODEL');
|
|
expect(Artisan::call('manager:doctor'))->toBe(1);
|
|
});
|
|
|
|
it('warns when there is no super admin yet', function () {
|
|
$check = collect(doctorReport()['checks'])->firstWhere('check', 'super_admin');
|
|
|
|
expect($check['status'])->toBe('warn')->and($check['fix'])->toContain('manager:create-user');
|
|
});
|
|
|
|
it('lists the tables of the active modules', function () {
|
|
$tables = collect(app(ModuleRegistry::class)->active())->flatMap->tables();
|
|
|
|
expect($tables)->toContain('media', 'posts');
|
|
});
|
|
|
|
it('refuses an unknown module in the installer', function () {
|
|
expect(Artisan::call('manager:install', ['--modules' => 'users,nonsense']))->toBe(1);
|
|
});
|
|
|
|
it('writes the switches to .env', function () {
|
|
$env = base_path('.env');
|
|
|
|
Artisan::call('manager:install', ['--modules' => 'users,media,posts', '--path' => 'admin']);
|
|
|
|
$written = file_get_contents($env);
|
|
|
|
expect($written)->toContain('MANAGER_PATH=admin')->toContain('MANAGER_AUDIT=false')->toContain('MANAGER_POSTS=true');
|
|
});
|
|
|
|
it('leaves the check to a new process after it changed the switches', function () {
|
|
Artisan::call('manager:install', ['--path' => 'admin']);
|
|
|
|
expect(Artisan::output())->toContain('manager:doctor')->not->toContain('[OK]');
|
|
});
|
|
|
|
it('finds no shared names in a clean setup', function () {
|
|
$check = collect(doctorReport()['checks'])->firstWhere('check', 'names');
|
|
expect($check['message'])->toBe('No route name or address is shared with the site.');
|
|
});
|
|
|
|
it('warns when the site uses a route name of the manager, and says what to set', function () {
|
|
Route::get('/home', fn () => 'x')->name('manager.dashboard');
|
|
|
|
$check = collect(doctorReport()['checks'])->firstWhere('check', 'names');
|
|
|
|
expect($check['status'])->toBe('warn')->and($check['message'])->toContain('manager.dashboard')->and($check['fix'])->toContain('route_name');
|
|
});
|
|
|
|
it('warns when the site has routes under the address of the manager', function () {
|
|
Route::get('/manager/reports', fn () => 'x');
|
|
|
|
$check = collect(doctorReport()['checks'])->firstWhere('check', 'names');
|
|
|
|
expect($check['status'])->toBe('warn')->and($check['message'])->toContain('manager/reports');
|
|
});
|