X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b56f7355aa3a44c8529073fc2a3e760d0404f2ad..refs/pull/3918/head:/tests/Entity/BookShelfTest.php diff --git a/tests/Entity/BookShelfTest.php b/tests/Entity/BookShelfTest.php index 798edeadf..5d919f12b 100644 --- a/tests/Entity/BookShelfTest.php +++ b/tests/Entity/BookShelfTest.php @@ -39,7 +39,7 @@ class BookShelfTest extends TestCase { $user = User::factory()->create(); $this->giveUserPermissions($user, ['image-create-all']); - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $userRole = $user->roles()->first(); $resp = $this->actingAs($user)->get('/'); @@ -130,7 +130,7 @@ class BookShelfTest extends TestCase public function test_shelf_view() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asEditor()->get($shelf->getUrl()); $resp->assertStatus(200); $resp->assertSeeText($shelf->name); @@ -143,7 +143,7 @@ class BookShelfTest extends TestCase public function test_shelf_view_shows_action_buttons() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asAdmin()->get($shelf->getUrl()); $resp->assertSee($shelf->getUrl('/create-book')); $resp->assertSee($shelf->getUrl('/edit')); @@ -201,7 +201,7 @@ class BookShelfTest extends TestCase public function test_shelf_edit() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asEditor()->get($shelf->getUrl('/edit')); $resp->assertSeeText('Edit Shelf'); @@ -239,7 +239,7 @@ class BookShelfTest extends TestCase public function test_shelf_create_new_book() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asEditor()->get($shelf->getUrl('/create-book')); $resp->assertSee('Create New Book'); @@ -288,14 +288,14 @@ class BookShelfTest extends TestCase public function test_shelf_copy_permissions() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asAdmin()->get($shelf->getUrl('/permissions')); $resp->assertSeeText('Copy Permissions'); $resp->assertSee("action=\"{$shelf->getUrl('/copy-permissions')}\"", false); $child = $shelf->books()->first(); $editorRole = $this->getEditor()->roles()->first(); - $this->assertFalse(boolval($child->restricted), 'Child book should not be restricted by default'); + $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]); @@ -303,22 +303,26 @@ class BookShelfTest extends TestCase $child = $shelf->books()->first(); $resp->assertRedirect($shelf->getUrl()); - $this->assertTrue(boolval($child->restricted), 'Child book should now be restricted'); + $this->assertTrue($child->hasPermissions(), 'Child book should now be restricted'); $this->assertTrue($child->permissions()->count() === 2, 'Child book should have copied permissions'); - $this->assertDatabaseHas('entity_permissions', ['restrictable_id' => $child->id, 'action' => 'view', 'role_id' => $editorRole->id]); - $this->assertDatabaseHas('entity_permissions', ['restrictable_id' => $child->id, 'action' => 'update', 'role_id' => $editorRole->id]); + $this->assertDatabaseHas('entity_permissions', [ + 'entity_type' => 'book', + 'entity_id' => $child->id, + 'role_id' => $editorRole->id, + 'view' => true, 'update' => true, 'create' => false, 'delete' => false, + ]); } public function test_permission_page_has_a_warning_about_no_cascading() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asAdmin()->get($shelf->getUrl('/permissions')); $resp->assertSeeText('Permissions on shelves do not automatically cascade to contained books.'); } public function test_bookshelves_show_in_breadcrumbs_if_in_context() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $shelfBook = $shelf->books()->first(); $shelfPage = $shelfBook->pages()->first(); $this->asAdmin();