X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/756b55bbffedb6e5fde91f9fbc61f5a382f20705..refs/pull/3032/head:/tests/Entity/PageDraftTest.php diff --git a/tests/Entity/PageDraftTest.php b/tests/Entity/PageDraftTest.php index b2fa4bb31..4fb7d7ab6 100644 --- a/tests/Entity/PageDraftTest.php +++ b/tests/Entity/PageDraftTest.php @@ -4,6 +4,7 @@ namespace Tests\Entity; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Page; +use BookStack\Entities\Models\PageRevision; use BookStack\Entities\Repos\PageRepo; use Tests\TestCase; @@ -80,6 +81,63 @@ class PageDraftTest extends TestCase ->assertElementNotContains('.notification', 'Admin has started editing this page'); } + public function test_draft_save_shows_alert_if_draft_older_than_last_page_update() + { + $admin = $this->getAdmin(); + $editor = $this->getEditor(); + /** @var Page $page */ + $page = Page::query()->first(); + + $this->actingAs($editor)->put('/ajax/page/' . $page->id . '/save-draft', [ + 'name' => $page->name, + 'html' => '

updated draft

', + ]); + + /** @var PageRevision $draft */ + $draft = $page->allRevisions() + ->where('type', '=', 'update_draft') + ->where('created_by', '=', $editor->id) + ->first(); + $draft->created_at = now()->subMinute(1); + $draft->save(); + + $this->actingAs($admin)->put($page->refresh()->getUrl(), [ + 'name' => $page->name, + 'html' => '

admin update

', + ]); + + $resp = $this->actingAs($editor)->put('/ajax/page/' . $page->id . '/save-draft', [ + 'name' => $page->name, + 'html' => '

updated draft again

', + ]); + + $resp->assertJson([ + 'warning' => 'This page has been updated since this draft was created. It is recommended that you discard this draft or take care not to overwrite any page changes.', + ]); + } + + public function test_draft_save_shows_alert_if_draft_edit_started_by_someone_else() + { + $admin = $this->getAdmin(); + $editor = $this->getEditor(); + /** @var Page $page */ + $page = Page::query()->first(); + + $this->actingAs($admin)->put('/ajax/page/' . $page->id . '/save-draft', [ + 'name' => $page->name, + 'html' => '

updated draft

', + ]); + + $resp = $this->actingAs($editor)->put('/ajax/page/' . $page->id . '/save-draft', [ + 'name' => $page->name, + 'html' => '

updated draft again

', + ]); + + $resp->assertJson([ + 'warning' => 'Admin has started editing this page in the last 60 minutes. Take care not to overwrite each other\'s updates!', + ]); + } + public function test_draft_pages_show_on_homepage() { /** @var Book $book */