]> BookStack Code Mirror - bookstack/blobdiff - tests/BrowserKitTest.php
reduced icon size
[bookstack] / tests / BrowserKitTest.php
index c665bfc231453308a0cd18d33752b834f590b71b..a8ff0304422cfef5cf04a964e011cb3b3ff43de1 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace Tests;
 
+use BookStack\Entity;
 use BookStack\Role;
 use BookStack\Services\PermissionService;
 use Illuminate\Contracts\Console\Kernel;
@@ -12,17 +13,16 @@ abstract class BrowserKitTest extends TestCase
 
     use DatabaseTransactions;
 
+    // Local user instances
+    private $admin;
+    private $editor;
+
     /**
      * The base URL to use while testing the application.
-     *
      * @var string
      */
     protected $baseUrl = 'http://localhost';
 
-    // Local user instances
-    private $admin;
-    private $editor;
-
     public function tearDown()
     {
         \DB::disconnect();
@@ -118,15 +118,35 @@ abstract class BrowserKitTest extends TestCase
     }
 
     /**
-     * Quick way to create a new user
+     * Helper for updating entity permissions.
+     * @param Entity $entity
+     */
+    protected function updateEntityPermissions(Entity $entity)
+    {
+        $restrictionService = $this->app[PermissionService::class];
+        $restrictionService->buildJointPermissionsForEntity($entity);
+    }
+
+    /**
+     * Get an instance of a user with 'editor' permissions
      * @param array $attributes
      * @return mixed
      */
     protected function getEditor($attributes = [])
     {
-        $user = factory(\BookStack\User::class)->create($attributes);
-        $role = Role::getRole('editor');
-        $user->attachRole($role);;
+        $user = \BookStack\Role::getRole('editor')->users()->first();
+        if (!empty($attributes)) $user->forceFill($attributes)->save();
+        return $user;
+    }
+
+    /**
+     * Get an instance of a user with 'viewer' permissions
+     * @return mixed
+     */
+    protected function getViewer()
+    {
+        $user = \BookStack\Role::getRole('viewer')->users()->first();
+        if (!empty($attributes)) $user->forceFill($attributes)->save();
         return $user;
     }