2017-02-04 06:58:42 -05:00
|
|
|
<?php namespace Tests;
|
2016-03-12 11:31:02 -05:00
|
|
|
|
|
|
|
|
2018-10-13 06:27:55 -04:00
|
|
|
use BookStack\Entities\Repos\PageRepo;
|
|
|
|
|
2017-01-25 14:35:40 -05:00
|
|
|
class PageDraftTest extends BrowserKitTest
|
2016-03-12 11:31:02 -05:00
|
|
|
{
|
|
|
|
protected $page;
|
2018-10-13 06:27:55 -04:00
|
|
|
protected $pageRepo;
|
2016-03-12 11:31:02 -05:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2018-09-25 07:30:50 -04:00
|
|
|
$this->page = \BookStack\Entities\Page::first();
|
2018-10-13 06:27:55 -04:00
|
|
|
$this->pageRepo = app(PageRepo::class);
|
2016-03-12 11:31:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_draft_content_shows_if_available()
|
|
|
|
{
|
|
|
|
$addedContent = '<p>test message content</p>';
|
|
|
|
$this->asAdmin()->visit($this->page->getUrl() . '/edit')
|
|
|
|
->dontSeeInField('html', $addedContent);
|
|
|
|
|
|
|
|
$newContent = $this->page->html . $addedContent;
|
2018-10-13 06:27:55 -04:00
|
|
|
$this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
2016-03-12 11:31:02 -05:00
|
|
|
$this->asAdmin()->visit($this->page->getUrl() . '/edit')
|
|
|
|
->seeInField('html', $newContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_draft_not_visible_by_others()
|
|
|
|
{
|
|
|
|
$addedContent = '<p>test message content</p>';
|
|
|
|
$this->asAdmin()->visit($this->page->getUrl() . '/edit')
|
|
|
|
->dontSeeInField('html', $addedContent);
|
|
|
|
|
|
|
|
$newContent = $this->page->html . $addedContent;
|
2016-05-07 09:29:43 -04:00
|
|
|
$newUser = $this->getEditor();
|
2018-10-13 06:27:55 -04:00
|
|
|
$this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
2016-03-12 11:31:02 -05:00
|
|
|
$this->actingAs($newUser)->visit($this->page->getUrl() . '/edit')
|
|
|
|
->dontSeeInField('html', $newContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_alert_message_shows_if_editing_draft()
|
|
|
|
{
|
|
|
|
$this->asAdmin();
|
2018-10-13 06:27:55 -04:00
|
|
|
$this->pageRepo->updatePageDraft($this->page, ['html' => 'test content']);
|
2016-03-12 11:31:02 -05:00
|
|
|
$this->asAdmin()->visit($this->page->getUrl() . '/edit')
|
|
|
|
->see('You are currently editing a draft');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_alert_message_shows_if_someone_else_editing()
|
|
|
|
{
|
2018-09-25 07:30:50 -04:00
|
|
|
$nonEditedPage = \BookStack\Entities\Page::take(10)->get()->last();
|
2016-03-12 11:31:02 -05:00
|
|
|
$addedContent = '<p>test message content</p>';
|
|
|
|
$this->asAdmin()->visit($this->page->getUrl() . '/edit')
|
|
|
|
->dontSeeInField('html', $addedContent);
|
|
|
|
|
|
|
|
$newContent = $this->page->html . $addedContent;
|
2016-05-07 09:29:43 -04:00
|
|
|
$newUser = $this->getEditor();
|
2018-10-13 06:27:55 -04:00
|
|
|
$this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
2016-03-13 10:33:43 -04:00
|
|
|
|
|
|
|
$this->actingAs($newUser)
|
|
|
|
->visit($this->page->getUrl() . '/edit')
|
2016-03-12 11:31:02 -05:00
|
|
|
->see('Admin has started editing this page');
|
2016-03-13 10:33:43 -04:00
|
|
|
$this->flushSession();
|
|
|
|
$this->visit($nonEditedPage->getUrl() . '/edit')
|
|
|
|
->dontSeeInElement('.notification', 'Admin has started editing this page');
|
2016-03-12 11:31:02 -05:00
|
|
|
}
|
|
|
|
|
2016-03-13 08:04:08 -04:00
|
|
|
public function test_draft_pages_show_on_homepage()
|
|
|
|
{
|
2018-09-25 07:30:50 -04:00
|
|
|
$book = \BookStack\Entities\Book::first();
|
2016-03-13 08:04:08 -04:00
|
|
|
$this->asAdmin()->visit('/')
|
|
|
|
->dontSeeInElement('#recent-drafts', 'New Page')
|
2018-03-25 06:34:42 -04:00
|
|
|
->visit($book->getUrl() . '/create-page')
|
2016-03-13 08:04:08 -04:00
|
|
|
->visit('/')
|
|
|
|
->seeInElement('#recent-drafts', 'New Page');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_draft_pages_not_visible_by_others()
|
|
|
|
{
|
2018-09-25 07:30:50 -04:00
|
|
|
$book = \BookStack\Entities\Book::first();
|
2016-03-13 08:04:08 -04:00
|
|
|
$chapter = $book->chapters->first();
|
2016-05-07 09:29:43 -04:00
|
|
|
$newUser = $this->getEditor();
|
2016-03-13 08:04:08 -04:00
|
|
|
|
|
|
|
$this->actingAs($newUser)->visit('/')
|
2018-03-25 06:34:42 -04:00
|
|
|
->visit($book->getUrl() . '/create-page')
|
2016-03-13 08:04:08 -04:00
|
|
|
->visit($chapter->getUrl() . '/create-page')
|
|
|
|
->visit($book->getUrl())
|
2019-04-06 13:36:17 -04:00
|
|
|
->seeInElement('.book-contents', 'New Page');
|
2016-09-17 13:22:04 -04:00
|
|
|
|
2016-03-13 08:04:08 -04:00
|
|
|
$this->asAdmin()
|
|
|
|
->visit($book->getUrl())
|
2019-04-06 13:36:17 -04:00
|
|
|
->dontSeeInElement('.book-contents', 'New Page')
|
2016-03-13 08:04:08 -04:00
|
|
|
->visit($chapter->getUrl())
|
2019-04-06 13:36:17 -04:00
|
|
|
->dontSeeInElement('.book-contents', 'New Page');
|
2016-03-13 08:04:08 -04:00
|
|
|
}
|
|
|
|
|
2016-03-12 11:31:02 -05:00
|
|
|
}
|