]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/RecycleBinApiTest.php
Merge pull request #5917 from BookStackApp/copy_references
[bookstack] / tests / Api / RecycleBinApiTest.php
index cdb51f85af759acad4164839027b4f8cbc85793c..6ccc69c3545c7d4e8973673a3947afed74b61822 100644 (file)
@@ -4,7 +4,6 @@ namespace Tests\Api;
 
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Deletion;
-use BookStack\Entities\Models\Page;
 use Illuminate\Support\Collection;
 use Tests\TestCase;
 
@@ -22,8 +21,8 @@ class RecycleBinApiTest extends TestCase
 
     public function test_settings_manage_permission_needed_for_all_endpoints()
     {
-        $editor = $this->getEditor();
-        $this->giveUserPermissions($editor, ['settings-manage']);
+        $editor = $this->users->editor();
+        $this->permissions->grantUserRolePermissions($editor, ['settings-manage']);
         $this->actingAs($editor);
 
         foreach ($this->endpointMap as [$method, $uri]) {
@@ -35,8 +34,8 @@ class RecycleBinApiTest extends TestCase
 
     public function test_restrictions_manage_all_permission_needed_for_all_endpoints()
     {
-        $editor = $this->getEditor();
-        $this->giveUserPermissions($editor, ['restrictions-manage-all']);
+        $editor = $this->users->editor();
+        $this->permissions->grantUserRolePermissions($editor, ['restrictions-manage-all']);
         $this->actingAs($editor);
 
         foreach ($this->endpointMap as [$method, $uri]) {
@@ -48,7 +47,7 @@ class RecycleBinApiTest extends TestCase
 
     public function test_index_endpoint_returns_expected_page()
     {
-        $admin = $this->getAdmin();
+        $admin = $this->users->admin();
 
         $page = $this->entities->page();
         $book = $this->entities->book();
@@ -83,7 +82,7 @@ class RecycleBinApiTest extends TestCase
 
     public function test_index_endpoint_returns_children_count()
     {
-        $admin = $this->getAdmin();
+        $admin = $this->users->admin();
 
         $book = Book::query()->whereHas('pages')->whereHas('chapters')->withCount(['pages', 'chapters'])->first();
         $this->actingAs($admin)->delete($book->getUrl());
@@ -110,8 +109,8 @@ class RecycleBinApiTest extends TestCase
 
     public function test_index_endpoint_returns_parent()
     {
-        $admin = $this->getAdmin();
-        $page = Page::query()->whereHas('chapter')->with('chapter')->first();
+        $admin = $this->users->admin();
+        $page = $this->entities->pageWithinChapter();
 
         $this->actingAs($admin)->delete($page->getUrl());
         $deletion = Deletion::query()->orderBy('id')->first();
@@ -145,7 +144,7 @@ class RecycleBinApiTest extends TestCase
 
         $deletion = Deletion::query()->orderBy('id')->first();
 
-        $this->assertDatabaseHas('pages', [
+        $this->assertDatabaseHasEntityData('page', [
             'id'            => $page->id,
             'deleted_at'    => $page->deleted_at,
         ]);
@@ -155,7 +154,7 @@ class RecycleBinApiTest extends TestCase
             'restore_count' => 1,
         ]);
 
-        $this->assertDatabaseHas('pages', [
+        $this->assertDatabaseHasEntityData('page', [
             'id'            => $page->id,
             'deleted_at'    => null,
         ]);
@@ -169,7 +168,7 @@ class RecycleBinApiTest extends TestCase
 
         $deletion = Deletion::query()->orderBy('id')->first();
 
-        $this->assertDatabaseHas('pages', [
+        $this->assertDatabaseHasEntityData('page', [
             'id'            => $page->id,
             'deleted_at'    => $page->deleted_at,
         ]);
@@ -179,6 +178,6 @@ class RecycleBinApiTest extends TestCase
             'delete_count' => 1,
         ]);
 
-        $this->assertDatabaseMissing('pages', ['id' => $page->id]);
+        $this->assertDatabaseMissing('entities', ['id' => $page->id, 'type' => 'page']);
     }
 }