2021-06-26 23:23:15 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Commands;
|
2021-02-12 06:42:36 +08:00
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
use BookStack\Auth\Permissions\CollapsedPermission;
|
2022-07-13 03:15:41 +08:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2021-03-21 00:25:02 +08:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2021-02-12 06:42:36 +08:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class RegeneratePermissionsCommandTest extends TestCase
|
|
|
|
{
|
|
|
|
public function test_regen_permissions_command()
|
|
|
|
{
|
2022-07-13 03:15:41 +08:00
|
|
|
DB::rollBack();
|
2023-01-21 19:08:34 +08:00
|
|
|
$page = $this->entities->page();
|
|
|
|
$editor = $this->users->editor();
|
|
|
|
$this->permissions->addEntityPermission($page, ['view'], null, $editor);
|
|
|
|
CollapsedPermission::query()->truncate();
|
2021-02-12 06:42:36 +08:00
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
$this->assertDatabaseMissing('entity_permissions_collapsed', ['entity_id' => $page->id]);
|
2021-02-12 06:42:36 +08:00
|
|
|
|
2022-07-13 03:15:41 +08:00
|
|
|
$exitCode = Artisan::call('bookstack:regenerate-permissions');
|
2021-02-12 06:42:36 +08:00
|
|
|
$this->assertTrue($exitCode === 0, 'Command executed successfully');
|
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
$this->assertDatabaseHas('entity_permissions_collapsed', [
|
|
|
|
'entity_id' => $page->id,
|
|
|
|
'user_id' => $editor->id,
|
|
|
|
'view' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
CollapsedPermission::query()->truncate();
|
|
|
|
DB::beginTransaction();
|
2021-02-12 06:42:36 +08:00
|
|
|
}
|
2021-06-26 23:23:15 +08:00
|
|
|
}
|