Fixed inaccessible revisions, added regression tests
Fixes #309
Showing
5 changed files
with
68 additions
and
17 deletions
| ... | @@ -369,10 +369,13 @@ class PageController extends Controller | ... | @@ -369,10 +369,13 @@ class PageController extends Controller |
| 369 | public function showRevision($bookSlug, $pageSlug, $revisionId) | 369 | public function showRevision($bookSlug, $pageSlug, $revisionId) |
| 370 | { | 370 | { |
| 371 | $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); | 371 | $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); |
| 372 | - $revision = $this->entityRepo->getById('page_revision', $revisionId, false); | 372 | + $revision = $page->revisions()->where('id', '=', $revisionId)->first(); |
| 373 | + if ($revision === null) { | ||
| 374 | + abort(404); | ||
| 375 | + } | ||
| 373 | 376 | ||
| 374 | $page->fill($revision->toArray()); | 377 | $page->fill($revision->toArray()); |
| 375 | - $this->setPageTitle(trans('entities.pages_revision_named', ['pageName'=>$page->getShortName()])); | 378 | + $this->setPageTitle(trans('entities.pages_revision_named', ['pageName' => $page->getShortName()])); |
| 376 | 379 | ||
| 377 | return view('pages/revision', [ | 380 | return view('pages/revision', [ |
| 378 | 'page' => $page, | 381 | 'page' => $page, |
| ... | @@ -390,7 +393,10 @@ class PageController extends Controller | ... | @@ -390,7 +393,10 @@ class PageController extends Controller |
| 390 | public function showRevisionChanges($bookSlug, $pageSlug, $revisionId) | 393 | public function showRevisionChanges($bookSlug, $pageSlug, $revisionId) |
| 391 | { | 394 | { |
| 392 | $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); | 395 | $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); |
| 393 | - $revision = $this->entityRepo->getById('page_revision', $revisionId); | 396 | + $revision = $page->revisions()->where('id', '=', $revisionId)->first(); |
| 397 | + if ($revision === null) { | ||
| 398 | + abort(404); | ||
| 399 | + } | ||
| 394 | 400 | ||
| 395 | $prev = $revision->getPrevious(); | 401 | $prev = $revision->getPrevious(); |
| 396 | $prevContent = ($prev === null) ? '' : $prev->html; | 402 | $prevContent = ($prev === null) ? '' : $prev->html; | ... | ... |
| ... | @@ -86,8 +86,7 @@ class EntityRepo | ... | @@ -86,8 +86,7 @@ class EntityRepo |
| 86 | $this->entities = [ | 86 | $this->entities = [ |
| 87 | 'page' => $this->page, | 87 | 'page' => $this->page, |
| 88 | 'chapter' => $this->chapter, | 88 | 'chapter' => $this->chapter, |
| 89 | - 'book' => $this->book, | 89 | + 'book' => $this->book |
| 90 | - 'page_revision' => $this->pageRevision | ||
| 91 | ]; | 90 | ]; |
| 92 | $this->viewService = $viewService; | 91 | $this->viewService = $viewService; |
| 93 | $this->permissionService = $permissionService; | 92 | $this->permissionService = $permissionService; | ... | ... |
| 1 | <?php namespace Tests; | 1 | <?php namespace Tests; |
| 2 | 2 | ||
| 3 | -class PageContentTest extends BrowserKitTest | 3 | +use BookStack\Page; |
| 4 | +use BookStack\Repos\EntityRepo; | ||
| 5 | + | ||
| 6 | +class PageContentTest extends TestCase | ||
| 4 | { | 7 | { |
| 5 | 8 | ||
| 6 | public function test_page_includes() | 9 | public function test_page_includes() |
| 7 | { | 10 | { |
| 8 | - $page = \BookStack\Page::first(); | 11 | + $page = Page::first(); |
| 9 | - $secondPage = \BookStack\Page::all()->get(2); | 12 | + $secondPage = Page::all()->get(2); |
| 10 | 13 | ||
| 11 | $secondPage->html = "<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>"; | 14 | $secondPage->html = "<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>"; |
| 12 | $secondPage->save(); | 15 | $secondPage->save(); |
| 13 | 16 | ||
| 14 | - $this->asAdmin()->visit($page->getUrl()) | 17 | + $this->asEditor(); |
| 15 | - ->dontSee('Hello, This is a test'); | 18 | + |
| 19 | + $pageContent = $this->get($page->getUrl()); | ||
| 20 | + $pageContent->assertDontSee('Hello, This is a test'); | ||
| 16 | 21 | ||
| 17 | $originalHtml = $page->html; | 22 | $originalHtml = $page->html; |
| 18 | $page->html .= "{{@{$secondPage->id}}}"; | 23 | $page->html .= "{{@{$secondPage->id}}}"; |
| 19 | $page->save(); | 24 | $page->save(); |
| 20 | 25 | ||
| 21 | - $this->asAdmin()->visit($page->getUrl()) | 26 | + $pageContent = $this->get($page->getUrl()); |
| 22 | - ->see('Hello, This is a test') | 27 | + $pageContent->assertSee('Hello, This is a test'); |
| 23 | - ->see('This is a second block of content'); | 28 | + $pageContent->assertSee('This is a second block of content'); |
| 24 | 29 | ||
| 25 | $page->html = $originalHtml . " Well {{@{$secondPage->id}#section2}}"; | 30 | $page->html = $originalHtml . " Well {{@{$secondPage->id}#section2}}"; |
| 26 | $page->save(); | 31 | $page->save(); |
| 27 | 32 | ||
| 28 | - $this->asAdmin()->visit($page->getUrl()) | 33 | + $pageContent = $this->get($page->getUrl()); |
| 29 | - ->dontSee('Hello, This is a test') | 34 | + $pageContent->assertDontSee('Hello, This is a test'); |
| 30 | - ->see('Well This is a second block of content'); | 35 | + $pageContent->assertSee('Well This is a second block of content'); |
| 36 | + } | ||
| 37 | + | ||
| 38 | + public function test_page_revision_views_viewable() | ||
| 39 | + { | ||
| 40 | + $this->asEditor(); | ||
| 41 | + | ||
| 42 | + $entityRepo = $this->app[EntityRepo::class]; | ||
| 43 | + $page = Page::first(); | ||
| 44 | + $entityRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']); | ||
| 45 | + $pageRevision = $page->revisions->last(); | ||
| 46 | + | ||
| 47 | + $revisionView = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id); | ||
| 48 | + $revisionView->assertStatus(200); | ||
| 49 | + $revisionView->assertSee('new content'); | ||
| 50 | + | ||
| 51 | + $revisionView = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id . '/changes'); | ||
| 52 | + $revisionView->assertStatus(200); | ||
| 53 | + $revisionView->assertSee('new content'); | ||
| 31 | } | 54 | } |
| 32 | 55 | ||
| 33 | } | 56 | } | ... | ... |
| ... | @@ -84,7 +84,7 @@ class PublicActionTest extends BrowserKitTest | ... | @@ -84,7 +84,7 @@ class PublicActionTest extends BrowserKitTest |
| 84 | { | 84 | { |
| 85 | $page = \BookStack\Page::first(); | 85 | $page = \BookStack\Page::first(); |
| 86 | $this->asAdmin()->visit($page->getUrl()); | 86 | $this->asAdmin()->visit($page->getUrl()); |
| 87 | - Auth::logout(); | 87 | + \Auth::logout(); |
| 88 | view()->share('pageTitle', ''); | 88 | view()->share('pageTitle', ''); |
| 89 | $this->forceVisit('/cats/dogs/hippos'); | 89 | $this->forceVisit('/cats/dogs/hippos'); |
| 90 | $this->dontSee($page->name); | 90 | $this->dontSee($page->name); | ... | ... |
| ... | @@ -13,6 +13,7 @@ abstract class TestCase extends BaseTestCase | ... | @@ -13,6 +13,7 @@ abstract class TestCase extends BaseTestCase |
| 13 | use DatabaseTransactions; | 13 | use DatabaseTransactions; |
| 14 | 14 | ||
| 15 | protected $admin; | 15 | protected $admin; |
| 16 | + protected $editor; | ||
| 16 | 17 | ||
| 17 | /** | 18 | /** |
| 18 | * Set the current user context to be an admin. | 19 | * Set the current user context to be an admin. |
| ... | @@ -36,6 +37,28 @@ abstract class TestCase extends BaseTestCase | ... | @@ -36,6 +37,28 @@ abstract class TestCase extends BaseTestCase |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | /** | 39 | /** |
| 40 | + * Set the current user context to be an editor. | ||
| 41 | + * @return $this | ||
| 42 | + */ | ||
| 43 | + public function asEditor() | ||
| 44 | + { | ||
| 45 | + return $this->actingAs($this->getEditor()); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Get a editor user. | ||
| 51 | + * @return mixed | ||
| 52 | + */ | ||
| 53 | + public function getEditor() { | ||
| 54 | + if($this->editor === null) { | ||
| 55 | + $editorRole = Role::getRole('editor'); | ||
| 56 | + $this->editor = $editorRole->users->first(); | ||
| 57 | + } | ||
| 58 | + return $this->editor; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 39 | * Create and return a new book. | 62 | * Create and return a new book. |
| 40 | * @param array $input | 63 | * @param array $input |
| 41 | * @return Book | 64 | * @return Book | ... | ... |
-
Please register or sign in to post a comment