X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/de8cceb0f72f19ed0b3aa43d7a139639fa634bd2..refs/pull/3918/head:/tests/Entity/PageTest.php diff --git a/tests/Entity/PageTest.php b/tests/Entity/PageTest.php index 3fb847e42..f481ffb61 100644 --- a/tests/Entity/PageTest.php +++ b/tests/Entity/PageTest.php @@ -3,16 +3,41 @@ namespace Tests\Entity; use BookStack\Entities\Models\Book; -use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; use Carbon\Carbon; use Tests\TestCase; class PageTest extends TestCase { + public function test_create() + { + $chapter = $this->entities->chapter(); + $page = Page::factory()->make([ + 'name' => 'My First Page', + ]); + + $resp = $this->asEditor()->get($chapter->getUrl()); + $this->withHtml($resp)->assertElementContains('a[href="' . $chapter->getUrl('/create-page') . '"]', 'New Page'); + + $resp = $this->get($chapter->getUrl('/create-page')); + /** @var Page $draftPage */ + $draftPage = Page::query() + ->where('draft', '=', true) + ->orderBy('created_at', 'desc') + ->first(); + $resp->assertRedirect($draftPage->getUrl()); + + $resp = $this->get($draftPage->getUrl()); + $this->withHtml($resp)->assertElementContains('form[action="' . $draftPage->getUrl() . '"][method="POST"]', 'Save Page'); + + $resp = $this->post($draftPage->getUrl(), $draftPage->only('name', 'html')); + $draftPage->refresh(); + $resp->assertRedirect($draftPage->getUrl()); + } + public function test_page_view_when_creator_is_deleted_but_owner_exists() { - $page = Page::query()->first(); + $page = $this->entities->page(); $user = $this->getViewer(); $owner = $this->getEditor(); $page->created_by = $user->id; @@ -28,7 +53,7 @@ class PageTest extends TestCase 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) @@ -56,7 +81,7 @@ class PageTest extends TestCase public function test_page_delete() { - $page = Page::query()->first(); + $page = $this->entities->page(); $this->assertNull($page->deleted_at); $deleteViewReq = $this->asEditor()->get($page->getUrl('/delete')); @@ -71,13 +96,12 @@ class PageTest extends TestCase $this->assertTrue($page->deletions()->count() === 1); $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location')); - $redirectReq->assertNotificationContains('Page Successfully Deleted'); + $this->assertNotificationContains($redirectReq, 'Page Successfully Deleted'); } public function test_page_full_delete_removes_all_revisions() { - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $page->revisions()->create([ 'html' => '
ducks
', 'name' => 'my page revision', @@ -103,7 +127,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(); @@ -126,7 +150,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
', + ]); - $this->asAdmin()->get('/pages/recently-updated') - ->assertElementContains('.entity-list .page:nth-child(1)', $content['page']->name); + $resp = $this->asAdmin()->get('/pages/recently-updated'); + $this->withHtml($resp)->assertElementContains('.entity-list .page:nth-child(1)', 'Updated 1 second ago by ' . $user->name); + } + + public function test_recently_updated_pages_view_shows_parent_chain() + { + $user = $this->getEditor(); + $page = $this->entities->pageWithinChapter(); + + $this->actingAs($user)->put($page->getUrl(), [ + 'name' => 'Updated title', + '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->getEditor(); + $page = $this->entities->pageWithinChapter(); + + $this->actingAs($user)->put($page->getUrl(), [ + 'name' => 'Updated title', + 'html' => 'Updated content
', + ]); + + $this->entities->setPermissions($page->book); + $this->entities->setPermissions($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() @@ -242,16 +312,15 @@ 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); } - }