mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-09 10:22:51 +03:00
Copied over work from user_permissions branch
Only that relevant to the additional testing work.
This commit is contained in:
@@ -19,7 +19,7 @@ class ClearActivityCommandTest extends TestCase
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'type' => 'page_update',
|
||||
'entity_id' => $page->id,
|
||||
'user_id' => $this->getEditor()->id,
|
||||
'user_id' => $this->users->editor()->id,
|
||||
]);
|
||||
|
||||
DB::rollBack();
|
||||
|
@@ -16,7 +16,7 @@ class ClearViewsCommandTest extends TestCase
|
||||
$this->get($page->getUrl());
|
||||
|
||||
$this->assertDatabaseHas('views', [
|
||||
'user_id' => $this->getEditor()->id,
|
||||
'user_id' => $this->users->editor()->id,
|
||||
'viewable_id' => $page->id,
|
||||
'views' => 1,
|
||||
]);
|
||||
@@ -27,7 +27,7 @@ class ClearViewsCommandTest extends TestCase
|
||||
$this->assertTrue($exitCode === 0, 'Command executed successfully');
|
||||
|
||||
$this->assertDatabaseMissing('views', [
|
||||
'user_id' => $this->getEditor()->id,
|
||||
'user_id' => $this->users->editor()->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -18,11 +18,11 @@ class CopyShelfPermissionsCommandTest extends TestCase
|
||||
{
|
||||
$shelf = $this->entities->shelf();
|
||||
$child = $shelf->books()->first();
|
||||
$editorRole = $this->getEditor()->roles()->first();
|
||||
$editorRole = $this->users->editor()->roles()->first();
|
||||
$this->assertFalse($child->hasPermissions(), 'Child book should not be restricted by default');
|
||||
$this->assertTrue($child->permissions()->count() === 0, 'Child book should have no permissions by default');
|
||||
|
||||
$this->entities->setPermissions($shelf, ['view', 'update'], [$editorRole]);
|
||||
$this->permissions->setEntityPermissions($shelf, ['view', 'update'], [$editorRole]);
|
||||
$this->artisan('bookstack:copy-shelf-permissions', [
|
||||
'--slug' => $shelf->slug,
|
||||
]);
|
||||
@@ -43,11 +43,11 @@ class CopyShelfPermissionsCommandTest extends TestCase
|
||||
$shelf = $this->entities->shelf();
|
||||
Bookshelf::query()->where('id', '!=', $shelf->id)->delete();
|
||||
$child = $shelf->books()->first();
|
||||
$editorRole = $this->getEditor()->roles()->first();
|
||||
$editorRole = $this->users->editor()->roles()->first();
|
||||
$this->assertFalse($child->hasPermissions(), 'Child book should not be restricted by default');
|
||||
$this->assertTrue($child->permissions()->count() === 0, 'Child book should have no permissions by default');
|
||||
|
||||
$this->entities->setPermissions($shelf, ['view', 'update'], [$editorRole]);
|
||||
$this->permissions->setEntityPermissions($shelf, ['view', 'update'], [$editorRole]);
|
||||
$this->artisan('bookstack:copy-shelf-permissions --all')
|
||||
->expectsQuestion('Permission settings for all shelves will be cascaded. Books assigned to multiple shelves will receive only the permissions of it\'s last processed shelf. Are you sure you want to proceed?', 'y');
|
||||
$child = $shelf->books()->first();
|
||||
|
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace Tests\Commands;
|
||||
|
||||
use BookStack\Auth\Permissions\JointPermission;
|
||||
use BookStack\Entities\Models\Page;
|
||||
use BookStack\Auth\Permissions\CollapsedPermission;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
@@ -13,15 +12,23 @@ class RegeneratePermissionsCommandTest extends TestCase
|
||||
public function test_regen_permissions_command()
|
||||
{
|
||||
DB::rollBack();
|
||||
JointPermission::query()->truncate();
|
||||
$page = Page::first();
|
||||
$page = $this->entities->page();
|
||||
$editor = $this->users->editor();
|
||||
$this->permissions->addEntityPermission($page, ['view'], null, $editor);
|
||||
CollapsedPermission::query()->truncate();
|
||||
|
||||
$this->assertDatabaseMissing('joint_permissions', ['entity_id' => $page->id]);
|
||||
$this->assertDatabaseMissing('entity_permissions_collapsed', ['entity_id' => $page->id]);
|
||||
|
||||
$exitCode = Artisan::call('bookstack:regenerate-permissions');
|
||||
$this->assertTrue($exitCode === 0, 'Command executed successfully');
|
||||
DB::beginTransaction();
|
||||
|
||||
$this->assertDatabaseHas('joint_permissions', ['entity_id' => $page->id]);
|
||||
$this->assertDatabaseHas('entity_permissions_collapsed', [
|
||||
'entity_id' => $page->id,
|
||||
'user_id' => $editor->id,
|
||||
'view' => 1,
|
||||
]);
|
||||
|
||||
CollapsedPermission::query()->truncate();
|
||||
DB::beginTransaction();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user