mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-09 10:22:51 +03:00
Entity Repo & Controller Refactor (#1690)
* Started mass-refactoring of the current entity repos * Rewrote book tree logic - Now does two simple queries instead of one really complex one. - Extracted logic into its own class. - Remove model-level akward union field listing. - Logic now more readable than being large separate query and compilation functions. * Extracted and split book sort logic * Finished up Book controller/repo organisation * Refactored bookshelves controllers and repo parts * Fixed issues found via phpunit * Refactored Chapter controller * Updated Chapter export controller * Started Page controller/repo refactor * Refactored another chunk of PageController * Completed initial pagecontroller refactor pass * Fixed tests and continued reduction of old repos * Removed old page remove and further reduced entity repo * Removed old entity repo, split out page controller * Ran phpcbf and split out some page content methods * Tidied up some EntityProvider elements * Fixed issued caused by viewservice change
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Auth\UserRepo;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use Carbon\Carbon;
|
||||
@@ -192,7 +191,7 @@ class EntityTest extends BrowserKitTest
|
||||
$entities = $this->createEntityChainBelongingToUser($creator, $updater);
|
||||
$this->actingAs($creator);
|
||||
app(UserRepo::class)->destroy($creator);
|
||||
app(PageRepo::class)->savePageRevision($entities['page']);
|
||||
app(PageRepo::class)->update($entities['page'], ['html' => '<p>hello!</p>>']);
|
||||
|
||||
$this->checkEntitiesViewable($entities);
|
||||
}
|
||||
@@ -205,7 +204,7 @@ class EntityTest extends BrowserKitTest
|
||||
$entities = $this->createEntityChainBelongingToUser($creator, $updater);
|
||||
$this->actingAs($updater);
|
||||
app(UserRepo::class)->destroy($updater);
|
||||
app(PageRepo::class)->savePageRevision($entities['page']);
|
||||
app(PageRepo::class)->update($entities['page'], ['html' => '<p>Hello there!</p>']);
|
||||
|
||||
$this->checkEntitiesViewable($entities);
|
||||
}
|
||||
@@ -273,8 +272,7 @@ class EntityTest extends BrowserKitTest
|
||||
|
||||
public function test_slug_multi_byte_lower_casing()
|
||||
{
|
||||
$entityRepo = app(EntityRepo::class);
|
||||
$book = $entityRepo->createFromInput('book', [
|
||||
$book = $this->newBook([
|
||||
'name' => 'КНИГА'
|
||||
]);
|
||||
|
||||
@@ -284,8 +282,7 @@ class EntityTest extends BrowserKitTest
|
||||
|
||||
public function test_slug_format()
|
||||
{
|
||||
$entityRepo = app(EntityRepo::class);
|
||||
$book = $entityRepo->createFromInput('book', [
|
||||
$book = $this->newBook([
|
||||
'name' => 'PartA / PartB / PartC'
|
||||
]);
|
||||
|
||||
|
@@ -1,8 +1,7 @@
|
||||
<?php namespace Tests;
|
||||
|
||||
use BookStack\Entities\Managers\PageContent;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
|
||||
class PageContentTest extends TestCase
|
||||
{
|
||||
@@ -242,4 +241,66 @@ class PageContentTest extends TestCase
|
||||
$updatedPage = Page::where('id', '=', $page->id)->first();
|
||||
$this->assertEquals(substr_count($updatedPage->html, "bkmrk-test\""), 1);
|
||||
}
|
||||
|
||||
public function test_get_page_nav_sets_correct_properties()
|
||||
{
|
||||
$content = '<h1 id="testa">Hello</h1><h2 id="testb">There</h2><h3 id="testc">Donkey</h3>';
|
||||
$pageContent = new PageContent(new Page(['html' => $content]));
|
||||
$navMap = $pageContent->getNavigation($content);
|
||||
|
||||
$this->assertCount(3, $navMap);
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h1',
|
||||
'link' => '#testa',
|
||||
'text' => 'Hello',
|
||||
'level' => 1,
|
||||
], $navMap[0]);
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h2',
|
||||
'link' => '#testb',
|
||||
'text' => 'There',
|
||||
'level' => 2,
|
||||
], $navMap[1]);
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h3',
|
||||
'link' => '#testc',
|
||||
'text' => 'Donkey',
|
||||
'level' => 3,
|
||||
], $navMap[2]);
|
||||
}
|
||||
|
||||
public function test_get_page_nav_does_not_show_empty_titles()
|
||||
{
|
||||
$content = '<h1 id="testa">Hello</h1><h2 id="testb"> </h2><h3 id="testc"></h3>';
|
||||
$pageContent = new PageContent(new Page(['html' => $content]));
|
||||
$navMap = $pageContent->getNavigation($content);
|
||||
|
||||
$this->assertCount(1, $navMap);
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h1',
|
||||
'link' => '#testa',
|
||||
'text' => 'Hello'
|
||||
], $navMap[0]);
|
||||
}
|
||||
|
||||
public function test_get_page_nav_shifts_headers_if_only_smaller_ones_are_used()
|
||||
{
|
||||
$content = '<h4 id="testa">Hello</h4><h5 id="testb">There</h5><h6 id="testc">Donkey</h6>';
|
||||
$pageContent = new PageContent(new Page(['html' => $content]));
|
||||
$navMap = $pageContent->getNavigation($content);
|
||||
|
||||
$this->assertCount(3, $navMap);
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h4',
|
||||
'level' => 1,
|
||||
], $navMap[0]);
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h5',
|
||||
'level' => 2,
|
||||
], $navMap[1]);
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h6',
|
||||
'level' => 3,
|
||||
], $navMap[2]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,14 @@
|
||||
<?php namespace Tests;
|
||||
|
||||
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
|
||||
class PageDraftTest extends BrowserKitTest
|
||||
{
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* @var PageRepo
|
||||
*/
|
||||
protected $pageRepo;
|
||||
|
||||
public function setUp(): void
|
||||
@@ -85,11 +88,11 @@ class PageDraftTest extends BrowserKitTest
|
||||
$newUser = $this->getEditor();
|
||||
|
||||
$this->actingAs($newUser)->visit('/')
|
||||
->visit($book->getUrl() . '/create-page')
|
||||
->visit($chapter->getUrl() . '/create-page')
|
||||
->visit($book->getUrl('/create-page'))
|
||||
->visit($chapter->getUrl('/create-page'))
|
||||
->visit($book->getUrl())
|
||||
->seeInElement('.book-contents', 'New Page');
|
||||
|
||||
|
||||
$this->asAdmin()
|
||||
->visit($book->getUrl())
|
||||
->dontSeeInElement('.book-contents', 'New Page')
|
||||
|
@@ -12,7 +12,7 @@ class PageRevisionTest extends TestCase
|
||||
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$page = Page::first();
|
||||
$pageRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$pageRepo->update($page, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$pageRevision = $page->revisions->last();
|
||||
|
||||
$revisionView = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id);
|
||||
@@ -30,8 +30,8 @@ class PageRevisionTest extends TestCase
|
||||
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$page = Page::first();
|
||||
$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']);
|
||||
$pageRepo->update($page, ['name' => 'updated page abc123', 'html' => '<p>new contente def456</p>', 'summary' => 'initial page revision testing']);
|
||||
$pageRepo->update($page, ['name' => 'updated page again', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
|
||||
$page = Page::find($page->id);
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class PageRevisionTest extends TestCase
|
||||
$beforeRevisionCount = $page->revisions->count();
|
||||
$currentRevision = $page->getCurrentRevision();
|
||||
$resp = $this->asEditor()->delete($currentRevision->getUrl('/delete/'));
|
||||
$resp->assertStatus(400);
|
||||
$resp->assertRedirect($page->getUrl('/revisions'));
|
||||
|
||||
$page = Page::find($page->id);
|
||||
$afterRevisionCount = $page->revisions->count();
|
||||
|
@@ -1,6 +1,5 @@
|
||||
<?php namespace Tests;
|
||||
|
||||
use BookStack\Auth\Role;
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Page;
|
||||
@@ -20,7 +19,7 @@ class SortTest extends TestCase
|
||||
{
|
||||
$this->asAdmin();
|
||||
$pageRepo = app(PageRepo::class);
|
||||
$draft = $pageRepo->getDraftPage($this->book);
|
||||
$draft = $pageRepo->getNewDraftPage($this->book);
|
||||
|
||||
$resp = $this->get($this->book->getUrl());
|
||||
$resp->assertSee($draft->name);
|
||||
@@ -214,7 +213,6 @@ class SortTest extends TestCase
|
||||
'entity_selection' => 'book:' . $newBook->id,
|
||||
'name' => 'My copied test page'
|
||||
]);
|
||||
|
||||
$pageCopy = Page::where('name', '=', 'My copied test page')->first();
|
||||
|
||||
$movePageResp->assertRedirect($pageCopy->getUrl());
|
||||
|
Reference in New Issue
Block a user