2017-02-04 19:58:42 +08:00
|
|
|
<?php namespace Tests;
|
2016-03-13 00:31:02 +08:00
|
|
|
|
|
|
|
|
2017-01-26 03:35:40 +08:00
|
|
|
class PageDraftTest extends BrowserKitTest
|
2016-03-13 00:31:02 +08:00
|
|
|
{
|
|
|
|
protected $page;
|
2017-01-02 19:07:27 +08:00
|
|
|
protected $entityRepo;
|
2016-03-13 00:31:02 +08:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->page = \BookStack\Page::first();
|
2017-01-02 19:07:27 +08:00
|
|
|
$this->entityRepo = app('\BookStack\Repos\EntityRepo');
|
2016-03-13 00:31:02 +08: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;
|
2017-01-02 19:07:27 +08:00
|
|
|
$this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
2016-03-13 00:31:02 +08: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 21:29:43 +08:00
|
|
|
$newUser = $this->getEditor();
|
2017-01-02 19:07:27 +08:00
|
|
|
$this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
2016-03-13 00:31:02 +08:00
|
|
|
$this->actingAs($newUser)->visit($this->page->getUrl() . '/edit')
|
|
|
|
->dontSeeInField('html', $newContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_alert_message_shows_if_editing_draft()
|
|
|
|
{
|
|
|
|
$this->asAdmin();
|
2017-01-02 19:07:27 +08:00
|
|
|
$this->entityRepo->updatePageDraft($this->page, ['html' => 'test content']);
|
2016-03-13 00:31:02 +08: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()
|
|
|
|
{
|
2016-03-13 22:33:43 +08:00
|
|
|
$nonEditedPage = \BookStack\Page::take(10)->get()->last();
|
2016-03-13 00:31:02 +08: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 21:29:43 +08:00
|
|
|
$newUser = $this->getEditor();
|
2017-01-02 19:07:27 +08:00
|
|
|
$this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
2016-03-13 22:33:43 +08:00
|
|
|
|
|
|
|
$this->actingAs($newUser)
|
|
|
|
->visit($this->page->getUrl() . '/edit')
|
2016-03-13 00:31:02 +08:00
|
|
|
->see('Admin has started editing this page');
|
2016-03-13 22:33:43 +08:00
|
|
|
$this->flushSession();
|
|
|
|
$this->visit($nonEditedPage->getUrl() . '/edit')
|
|
|
|
->dontSeeInElement('.notification', 'Admin has started editing this page');
|
2016-03-13 00:31:02 +08:00
|
|
|
}
|
|
|
|
|
2016-03-13 20:04:08 +08:00
|
|
|
public function test_draft_pages_show_on_homepage()
|
|
|
|
{
|
|
|
|
$book = \BookStack\Book::first();
|
|
|
|
$this->asAdmin()->visit('/')
|
|
|
|
->dontSeeInElement('#recent-drafts', 'New Page')
|
2018-03-25 18:34:42 +08:00
|
|
|
->visit($book->getUrl() . '/create-page')
|
2016-03-13 20:04:08 +08:00
|
|
|
->visit('/')
|
|
|
|
->seeInElement('#recent-drafts', 'New Page');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_draft_pages_not_visible_by_others()
|
|
|
|
{
|
|
|
|
$book = \BookStack\Book::first();
|
|
|
|
$chapter = $book->chapters->first();
|
2016-05-07 21:29:43 +08:00
|
|
|
$newUser = $this->getEditor();
|
2016-03-13 20:04:08 +08:00
|
|
|
|
|
|
|
$this->actingAs($newUser)->visit('/')
|
2018-03-25 18:34:42 +08:00
|
|
|
->visit($book->getUrl() . '/create-page')
|
2016-03-13 20:04:08 +08:00
|
|
|
->visit($chapter->getUrl() . '/create-page')
|
|
|
|
->visit($book->getUrl())
|
|
|
|
->seeInElement('.page-list', 'New Page');
|
2016-09-18 01:22:04 +08:00
|
|
|
|
2016-03-13 20:04:08 +08:00
|
|
|
$this->asAdmin()
|
|
|
|
->visit($book->getUrl())
|
|
|
|
->dontSeeInElement('.page-list', 'New Page')
|
|
|
|
->visit($chapter->getUrl())
|
|
|
|
->dontSeeInElement('.page-list', 'New Page');
|
|
|
|
}
|
|
|
|
|
2016-03-13 00:31:02 +08:00
|
|
|
}
|