X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/0f113ec41f328eab6af78097d47c28d9cb99d893..refs/pull/5676/head:/tests/Helpers/EntityProvider.php diff --git a/tests/Helpers/EntityProvider.php b/tests/Helpers/EntityProvider.php index d79015f75..22e554f74 100644 --- a/tests/Helpers/EntityProvider.php +++ b/tests/Helpers/EntityProvider.php @@ -2,16 +2,18 @@ namespace Tests\Helpers; -use BookStack\Auth\User; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Bookshelf; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Entity; +use BookStack\Entities\Models\HasCoverImage; use BookStack\Entities\Models\Page; use BookStack\Entities\Repos\BookRepo; use BookStack\Entities\Repos\BookshelfRepo; use BookStack\Entities\Repos\ChapterRepo; use BookStack\Entities\Repos\PageRepo; +use BookStack\Entities\Tools\TrashCan; +use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Builder; /** @@ -52,6 +54,15 @@ class EntityProvider return $this->page(fn(Builder $query) => $query->where('chapter_id', '=', 0)); } + public function templatePage(): Page + { + $page = $this->page(); + $page->template = true; + $page->save(); + + return $page; + } + /** * Get an un-fetched chapter from the system. */ @@ -184,6 +195,52 @@ class EntityProvider return $pageRepo->publishDraft($draftPage, $input); } + /** + * Create and return a new test draft page. + */ + public function newDraftPage(array $input = ['name' => 'test page', 'html' => 'My new test page']): Page + { + $book = $this->book(); + $pageRepo = app(PageRepo::class); + $draftPage = $pageRepo->getNewDraftPage($book); + $pageRepo->updatePageDraft($draftPage, $input); + $this->addToCache($draftPage); + return $draftPage; + } + + /** + * Send an entity to the recycle bin. + */ + public function sendToRecycleBin(Entity $entity) + { + $trash = app()->make(TrashCan::class); + + if ($entity instanceof Page) { + $trash->softDestroyPage($entity); + } elseif ($entity instanceof Chapter) { + $trash->softDestroyChapter($entity); + } elseif ($entity instanceof Book) { + $trash->softDestroyBook($entity); + } elseif ($entity instanceof Bookshelf) { + $trash->softDestroyBookshelf($entity); + } + + $entity->refresh(); + if (is_null($entity->deleted_at)) { + throw new \Exception("Could not send entity type [{$entity->getMorphClass()}] to the recycle bin"); + } + } + + /** + * Fully destroy the given entity from the system, bypassing the recycle bin + * stage. Still runs through main app deletion logic. + */ + public function destroy(Entity $entity) + { + $trash = app()->make(TrashCan::class); + $trash->destroyEntity($entity); + } + /** * @param Entity|Entity[] $entities */