X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/f139cded789908efce3ac2ed1be26b947df647db..refs/pull/3365/head:/tests/Entity/PageEditorTest.php diff --git a/tests/Entity/PageEditorTest.php b/tests/Entity/PageEditorTest.php index 652bc1336..c06aa5bf1 100644 --- a/tests/Entity/PageEditorTest.php +++ b/tests/Entity/PageEditorTest.php @@ -3,6 +3,7 @@ namespace Tests\Entity; use BookStack\Entities\Models\Book; +use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; use Tests\TestCase; @@ -74,4 +75,31 @@ class PageEditorTest extends TestCase 'draft' => false, ]); } + + public function test_back_link_in_editor_has_correct_url() + { + /** @var Book $book */ + $book = Book::query()->whereHas('pages')->whereHas('chapters')->firstOrFail(); + $this->asEditor()->get($book->getUrl('/create-page')); + /** @var Chapter $chapter */ + $chapter = $book->chapters()->firstOrFail(); + /** @var Page $draft */ + $draft = $book->pages()->where('draft', '=', true)->firstOrFail(); + + // Book draft goes back to book + $resp = $this->get($book->getUrl("/draft/{$draft->id}")); + $resp->assertElementContains('a[href="' . $book->getUrl() . '"]', 'Back'); + + // Chapter draft goes back to chapter + $draft->chapter_id = $chapter->id; + $draft->save(); + $resp = $this->get($book->getUrl("/draft/{$draft->id}")); + $resp->assertElementContains('a[href="' . $chapter->getUrl() . '"]', 'Back'); + + // Saved page goes back to page + $this->post($book->getUrl("/draft/{$draft->id}"), ['name' => 'Updated', 'html' => 'Updated']); + $draft->refresh(); + $resp = $this->get($draft->getUrl('/edit')); + $resp->assertElementContains('a[href="' . $draft->getUrl() . '"]', 'Back'); + } }