2021-06-26 23:23:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<?php
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								namespace Tests\Entity;
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-22 08:17:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use BookStack\Entities\Models\Page;
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-13 18:27:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use BookStack\Entities\Repos\PageRepo;
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-04 08:16:05 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use Tests\BrowserKitTest;
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-13 18:27:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 03:35:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								class PageDraftTest extends BrowserKitTest
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    protected $page;
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-05 19:55:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     * @var PageRepo
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     */
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-13 18:27:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    protected $pageRepo;
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-14 06:58:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    public function setUp(): void
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        parent::setUp();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-22 08:17:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->page = \BookStack\Entities\Models\Page::first();
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-13 18:27:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->pageRepo = app(PageRepo::class);
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public function test_draft_content_shows_if_available()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $addedContent = '<p>test message content</p>';
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-20 07:18:28 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        $this->asAdmin()->visit($this->page->getUrl('/edit'))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->dontSeeInField('html', $addedContent);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $newContent = $this->page->html . $addedContent;
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-13 18:27:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-20 07:18:28 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->asAdmin()->visit($this->page->getUrl('/edit'))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->seeInField('html', $newContent);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public function test_draft_not_visible_by_others()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $addedContent = '<p>test message content</p>';
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-20 07:18:28 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->asAdmin()->visit($this->page->getUrl('/edit'))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->dontSeeInField('html', $addedContent);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $newContent = $this->page->html . $addedContent;
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-07 21:29:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        $newUser = $this->getEditor();
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-13 18:27:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-20 07:18:28 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->actingAs($newUser)->visit($this->page->getUrl('/edit'))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->dontSeeInField('html', $newContent);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public function test_alert_message_shows_if_editing_draft()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->asAdmin();
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-13 18:27:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->pageRepo->updatePageDraft($this->page, ['html' => 'test content']);
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-20 07:18:28 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->asAdmin()->visit($this->page->getUrl('/edit'))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->see('You are currently editing a draft');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    public function test_alert_message_shows_if_someone_else_editing()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-22 08:17:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $nonEditedPage = \BookStack\Entities\Models\Page::take(10)->get()->last();
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $addedContent = '<p>test message content</p>';
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-20 07:18:28 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->asAdmin()->visit($this->page->getUrl('/edit'))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->dontSeeInField('html', $addedContent);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $newContent = $this->page->html . $addedContent;
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-07 21:29:43 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $newUser = $this->getEditor();
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-13 18:27:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 22:33:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->actingAs($newUser)
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-20 07:18:28 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->visit($this->page->getUrl('/edit'))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->see('Admin has started editing this page');
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->flushSession();
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 22:33:43 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $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()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-22 08:17:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $book = \BookStack\Entities\Models\Book::first();
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 20:04:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $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()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-22 08:17:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $book = \BookStack\Entities\Models\Book::first();
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 20:04:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $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('/')
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-05 19:55:01 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->visit($book->getUrl('/create-page'))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->visit($chapter->getUrl('/create-page'))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 20:04:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->visit($book->getUrl())
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-07 01:36:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            ->seeInElement('.book-contents', 'New Page');
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-05 19:55:01 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 20:04:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->asAdmin()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->visit($book->getUrl())
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-07 01:36:17 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->dontSeeInElement('.book-contents', 'New Page')
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 20:04:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->visit($chapter->getUrl())
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-07 01:36:17 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ->dontSeeInElement('.book-contents', 'New Page');
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 20:04:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 04:18:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    public function test_page_html_in_ajax_fetch_response()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->asAdmin();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $page = Page::query()->first();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->getJson('/ajax/page/' . $page->id);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        $this->seeJson([
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            'html' => $page->html,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-13 00:31:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |