X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/7c9937e9240b9656fe865de85a89c97b734656ab..refs/pull/358/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index d52e991e3..f3f36ca1c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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