104 lines
4.1 KiB
PHP
104 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\AdminRole;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Spatie\Permission\Models\Role;
|
|
use Spatie\Permission\PermissionRegistrar;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* php artisan upgrade:verify: a read-only check per area, run before and after every upgrade step
|
|
* (references/plans/LARAVEL_UPGRADE_PLAN.md, section 4.2). Exit code 1 when a check fails.
|
|
*/
|
|
class UpgradeVerifyCommandTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
private function makeScopedRole(array $definitionPermissions, array $rolePermissions): string
|
|
{
|
|
foreach (array_unique(array_merge($definitionPermissions, $rolePermissions)) as $name) {
|
|
Permission::findOrCreate($name, 'web');
|
|
}
|
|
$definition = AdminRole::create(['name' => 'verify-test-role', 'label' => 'Verify test', 'permissions' => $definitionPermissions]);
|
|
$role = Role::create(['name' => "Admin\\999\\{$definition->name}", 'guard_name' => 'web']);
|
|
$role->syncPermissions($rolePermissions);
|
|
app(PermissionRegistrar::class)->forgetCachedPermissions();
|
|
|
|
return $role->name;
|
|
}
|
|
|
|
public function test_scoped_roles_in_sync_with_their_definition_pass(): void
|
|
{
|
|
$this->makeScopedRole(['verify view', 'verify edit'], ['verify edit', 'verify view']);
|
|
|
|
$this->artisan('upgrade:verify', ['--only' => 'permissions'])
|
|
->expectsOutputToContain('scoped roles match admin_roles / organization_roles')
|
|
->assertExitCode(0);
|
|
}
|
|
|
|
public function test_a_scoped_role_that_differs_from_its_definition_fails(): void
|
|
{
|
|
$name = $this->makeScopedRole(['verify view', 'verify edit'], ['verify view']);
|
|
|
|
$this->artisan('upgrade:verify', ['--only' => 'permissions'])
|
|
->expectsOutputToContain($name)
|
|
->assertExitCode(1);
|
|
}
|
|
|
|
public function test_an_app_user_that_may_change_transactions_fails(): void
|
|
{
|
|
// The tests connect as MySQL root, which may UPDATE and DELETE everything
|
|
$this->artisan('upgrade:verify', ['--only' => 'payments'])
|
|
->expectsOutputToContain('may UPDATE or DELETE transactions')
|
|
->assertExitCode(1);
|
|
}
|
|
|
|
public function test_a_platform_still_named_like_the_template_gets_a_warning(): void
|
|
{
|
|
config([config('app.timebank_config') . '.platform_translations.en.platform_name' => 'Example Timebank']);
|
|
|
|
$this->artisan('upgrade:verify', ['--only' => 'white-label'])
|
|
->expectsOutputToContain("platform name is 'Example Timebank'")
|
|
->assertExitCode(0);
|
|
}
|
|
|
|
public function test_a_missing_platform_config_fails(): void
|
|
{
|
|
config(['app.timebank_config' => 'does-not-exist']);
|
|
|
|
$this->artisan('upgrade:verify', ['--only' => 'white-label'])
|
|
->expectsOutputToContain('config/does-not-exist.php does not exist')
|
|
->assertExitCode(1);
|
|
}
|
|
|
|
public function test_a_platform_folder_config_counts_as_the_platform_config(): void
|
|
{
|
|
$root = sys_get_temp_dir() . '/verify-platform-' . uniqid();
|
|
mkdir($root);
|
|
file_put_contents("{$root}/config.php", "<?php\n\nreturn ['local_pages' => [], 'android_app' => ['enabled' => false]];\n");
|
|
config(['app.timebank_config' => 'does-not-exist', 'app.platform_path' => $root]);
|
|
|
|
try {
|
|
$this->artisan('upgrade:verify', ['--only' => 'white-label,platform'])
|
|
->expectsOutputToContain('platform config: platform/config.php')
|
|
->expectsOutputToContain('Platform config: platform/config.php')
|
|
->assertExitCode(0);
|
|
} finally {
|
|
unlink("{$root}/config.php");
|
|
rmdir($root);
|
|
}
|
|
}
|
|
|
|
public function test_it_changes_nothing(): void
|
|
{
|
|
$before = [Role::count(), Permission::count(), AdminRole::count(), \DB::table('transactions')->count()];
|
|
|
|
$this->artisan('upgrade:verify', ['--only' => 'framework,profiles,permissions,white-label,payments']);
|
|
|
|
$this->assertSame($before, [Role::count(), Permission::count(), AdminRole::count(), \DB::table('transactions')->count()]);
|
|
}
|
|
}
|