first(); $page = Page::factory()->make([ 'name' => 'My First Page', ]); $resp = $this->asEditor()->get($chapter->getUrl()); $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()); $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(); $user = $this->getViewer(); $owner = $this->getEditor(); $page->created_by = $user->id; $page->owned_by = $owner->id; $page->save(); $user->delete(); $resp = $this->asAdmin()->get($page->getUrl()); $resp->assertStatus(200); $resp->assertSeeText('Owned by ' . $owner->name); } public function test_page_creation_with_markdown_content() { $this->setSettings(['app-editor' => 'markdown']); $book = Book::query()->first(); $this->asEditor()->get($book->getUrl('/create-page')); $draft = Page::query()->where('book_id', '=', $book->id) ->where('draft', '=', true)->first(); $details = [ 'markdown' => '# a title', 'html' => '
ducks
', 'name' => 'my page revision', 'type' => 'draft', ]); $page->revisions()->create([ 'html' => 'ducks
', 'name' => 'my page revision', 'type' => 'revision', ]); $this->assertDatabaseHas('page_revisions', [ 'page_id' => $page->id, ]); $this->asEditor()->delete($page->getUrl()); $this->asAdmin()->post('/settings/recycle-bin/empty'); $this->assertDatabaseMissing('page_revisions', [ 'page_id' => $page->id, ]); } public function test_page_copy() { $page = Page::first(); $page->html = 'This is some test content
'; $page->save(); $currentBook = $page->book; $newBook = Book::where('id', '!=', $currentBook->id)->first(); $resp = $this->asEditor()->get($page->getUrl('/copy')); $resp->assertSee('Copy Page'); $movePageResp = $this->post($page->getUrl('/copy'), [ 'entity_selection' => 'book:' . $newBook->id, 'name' => 'My copied test page', ]); $pageCopy = Page::where('name', '=', 'My copied test page')->first(); $movePageResp->assertRedirect($pageCopy->getUrl()); $this->assertTrue($pageCopy->book->id == $newBook->id, 'Page was copied to correct book'); $this->assertStringContainsString('This is some test content', $pageCopy->html); } public function test_page_copy_with_markdown_has_both_html_and_markdown() { $page = Page::first(); $page->html = 'Updated content
', ]); $resp = $this->asAdmin()->get('/pages/recently-updated'); $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(); /** @var Page $page */ $page = Page::query()->whereNotNull('chapter_id')->first(); $this->actingAs($user)->put($page->getUrl(), [ 'name' => 'Updated title', 'html' => 'Updated content
', ]); $resp = $this->asAdmin()->get('/pages/recently-updated'); $resp->assertElementContains('.entity-list .page:nth-child(1)', $page->chapter->getShortName(42)); $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(); /** @var Page $page */ $page = Page::query()->whereNotNull('chapter_id')->first(); $this->actingAs($user)->put($page->getUrl(), [ 'name' => 'Updated title', 'html' => 'Updated content
', ]); $this->setEntityRestrictions($page->book); $this->setEntityRestrictions($page, ['view'], [$user->roles->first()]); $resp = $this->get('/pages/recently-updated'); $resp->assertDontSee($page->book->getShortName(42)); $resp->assertDontSee($page->chapter->getShortName(42)); $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), ]); $this->asAdmin()->get('/') ->assertElementNotContains('#recently-updated-pages', $page->name); $this->put($page->getUrl(), [ 'name' => $page->name, 'html' => $page->html, ]); $this->get('/') ->assertElementContains('#recently-updated-pages', $page->name); } }