X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1ac1cf0c786b783a17bcc60828e42ca13a683c11..refs/pull/5689/head:/tests/Entity/PageRevisionTest.php diff --git a/tests/Entity/PageRevisionTest.php b/tests/Entity/PageRevisionTest.php index 05c86c97d..9040254f7 100644 --- a/tests/Entity/PageRevisionTest.php +++ b/tests/Entity/PageRevisionTest.php @@ -2,7 +2,7 @@ namespace Tests\Entity; -use BookStack\Actions\ActivityType; +use BookStack\Activity\ActivityType; use BookStack\Entities\Models\Page; use Tests\TestCase; @@ -10,8 +10,7 @@ class PageRevisionTest extends TestCase { public function test_revision_links_visible_to_viewer() { - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $html = $this->withHtml($this->asViewer()->get($page->getUrl())); $html->assertLinkExists($page->getUrl('/revisions')); @@ -22,7 +21,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_views_viewable() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => '

new content

']); $pageRevision = $page->revisions->last(); @@ -38,7 +37,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_preview_shows_content_of_revision() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => '

new revision content

']); $pageRevision = $page->revisions->last(); $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => '

Updated content

']); @@ -51,7 +50,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_restore_updates_content() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'html' => '

new contente def456

']); $this->createRevisions($page, 1, ['name' => 'updated page again', 'html' => '

new content

']); $page = Page::find($page->id); @@ -75,7 +74,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_restore_with_markdown_retains_markdown_content() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'markdown' => '## New Content def456']); $this->createRevisions($page, 1, ['name' => 'updated page again', 'markdown' => '## New Content Updated']); $page = Page::find($page->id); @@ -103,7 +102,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_restore_sets_new_revision_with_summary() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'html' => '

new contente def456

', 'summary' => 'My first update']); $this->createRevisions($page, 1, ['html' => '

new content

']); $page->refresh(); @@ -125,7 +124,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_count_increments_on_update() { - $page = Page::first(); + $page = $this->entities->page(); $startCount = $page->revision_count; $this->createRevisions($page, 1); @@ -134,17 +133,16 @@ class PageRevisionTest extends TestCase public function test_revision_count_shown_in_page_meta() { - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 2); - $pageView = $this->get($page->getUrl()); + $pageView = $this->asViewer()->get($page->getUrl()); $pageView->assertSee('Revision #' . $page->revision_count); } public function test_revision_deletion() { - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $this->createRevisions($page, 2); $beforeRevisionCount = $page->revisions->count(); @@ -174,7 +172,7 @@ class PageRevisionTest extends TestCase public function test_revision_limit_enforced() { config()->set('app.revision_limit', 2); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 12); $revisionCount = $page->revisions()->count(); @@ -184,7 +182,7 @@ class PageRevisionTest extends TestCase public function test_false_revision_limit_allows_many_revisions() { config()->set('app.revision_limit', false); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 12); $revisionCount = $page->revisions()->count(); @@ -193,32 +191,42 @@ class PageRevisionTest extends TestCase public function test_revision_list_shows_editor_type() { - /** @var Page $page */ - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['html' => 'new page html']); $resp = $this->asAdmin()->get($page->refresh()->getUrl('/revisions')); - $this->withHtml($resp)->assertElementContains('td', '(WYSIWYG)'); - $this->withHtml($resp)->assertElementNotContains('td', '(Markdown)'); + $this->withHtml($resp)->assertElementContains('.item-list-row > div:nth-child(2)', 'WYSIWYG)'); + $this->withHtml($resp)->assertElementNotContains('.item-list-row > div:nth-child(2)', 'Markdown)'); $this->createRevisions($page, 1, ['markdown' => '# Some markdown content']); $resp = $this->get($page->refresh()->getUrl('/revisions')); - $this->withHtml($resp)->assertElementContains('td', '(Markdown)'); + $this->withHtml($resp)->assertElementContains('.item-list-row > div:nth-child(2)', 'Markdown)'); + } + + public function test_revision_changes_link_not_shown_for_oldest_revision() + { + $page = $this->entities->page(); + $this->createRevisions($page, 3, ['html' => 'new page html']); + + $resp = $this->asAdmin()->get($page->refresh()->getUrl('/revisions')); + $html = $this->withHtml($resp); + + $html->assertElementNotExists('.item-list > .item-list-row:last-child a[href*="/changes"]'); + $html->assertElementContains('.item-list > .item-list-row:nth-child(2)', 'Changes'); } public function test_revision_restore_action_only_visible_with_permission() { - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $this->createRevisions($page, 2); - $viewer = $this->getViewer(); + $viewer = $this->users->viewer(); $this->actingAs($viewer); $respHtml = $this->withHtml($this->get($page->getUrl('/revisions'))); $respHtml->assertElementNotContains('.actions a', 'Restore'); $respHtml->assertElementNotExists('form[action$="/restore"]'); - $this->giveUserPermissions($viewer, ['page-update-all']); + $this->permissions->grantUserRolePermissions($viewer, ['page-update-all']); $respHtml = $this->withHtml($this->get($page->getUrl('/revisions'))); $respHtml->assertElementContains('.actions a', 'Restore'); @@ -227,17 +235,16 @@ class PageRevisionTest extends TestCase public function test_revision_delete_action_only_visible_with_permission() { - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $this->createRevisions($page, 2); - $viewer = $this->getViewer(); + $viewer = $this->users->viewer(); $this->actingAs($viewer); $respHtml = $this->withHtml($this->get($page->getUrl('/revisions'))); $respHtml->assertElementNotContains('.actions a', 'Delete'); $respHtml->assertElementNotExists('form[action$="/delete"]'); - $this->giveUserPermissions($viewer, ['page-delete-all']); + $this->permissions->grantUserRolePermissions($viewer, ['page-delete-all']); $respHtml = $this->withHtml($this->get($page->getUrl('/revisions'))); $respHtml->assertElementContains('.actions a', 'Delete');