]> BookStack Code Mirror - bookstack/blobdiff - tests/TestCase.php
Add Slovak translation
[bookstack] / tests / TestCase.php
index d52e991e31cd88103e74e145a7478871bccbf380..f3f36ca1cc75daa3211c82d0ee5eec2628891b33 100644 (file)
@@ -4,13 +4,16 @@ use BookStack\Book;
 use BookStack\Chapter;
 use BookStack\Repos\EntityRepo;
 use BookStack\Role;
+use Illuminate\Foundation\Testing\DatabaseTransactions;
 use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
 
 abstract class TestCase extends BaseTestCase
 {
     use CreatesApplication;
+    use DatabaseTransactions;
 
     protected $admin;
+    protected $editor;
 
     /**
      * Set the current user context to be an admin.
@@ -33,6 +36,28 @@ abstract class TestCase extends BaseTestCase
         return $this->admin;
     }
 
+    /**
+     * Set the current user context to be an editor.
+     * @return $this
+     */
+    public function asEditor()
+    {
+        return $this->actingAs($this->getEditor());
+    }
+
+
+    /**
+     * Get a editor user.
+     * @return mixed
+     */
+    public function getEditor() {
+        if($this->editor === null) {
+            $editorRole = Role::getRole('editor');
+            $this->editor = $editorRole->users->first();
+        }
+        return $this->editor;
+    }
+
     /**
      * Create and return a new book.
      * @param array $input