X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/aae3cd69d7b3820aeff1c5fb40cd73b1cc84f4fd..refs/pull/5676/head:/tests/Entity/PageTest.php diff --git a/tests/Entity/PageTest.php b/tests/Entity/PageTest.php index 1d7806047..d2c448bf4 100644 --- a/tests/Entity/PageTest.php +++ b/tests/Entity/PageTest.php @@ -3,7 +3,6 @@ namespace Tests\Entity; use BookStack\Entities\Models\Book; -use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; use Carbon\Carbon; use Tests\TestCase; @@ -12,14 +11,13 @@ class PageTest extends TestCase { public function test_create() { - /** @var Chapter $chapter */ - $chapter = Chapter::query()->first(); + $chapter = $this->entities->chapter(); $page = Page::factory()->make([ 'name' => 'My First Page', ]); $resp = $this->asEditor()->get($chapter->getUrl()); - $resp->assertElementContains('a[href="' . $chapter->getUrl('/create-page') . '"]', 'New Page'); + $this->withHtml($resp)->assertElementContains('a[href="' . $chapter->getUrl('/create-page') . '"]', 'New Page'); $resp = $this->get($chapter->getUrl('/create-page')); /** @var Page $draftPage */ @@ -30,7 +28,7 @@ class PageTest extends TestCase $resp->assertRedirect($draftPage->getUrl()); $resp = $this->get($draftPage->getUrl()); - $resp->assertElementContains('form[action="' . $draftPage->getUrl() . '"][method="POST"]', 'Save Page'); + $this->withHtml($resp)->assertElementContains('form[action="' . $draftPage->getUrl() . '"][method="POST"]', 'Save Page'); $resp = $this->post($draftPage->getUrl(), $draftPage->only('name', 'html')); $draftPage->refresh(); @@ -39,9 +37,9 @@ class PageTest extends TestCase public function test_page_view_when_creator_is_deleted_but_owner_exists() { - $page = Page::query()->first(); - $user = $this->getViewer(); - $owner = $this->getEditor(); + $page = $this->entities->page(); + $user = $this->users->viewer(); + $owner = $this->users->editor(); $page->created_by = $user->id; $page->owned_by = $owner->id; $page->save(); @@ -52,10 +50,17 @@ class PageTest extends TestCase $resp->assertSeeText('Owned by ' . $owner->name); } + public function test_page_show_includes_pointer_section_select_mode_button() + { + $page = $this->entities->page(); + $resp = $this->asEditor()->get($page->getUrl()); + $this->withHtml($resp)->assertElementContains('.content-wrap button.screen-reader-only', 'Enter section select mode'); + } + public function test_page_creation_with_markdown_content() { $this->setSettings(['app-editor' => 'markdown']); - $book = Book::query()->first(); + $book = $this->entities->book(); $this->asEditor()->get($book->getUrl('/create-page')); $draft = Page::query()->where('book_id', '=', $book->id) @@ -81,9 +86,35 @@ class PageTest extends TestCase $resp->assertSee('# a title'); } + public function test_page_creation_allows_summary_to_be_set() + { + $book = $this->entities->book(); + + $this->asEditor()->get($book->getUrl('/create-page')); + $draft = Page::query()->where('book_id', '=', $book->id) + ->where('draft', '=', true)->first(); + + $details = [ + 'html' => '
ducks
', 'name' => 'my page revision', @@ -130,7 +160,7 @@ class PageTest extends TestCase public function test_page_copy() { - $page = Page::first(); + $page = $this->entities->page(); $page->html = 'This is some test content
'; $page->save(); @@ -153,7 +183,7 @@ class PageTest extends TestCase public function test_page_copy_with_markdown_has_both_html_and_markdown() { - $page = Page::first(); + $page = $this->entities->page(); $page->html = 'Updated content
', + ]); + + $resp = $this->asAdmin()->get('/pages/recently-updated'); + $this->withHtml($resp)->assertElementContains('.entity-list .page:nth-child(1)', $page->chapter->getShortName(42)); + $this->withHtml($resp)->assertElementContains('.entity-list .page:nth-child(1)', $page->book->getShortName(42)); + } + + public function test_recently_updated_pages_view_does_not_show_parent_if_not_visible() + { + $user = $this->users->editor(); + $page = $this->entities->pageWithinChapter(); + + $this->actingAs($user)->put($page->getUrl(), [ + 'name' => 'Updated title', + 'html' => 'Updated content
', + ]); + + $this->permissions->setEntityPermissions($page->book); + $this->permissions->setEntityPermissions($page, ['view'], [$user->roles->first()]); + + $resp = $this->get('/pages/recently-updated'); + $resp->assertDontSee($page->book->getShortName(42)); + $resp->assertDontSee($page->chapter->getShortName(42)); + $this->withHtml($resp)->assertElementContains('.entity-list .page:nth-child(1)', 'Updated title'); } public function test_recently_updated_pages_on_home() @@ -284,15 +345,25 @@ class PageTest extends TestCase 'updated_at' => Carbon::now()->subSecond(1), ]); - $this->asAdmin()->get('/') - ->assertElementNotContains('#recently-updated-pages', $page->name); + $resp = $this->asAdmin()->get('/'); + $this->withHtml($resp)->assertElementNotContains('#recently-updated-pages', $page->name); $this->put($page->getUrl(), [ 'name' => $page->name, 'html' => $page->html, ]); - $this->get('/') - ->assertElementContains('#recently-updated-pages', $page->name); + $resp = $this->get('/'); + $this->withHtml($resp)->assertElementContains('#recently-updated-pages', $page->name); + } + + public function test_page_edit_without_update_permissions_but_with_view_redirects_to_page() + { + $page = $this->entities->page(); + + $resp = $this->asViewer()->get($page->getUrl('/edit')); + $resp->assertRedirect($page->getUrl()); + + $resp->assertSessionHas('error', 'You do not have permission to access the requested page.'); } }