]> BookStack Code Mirror - bookstack/blobdiff - tests/Helpers/EntityProvider.php
My Acount: Updated old preference url reference for watches
[bookstack] / tests / Helpers / EntityProvider.php
index 05925909e568671606fd16fbfdac5e529642486e..3cb8c44d32ca75c095cae6b73d49b6d7bf6bde20 100644 (file)
@@ -2,8 +2,6 @@
 
 namespace Tests\Helpers;
 
-use BookStack\Auth\Role;
-use BookStack\Auth\User;
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Bookshelf;
 use BookStack\Entities\Models\Chapter;
@@ -13,6 +11,8 @@ 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;
 
 /**
@@ -186,40 +186,26 @@ class EntityProvider
     }
 
     /**
-     * Regenerate the permission for an entity.
-     * Centralised to manage clearing of cached elements between requests.
+     * Create and return a new test draft page.
      */
-    public function regenPermissions(Entity $entity): void
+    public function newDraftPage(array $input = ['name' => 'test page', 'html' => 'My new test page']): Page
     {
-        $entity->rebuildPermissions();
-        $entity->load('jointPermissions');
+        $book = $this->book();
+        $pageRepo = app(PageRepo::class);
+        $draftPage = $pageRepo->getNewDraftPage($book);
+        $pageRepo->updatePageDraft($draftPage, $input);
+        $this->addToCache($draftPage);
+        return $draftPage;
     }
 
     /**
-     * Set the given entity as having restricted permissions, and apply the given
-     * permissions for the given roles.
-     * @param string[] $actions
-     * @param Role[] $roles
+     * Fully destroy the given entity from the system, bypassing the recycle bin
+     * stage. Still runs through main app deletion logic.
      */
-    public function setPermissions(Entity $entity, array $actions = [], array $roles = []): void
-    {
-        $entity->restricted = true;
-        $entity->permissions()->delete();
-
-        $permissions = [];
-        foreach ($actions as $action) {
-            foreach ($roles as $role) {
-                $permissions[] = [
-                    'role_id' => $role->id,
-                    'action'  => strtolower($action),
-                ];
-            }
-        }
-
-        $entity->permissions()->createMany($permissions);
-        $entity->save();
-        $entity->load('permissions');
-        $this->regenPermissions($entity);
+    public function destroy(Entity $entity)
+    {
+        $trash = app()->make(TrashCan::class);
+        $trash->destroyEntity($entity);
     }
 
     /**