X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/3a36d3c847d235da3926f80303715e5349ee449f..refs/pull/5721/head:/tests/Api/PagesApiTest.php diff --git a/tests/Api/PagesApiTest.php b/tests/Api/PagesApiTest.php index a1f65692f..ced8954eb 100644 --- a/tests/Api/PagesApiTest.php +++ b/tests/Api/PagesApiTest.php @@ -27,43 +27,15 @@ class PagesApiTest extends TestCase 'slug' => $firstPage->slug, 'book_id' => $firstPage->book->id, 'priority' => $firstPage->priority, + 'owned_by' => $firstPage->owned_by, + 'created_by' => $firstPage->created_by, + 'updated_by' => $firstPage->updated_by, + 'revision_count' => $firstPage->revision_count, ], ]]); } public function test_create_endpoint() - { - $this->actingAsApiEditor(); - $book = $this->entities->book(); - $details = [ - 'name' => 'My API page', - 'book_id' => $book->id, - 'html' => '
My new page content
', - 'tags' => [ - [ - 'name' => 'tagname', - 'value' => 'tagvalue', - ], - ], - ]; - - $resp = $this->postJson($this->baseEndpoint, $details); - unset($details['html']); - $resp->assertStatus(200); - $newItem = Page::query()->orderByDesc('id')->where('name', '=', $details['name'])->first(); - $resp->assertJson(array_merge($details, ['id' => $newItem->id, 'slug' => $newItem->slug])); - $this->assertDatabaseHas('tags', [ - 'entity_id' => $newItem->id, - 'entity_type' => $newItem->getMorphClass(), - 'name' => 'tagname', - 'value' => 'tagvalue', - ]); - $resp->assertSeeText('My new page content'); - $resp->assertJsonMissing(['book' => []]); - $this->assertActivityExists('page_create', $newItem); - } - - public function test_create_applies_correct_priority() { $this->actingAsApiEditor(); $book = $this->entities->book(); @@ -336,60 +308,4 @@ class PagesApiTest extends TestCase $resp->assertStatus(204); $this->assertActivityExists('page_delete', $page); } - - public function test_export_html_endpoint() - { - $this->actingAsApiEditor(); - $page = $this->entities->page(); - - $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/html"); - $resp->assertStatus(200); - $resp->assertSee($page->name); - $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.html"'); - } - - public function test_export_plain_text_endpoint() - { - $this->actingAsApiEditor(); - $page = $this->entities->page(); - - $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/plaintext"); - $resp->assertStatus(200); - $resp->assertSee($page->name); - $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.txt"'); - } - - public function test_export_pdf_endpoint() - { - $this->actingAsApiEditor(); - $page = $this->entities->page(); - - $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/pdf"); - $resp->assertStatus(200); - $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.pdf"'); - } - - public function test_export_markdown_endpoint() - { - $this->actingAsApiEditor(); - $page = $this->entities->page(); - - $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/markdown"); - $resp->assertStatus(200); - $resp->assertSee('# ' . $page->name); - $resp->assertHeader('Content-Disposition', 'attachment; filename="' . $page->slug . '.md"'); - } - - public function test_cant_export_when_not_have_permission() - { - $types = ['html', 'plaintext', 'pdf', 'markdown']; - $this->actingAsApiEditor(); - $this->permissions->removeUserRolePermissions($this->users->editor(), ['content-export']); - - $page = $this->entities->page(); - foreach ($types as $type) { - $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/{$type}"); - $this->assertPermissionError($resp); - } - } }