mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-03 16:23:35 +08:00
Extracted many page-specific repo methods into page-specific repo
This commit is contained in:
@ -2,8 +2,9 @@
|
||||
|
||||
use BookStack\Auth\Permissions\JointPermission;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\EntityRepo;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Auth\User;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
|
||||
class CommandsTest extends TestCase
|
||||
{
|
||||
@ -53,10 +54,10 @@ class CommandsTest extends TestCase
|
||||
public function test_clear_revisions_command()
|
||||
{
|
||||
$this->asEditor();
|
||||
$entityRepo = $this->app[EntityRepo::class];
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$page = Page::first();
|
||||
$entityRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$entityRepo->updatePageDraft($page, ['name' => 'updated page', 'html' => '<p>new content in draft</p>', 'summary' => 'page revision testing']);
|
||||
$pageRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$pageRepo->updatePageDraft($page, ['name' => 'updated page', 'html' => '<p>new content in draft</p>', 'summary' => 'page revision testing']);
|
||||
|
||||
$this->assertDatabaseHas('page_revisions', [
|
||||
'page_id' => $page->id,
|
||||
|
@ -3,8 +3,9 @@
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\EntityRepo;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Auth\UserRepo;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class EntityTest extends BrowserKitTest
|
||||
@ -193,7 +194,7 @@ class EntityTest extends BrowserKitTest
|
||||
$entities = $this->createEntityChainBelongingToUser($creator, $updater);
|
||||
$this->actingAs($creator);
|
||||
app(UserRepo::class)->destroy($creator);
|
||||
app(EntityRepo::class)->savePageRevision($entities['page']);
|
||||
app(PageRepo::class)->savePageRevision($entities['page']);
|
||||
|
||||
$this->checkEntitiesViewable($entities);
|
||||
}
|
||||
@ -206,7 +207,7 @@ class EntityTest extends BrowserKitTest
|
||||
$entities = $this->createEntityChainBelongingToUser($creator, $updater);
|
||||
$this->actingAs($updater);
|
||||
app(UserRepo::class)->destroy($updater);
|
||||
app(EntityRepo::class)->savePageRevision($entities['page']);
|
||||
app(PageRepo::class)->savePageRevision($entities['page']);
|
||||
|
||||
$this->checkEntitiesViewable($entities);
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
<?php namespace Tests;
|
||||
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\EntityRepo;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
|
||||
class PageContentTest extends TestCase
|
||||
{
|
||||
@ -71,9 +72,9 @@ class PageContentTest extends TestCase
|
||||
{
|
||||
$this->asEditor();
|
||||
|
||||
$entityRepo = $this->app[EntityRepo::class];
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$page = Page::first();
|
||||
$entityRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$pageRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$pageRevision = $page->revisions->last();
|
||||
|
||||
$revisionView = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id);
|
||||
@ -89,10 +90,10 @@ class PageContentTest extends TestCase
|
||||
{
|
||||
$this->asEditor();
|
||||
|
||||
$entityRepo = $this->app[EntityRepo::class];
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$page = Page::first();
|
||||
$entityRepo->updatePage($page, $page->book_id, ['name' => 'updated page abc123', 'html' => '<p>new contente def456</p>', 'summary' => 'initial page revision testing']);
|
||||
$entityRepo->updatePage($page, $page->book_id, ['name' => 'updated page again', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$pageRepo->updatePage($page, $page->book_id, ['name' => 'updated page abc123', 'html' => '<p>new contente def456</p>', 'summary' => 'initial page revision testing']);
|
||||
$pageRepo->updatePage($page, $page->book_id, ['name' => 'updated page again', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$page = Page::find($page->id);
|
||||
|
||||
|
||||
|
@ -1,16 +1,18 @@
|
||||
<?php namespace Tests;
|
||||
|
||||
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
|
||||
class PageDraftTest extends BrowserKitTest
|
||||
{
|
||||
protected $page;
|
||||
protected $entityRepo;
|
||||
protected $pageRepo;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->page = \BookStack\Entities\Page::first();
|
||||
$this->entityRepo = app('\BookStack\Entities\EntityRepo');
|
||||
$this->pageRepo = app(PageRepo::class);
|
||||
}
|
||||
|
||||
public function test_draft_content_shows_if_available()
|
||||
@ -20,7 +22,7 @@ class PageDraftTest extends BrowserKitTest
|
||||
->dontSeeInField('html', $addedContent);
|
||||
|
||||
$newContent = $this->page->html . $addedContent;
|
||||
$this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
||||
$this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
||||
$this->asAdmin()->visit($this->page->getUrl() . '/edit')
|
||||
->seeInField('html', $newContent);
|
||||
}
|
||||
@ -33,7 +35,7 @@ class PageDraftTest extends BrowserKitTest
|
||||
|
||||
$newContent = $this->page->html . $addedContent;
|
||||
$newUser = $this->getEditor();
|
||||
$this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
||||
$this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
||||
$this->actingAs($newUser)->visit($this->page->getUrl() . '/edit')
|
||||
->dontSeeInField('html', $newContent);
|
||||
}
|
||||
@ -41,7 +43,7 @@ class PageDraftTest extends BrowserKitTest
|
||||
public function test_alert_message_shows_if_editing_draft()
|
||||
{
|
||||
$this->asAdmin();
|
||||
$this->entityRepo->updatePageDraft($this->page, ['html' => 'test content']);
|
||||
$this->pageRepo->updatePageDraft($this->page, ['html' => 'test content']);
|
||||
$this->asAdmin()->visit($this->page->getUrl() . '/edit')
|
||||
->see('You are currently editing a draft');
|
||||
}
|
||||
@ -55,7 +57,7 @@ class PageDraftTest extends BrowserKitTest
|
||||
|
||||
$newContent = $this->page->html . $addedContent;
|
||||
$newUser = $this->getEditor();
|
||||
$this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
||||
$this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]);
|
||||
|
||||
$this->actingAs($newUser)
|
||||
->visit($this->page->getUrl() . '/edit')
|
||||
|
@ -3,7 +3,8 @@
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\EntityRepo;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
|
||||
class SortTest extends TestCase
|
||||
{
|
||||
@ -18,8 +19,8 @@ class SortTest extends TestCase
|
||||
public function test_drafts_do_not_show_up()
|
||||
{
|
||||
$this->asAdmin();
|
||||
$entityRepo = app(EntityRepo::class);
|
||||
$draft = $entityRepo->getDraftPage($this->book);
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$draft = $pageRepo->getDraftPage($this->book);
|
||||
|
||||
$resp = $this->get($this->book->getUrl());
|
||||
$resp->assertSee($draft->name);
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php namespace Tests;
|
||||
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Uploads\Image;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\EntityRepo;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Uploads\ImageService;
|
||||
|
||||
class ImageTest extends TestCase
|
||||
@ -250,8 +251,8 @@ class ImageTest extends TestCase
|
||||
$upload->assertStatus(200);
|
||||
$image = Image::where('type', '=', 'gallery')->first();
|
||||
|
||||
$entityRepo = app(EntityRepo::class);
|
||||
$entityRepo->updatePage($page, $page->book_id, [
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$pageRepo->updatePage($page, $page->book_id, [
|
||||
'name' => $page->name,
|
||||
'html' => $page->html . "<img src=\"{$image->url}\">",
|
||||
'summary' => ''
|
||||
@ -263,7 +264,7 @@ class ImageTest extends TestCase
|
||||
$this->assertCount(0, $toDelete);
|
||||
|
||||
// Save a revision of our page without the image;
|
||||
$entityRepo->updatePage($page, $page->book_id, [
|
||||
$pageRepo->updatePage($page, $page->book_id, [
|
||||
'name' => $page->name,
|
||||
'html' => "<p>Hello</p>",
|
||||
'summary' => ''
|
||||
|
@ -5,7 +5,7 @@ use BookStack\Entities\Bookshelf;
|
||||
use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Entity;
|
||||
use BookStack\Auth\User;
|
||||
use BookStack\Entities\EntityRepo;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Entities\Page;
|
||||
|
||||
class RestrictionsTest extends BrowserKitTest
|
||||
|
@ -5,10 +5,11 @@ use BookStack\Entities\Bookshelf;
|
||||
use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Entity;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\EntityRepo;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Auth\Permissions\PermissionsRepo;
|
||||
use BookStack\Auth\Role;
|
||||
use BookStack\Auth\Permissions\PermissionService;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Settings\SettingService;
|
||||
|
||||
trait SharedTestHelpers
|
||||
@ -78,7 +79,7 @@ trait SharedTestHelpers
|
||||
*/
|
||||
protected function regenEntityPermissions(Entity $entity)
|
||||
{
|
||||
$this->app[PermissionService::class]->buildJointPermissionsForEntity($entity);
|
||||
app(PermissionService::class)->buildJointPermissionsForEntity($entity);
|
||||
$entity->load('jointPermissions');
|
||||
}
|
||||
|
||||
@ -88,7 +89,7 @@ trait SharedTestHelpers
|
||||
* @return \BookStack\Entities\Bookshelf
|
||||
*/
|
||||
public function newShelf($input = ['name' => 'test shelf', 'description' => 'My new test shelf']) {
|
||||
return $this->app[EntityRepo::class]->createFromInput('bookshelf', $input, false);
|
||||
return app(EntityRepo::class)->createFromInput('bookshelf', $input, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,7 +98,7 @@ trait SharedTestHelpers
|
||||
* @return Book
|
||||
*/
|
||||
public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) {
|
||||
return $this->app[EntityRepo::class]->createFromInput('book', $input, false);
|
||||
return app(EntityRepo::class)->createFromInput('book', $input, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,7 +108,7 @@ trait SharedTestHelpers
|
||||
* @return \BookStack\Entities\Chapter
|
||||
*/
|
||||
public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) {
|
||||
return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book);
|
||||
return app(EntityRepo::class)->createFromInput('chapter', $input, $book);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,9 +118,9 @@ trait SharedTestHelpers
|
||||
*/
|
||||
public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) {
|
||||
$book = Book::first();
|
||||
$entityRepo = $this->app[EntityRepo::class];
|
||||
$draftPage = $entityRepo->getDraftPage($book);
|
||||
return $entityRepo->publishPageDraft($draftPage, $input);
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$draftPage = $pageRepo->getDraftPage($book);
|
||||
return $pageRepo->publishPageDraft($draftPage, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user