+
+ public function test_revision_list_shows_editor_type()
+ {
+ $page = $this->entities->page();
+ $this->createRevisions($page, 1, ['html' => 'new page html']);
+
+ $resp = $this->asAdmin()->get($page->refresh()->getUrl('/revisions'));
+ $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('.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()
+ {
+ $page = $this->entities->page();
+ $this->createRevisions($page, 2);
+
+ $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->permissions->grantUserRolePermissions($viewer, ['page-update-all']);
+
+ $respHtml = $this->withHtml($this->get($page->getUrl('/revisions')));
+ $respHtml->assertElementContains('.actions a', 'Restore');
+ $respHtml->assertElementExists('form[action$="/restore"]');
+ }
+
+ public function test_revision_delete_action_only_visible_with_permission()
+ {
+ $page = $this->entities->page();
+ $this->createRevisions($page, 2);
+
+ $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->permissions->grantUserRolePermissions($viewer, ['page-delete-all']);
+
+ $respHtml = $this->withHtml($this->get($page->getUrl('/revisions')));
+ $respHtml->assertElementContains('.actions a', 'Delete');
+ $respHtml->assertElementExists('form[action$="/delete"]');
+ }
+
+ protected function createRevisions(Page $page, int $times, array $attrs = [])
+ {
+ $user = user();
+
+ for ($i = 0; $i < $times; $i++) {
+ $data = ['name' => 'Page update' . $i, 'summary' => 'Update entry' . $i];
+ if (!isset($attrs['markdown'])) {
+ $data['html'] = '<p>My update page</p>';
+ }
+ $this->asAdmin()->put($page->getUrl(), array_merge($data, $attrs));
+ $page->refresh();
+ }
+
+ $this->actingAs($user);
+ }
+}