X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ff8dadefee9e400bb46a54b301a8b701c4a0b61b..refs/pull/4554/head:/tests/Api/RecycleBinApiTest.php diff --git a/tests/Api/RecycleBinApiTest.php b/tests/Api/RecycleBinApiTest.php index 05c896bd9..d174838c2 100644 --- a/tests/Api/RecycleBinApiTest.php +++ b/tests/Api/RecycleBinApiTest.php @@ -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]);