]> BookStack Code Mirror - bookstack/blobdiff - tests/Helpers/EntityProvider.php
respective book and chapter structure added.
[bookstack] / tests / Helpers / EntityProvider.php
index 3cb8c44d32ca75c095cae6b73d49b6d7bf6bde20..1897abefa28501009366f76661a925b1fb50214a 100644 (file)
@@ -53,6 +53,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.
      */
@@ -198,6 +207,29 @@ class EntityProvider
         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.