]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/RecycleBinApiTest.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / tests / Api / RecycleBinApiTest.php
index 05c896bd9632a47f9da1e9f546e4f79b46cb5321..d174838c27d0db38d5346cae9478ba1c0b3d09bd 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,10 +47,10 @@ class RecycleBinApiTest extends TestCase
 
     public function test_index_endpoint_returns_expected_page()
     {
-        $admin = $this->getAdmin();
+        $admin = $this->users->admin();
 
-        $page = Page::query()->first();
-        $book = Book::query()->first();
+        $page = $this->entities->page();
+        $book = $this->entities->book();
         $this->actingAs($admin)->delete($page->getUrl());
         $this->delete($book->getUrl());
 
@@ -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();
@@ -125,9 +124,9 @@ class RecycleBinApiTest extends TestCase
                     'parent' => [
                         'id'   => $page->chapter->id,
                         'name' => $page->chapter->name,
-                        'type' => 'chapter'
-                    ]
-                ]
+                        'type' => 'chapter',
+                    ],
+                ],
             ],
         ];
 
@@ -139,7 +138,7 @@ class RecycleBinApiTest extends TestCase
 
     public function test_restore_endpoint()
     {
-        $page = Page::query()->first();
+        $page = $this->entities->page();
         $this->asAdmin()->delete($page->getUrl());
         $page->refresh();
 
@@ -152,7 +151,7 @@ class RecycleBinApiTest extends TestCase
 
         $resp = $this->putJson($this->baseEndpoint . '/' . $deletion->id);
         $resp->assertJson([
-            'restore_count' => 1
+            'restore_count' => 1,
         ]);
 
         $this->assertDatabaseHas('pages', [
@@ -163,7 +162,7 @@ class RecycleBinApiTest extends TestCase
 
     public function test_destroy_endpoint()
     {
-        $page = Page::query()->first();
+        $page = $this->entities->page();
         $this->asAdmin()->delete($page->getUrl());
         $page->refresh();
 
@@ -176,7 +175,7 @@ class RecycleBinApiTest extends TestCase
 
         $resp = $this->deleteJson($this->baseEndpoint . '/' . $deletion->id);
         $resp->assertJson([
-            'delete_count' => 1
+            'delete_count' => 1,
         ]);
 
         $this->assertDatabaseMissing('pages', ['id' => $page->id]);