]> BookStack Code Mirror - bookstack/blob - tests/Entity/PageUpdateDraftTest.php
d321974db084a37531e7a5591e6021e1639ca166
[bookstack] / tests / Entity / PageUpdateDraftTest.php
1 <?php
2
3
4 class PageUpdateDraftTest extends TestCase
5 {
6     protected $page;
7     protected $pageRepo;
8
9     public function setUp()
10     {
11         parent::setUp();
12         $this->page = \BookStack\Page::first();
13         $this->pageRepo = app('\BookStack\Repos\PageRepo');
14     }
15
16     public function test_draft_content_shows_if_available()
17     {
18         $addedContent = '<p>test message content</p>';
19         $this->asAdmin()->visit($this->page->getUrl() . '/edit')
20             ->dontSeeInField('html', $addedContent);
21
22         $newContent = $this->page->html . $addedContent;
23         $this->pageRepo->saveUpdateDraft($this->page, ['html' => $newContent]);
24         $this->asAdmin()->visit($this->page->getUrl() . '/edit')
25             ->seeInField('html', $newContent);
26     }
27
28     public function test_draft_not_visible_by_others()
29     {
30         $addedContent = '<p>test message content</p>';
31         $this->asAdmin()->visit($this->page->getUrl() . '/edit')
32             ->dontSeeInField('html', $addedContent);
33
34         $newContent = $this->page->html . $addedContent;
35         $newUser = $this->getNewUser();
36         $this->pageRepo->saveUpdateDraft($this->page, ['html' => $newContent]);
37         $this->actingAs($newUser)->visit($this->page->getUrl() . '/edit')
38             ->dontSeeInField('html', $newContent);
39     }
40
41     public function test_alert_message_shows_if_editing_draft()
42     {
43         $this->asAdmin();
44         $this->pageRepo->saveUpdateDraft($this->page, ['html' => 'test content']);
45         $this->asAdmin()->visit($this->page->getUrl() . '/edit')
46             ->see('You are currently editing a draft');
47     }
48
49     public function test_alert_message_shows_if_someone_else_editing()
50     {
51         $addedContent = '<p>test message content</p>';
52         $this->asAdmin()->visit($this->page->getUrl() . '/edit')
53             ->dontSeeInField('html', $addedContent);
54
55         $newContent = $this->page->html . $addedContent;
56         $newUser = $this->getNewUser();
57         $this->pageRepo->saveUpdateDraft($this->page, ['html' => $newContent]);
58         $this->actingAs($newUser)->visit($this->page->getUrl() . '/edit')
59             ->see('Admin has started editing this page');
60     }
61
62 }