]> BookStack Code Mirror - bookstack/blobdiff - tests/Helpers/EntityProvider.php
ZIP Imports: Added API examples, finished testing
[bookstack] / tests / Helpers / EntityProvider.php
index 982063421453139c95470d4ac637a45f55f2b63e..22e554f74b5caa08ec049d3668afeca0780fb313 100644 (file)
@@ -6,6 +6,7 @@ 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;
@@ -207,6 +208,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.