]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/PageTest.php
respective book and chapter structure added.
[bookstack] / tests / Entity / PageTest.php
index 734516e872271ed6a6f22bf33377fe1ffcc41a42..b96d455eb253cec53e09c5a13ad5eca89fd53e07 100644 (file)
@@ -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,8 +11,7 @@ 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',
         ]);
@@ -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'    => '<h1>a title</h1>',
+            'name'    => 'My page with summary',
+            'summary' => 'Here is my changelog message for a new page!',
+        ];
+        $resp = $this->post($book->getUrl("/draft/{$draft->id}"), $details);
+        $resp->assertRedirect();
+
+        $this->assertDatabaseHas('page_revisions', [
+            'page_id' => $draft->id,
+            'summary' => 'Here is my changelog message for a new page!',
+        ]);
+
+        $draft->refresh();
+        $resp = $this->get($draft->getUrl('/revisions'));
+        $resp->assertSee('Here is my changelog message for a new page!');
+    }
+
     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'));
@@ -103,8 +134,7 @@ class PageTest extends TestCase
 
     public function test_page_full_delete_removes_all_revisions()
     {
-        /** @var Page $page */
-        $page = Page::query()->first();
+        $page = $this->entities->page();
         $page->revisions()->create([
             'html' => '<p>ducks</p>',
             '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 = '<p>This is some test content</p>';
         $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 = '<h1>This is some test content</h1>';
         $page->markdown = '# This is some test content';
         $page->save();
@@ -171,7 +201,7 @@ class PageTest extends TestCase
 
     public function test_page_copy_with_no_destination()
     {
-        $page = Page::first();
+        $page = $this->entities->page();
         $currentBook = $page->book;
 
         $resp = $this->asEditor()->get($page->getUrl('/copy'));
@@ -190,18 +220,18 @@ class PageTest extends TestCase
 
     public function test_page_can_be_copied_without_edit_permission()
     {
-        $page = Page::first();
+        $page = $this->entities->page();
         $currentBook = $page->book;
         $newBook = Book::where('id', '!=', $currentBook->id)->first();
-        $viewer = $this->getViewer();
+        $viewer = $this->users->viewer();
 
         $resp = $this->actingAs($viewer)->get($page->getUrl());
         $resp->assertDontSee($page->getUrl('/copy'));
 
         $newBook->owned_by = $viewer->id;
         $newBook->save();
-        $this->giveUserPermissions($viewer, ['page-create-own']);
-        $this->regenEntityPermissions($newBook);
+        $this->permissions->grantUserRolePermissions($viewer, ['page-create-own']);
+        $this->permissions->regenerateForEntity($newBook);
 
         $resp = $this->actingAs($viewer)->get($page->getUrl());
         $resp->assertSee($page->getUrl('/copy'));
@@ -221,8 +251,7 @@ class PageTest extends TestCase
 
     public function test_old_page_slugs_redirect_to_new_pages()
     {
-        /** @var Page $page */
-        $page = Page::query()->first();
+        $page = $this->entities->page();
 
         // Need to save twice since revisions are not generated in seeder.
         $this->asAdmin()->put($page->getUrl(), [
@@ -244,8 +273,7 @@ class PageTest extends TestCase
 
     public function test_page_within_chapter_deletion_returns_to_chapter()
     {
-        /** @var Chapter $chapter */
-        $chapter = Chapter::query()->first();
+        $chapter = $this->entities->chapter();
         $page = $chapter->pages()->first();
 
         $this->asEditor()->delete($page->getUrl())
@@ -254,8 +282,8 @@ class PageTest extends TestCase
 
     public function test_recently_updated_pages_view()
     {
-        $user = $this->getEditor();
-        $content = $this->createEntityChainBelongingToUser($user);
+        $user = $this->users->editor();
+        $content = $this->entities->createChainBelongingToUser($user);
 
         $resp = $this->asAdmin()->get('/pages/recently-updated');
         $this->withHtml($resp)->assertElementContains('.entity-list .page:nth-child(1)', $content['page']->name);
@@ -263,9 +291,8 @@ class PageTest extends TestCase
 
     public function test_recently_updated_pages_view_shows_updated_by_details()
     {
-        $user = $this->getEditor();
-        /** @var Page $page */
-        $page = Page::query()->first();
+        $user = $this->users->editor();
+        $page = $this->entities->page();
 
         $this->actingAs($user)->put($page->getUrl(), [
             'name' => 'Updated title',
@@ -278,9 +305,8 @@ class PageTest extends TestCase
 
     public function test_recently_updated_pages_view_shows_parent_chain()
     {
-        $user = $this->getEditor();
-        /** @var Page $page */
-        $page = Page::query()->whereNotNull('chapter_id')->first();
+        $user = $this->users->editor();
+        $page = $this->entities->pageWithinChapter();
 
         $this->actingAs($user)->put($page->getUrl(), [
             'name' => 'Updated title',
@@ -294,17 +320,16 @@ class PageTest extends TestCase
 
     public function test_recently_updated_pages_view_does_not_show_parent_if_not_visible()
     {
-        $user = $this->getEditor();
-        /** @var Page $page */
-        $page = Page::query()->whereNotNull('chapter_id')->first();
+        $user = $this->users->editor();
+        $page = $this->entities->pageWithinChapter();
 
         $this->actingAs($user)->put($page->getUrl(), [
             'name' => 'Updated title',
             'html' => '<p>Updated content</p>',
         ]);
 
-        $this->setEntityRestrictions($page->book);
-        $this->setEntityRestrictions($page, ['view'], [$user->roles->first()]);
+        $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));