]> BookStack Code Mirror - bookstack/blobdiff - tests/BrowserKitTest.php
Adds overflow:auto to popup content to allow it to scroll in lower res.
[bookstack] / tests / BrowserKitTest.php
index c665bfc231453308a0cd18d33752b834f590b71b..1eabc74170ab75067e1ff95c57057cc0d9e156d6 100644 (file)
@@ -1,7 +1,9 @@
 <?php namespace Tests;
 
+use BookStack\Entity;
 use BookStack\Role;
 use BookStack\Services\PermissionService;
+use BookStack\User;
 use Illuminate\Contracts\Console\Kernel;
 use Illuminate\Foundation\Testing\DatabaseTransactions;
 use Laravel\BrowserKitTesting\TestCase;
@@ -118,15 +120,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;
     }