+
+ public function test_old_page_slugs_redirect_to_new_pages()
+ {
+ $page = $this->entities->page();
+
+ // Need to save twice since revisions are not generated in seeder.
+ $this->asAdmin()->put($page->getUrl(), [
+ 'name' => 'super test',
+ 'html' => '<p></p>',
+ ]);
+
+ $page->refresh();
+ $pageUrl = $page->getUrl();
+
+ $this->put($pageUrl, [
+ 'name' => 'super test page',
+ 'html' => '<p></p>',
+ ]);
+
+ $this->get($pageUrl)
+ ->assertRedirect("/books/{$page->book->slug}/page/super-test-page");
+ }
+
+ public function test_page_within_chapter_deletion_returns_to_chapter()
+ {
+ $chapter = $this->entities->chapter();
+ $page = $chapter->pages()->first();
+
+ $this->asEditor()->delete($page->getUrl())
+ ->assertRedirect($chapter->getUrl());
+ }
+
+ public function test_recently_updated_pages_view()
+ {
+ $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);
+ }
+
+ public function test_recently_updated_pages_view_shows_updated_by_details()
+ {
+ $user = $this->users->editor();
+ $page = $this->entities->page();
+
+ $this->actingAs($user)->put($page->getUrl(), [
+ 'name' => 'Updated title',
+ 'html' => '<p>Updated content</p>',
+ ]);
+
+ $resp = $this->asAdmin()->get('/pages/recently-updated');
+ $this->withHtml($resp)->assertElementContains('.entity-list .page:nth-child(1) small', 'by ' . $user->name);
+ }
+
+ public function test_recently_updated_pages_view_shows_parent_chain()
+ {
+ $user = $this->users->editor();
+ $page = $this->entities->pageWithinChapter();
+
+ $this->actingAs($user)->put($page->getUrl(), [
+ 'name' => 'Updated title',
+ 'html' => '<p>Updated content</p>',
+ ]);
+
+ $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' => '<p>Updated content</p>',
+ ]);
+
+ $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()
+ {
+ /** @var Page $page */
+ $page = Page::query()->orderBy('updated_at', 'asc')->first();
+ Page::query()->where('id', '!=', $page->id)->update([
+ 'updated_at' => Carbon::now()->subSecond(1),
+ ]);
+
+ $resp = $this->asAdmin()->get('/');
+ $this->withHtml($resp)->assertElementNotContains('#recently-updated-pages', $page->name);
+
+ $this->put($page->getUrl(), [
+ 'name' => $page->name,
+ 'html' => $page->html,
+ ]);
+
+ $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.');
+ }
+}