]> BookStack Code Mirror - bookstack/blobdiff - tests/BrowserKitTest.php
Update search.js
[bookstack] / tests / BrowserKitTest.php
index 0a97c1292cee49ddfb85772d04535b6e9ee00327..98259dea94b587a7792da7bea8b8c7231ce575d6 100644 (file)
@@ -1,9 +1,14 @@
-<?php
+<?php namespace Tests;
 
+use BookStack\Entity;
+use BookStack\Role;
+use BookStack\Services\PermissionService;
+use Illuminate\Contracts\Console\Kernel;
 use Illuminate\Foundation\Testing\DatabaseTransactions;
+use Laravel\BrowserKitTesting\TestCase;
 use Symfony\Component\DomCrawler\Crawler;
 
-abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
+abstract class BrowserKitTest extends TestCase
 {
 
     use DatabaseTransactions;
@@ -19,6 +24,12 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     private $admin;
     private $editor;
 
+    public function tearDown()
+    {
+        \DB::disconnect();
+        parent::tearDown();
+    }
+
     /**
      * Creates the application.
      *
@@ -28,7 +39,7 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     {
         $app = require __DIR__.'/../bootstrap/app.php';
 
-        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+        $app->make(Kernel::class)->bootstrap();
 
         return $app;
     }
@@ -48,7 +59,7 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
      */
     public function getAdmin() {
         if($this->admin === null) {
-            $adminRole = \BookStack\Role::getRole('admin');
+            $adminRole = Role::getSystemRole('admin');
             $this->admin = $adminRole->users->first();
         }
         return $this->admin;
@@ -95,12 +106,10 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     protected function createEntityChainBelongingToUser($creatorUser, $updaterUser = false)
     {
         if ($updaterUser === false) $updaterUser = $creatorUser;
-        $book = factory(BookStack\Book::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
-        $chapter = factory(BookStack\Chapter::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
-        $page = factory(BookStack\Page::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id]);
-        $book->chapters()->saveMany([$chapter]);
-        $chapter->pages()->saveMany([$page]);
-        $restrictionService = $this->app[\BookStack\Services\PermissionService::class];
+        $book = factory(\BookStack\Book::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
+        $chapter = factory(\BookStack\Chapter::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id]);
+        $page = factory(\BookStack\Page::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id, 'chapter_id' => $chapter->id]);
+        $restrictionService = $this->app[PermissionService::class];
         $restrictionService->buildJointPermissionsForEntity($book);
         return [
             'book' => $book,
@@ -109,6 +118,16 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
         ];
     }
 
+    /**
+     * Helper for updating entity permissions.
+     * @param Entity $entity
+     */
+    protected function updateEntityPermissions(Entity $entity)
+    {
+        $restrictionService = $this->app[PermissionService::class];
+        $restrictionService->buildJointPermissionsForEntity($entity);
+    }
+
     /**
      * Quick way to create a new user
      * @param array $attributes
@@ -117,7 +136,7 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     protected function getEditor($attributes = [])
     {
         $user = factory(\BookStack\User::class)->create($attributes);
-        $role = \BookStack\Role::getRole('editor');
+        $role = Role::getRole('editor');
         $user->attachRole($role);;
         return $user;
     }
@@ -211,7 +230,6 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     /**
      * Check if the page contains the given element.
      * @param  string  $selector
-     * @return bool
      */
     protected function pageHasElement($selector)
     {
@@ -223,7 +241,6 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     /**
      * Check if the page contains the given element.
      * @param  string  $selector
-     * @return bool
      */
     protected function pageNotHasElement($selector)
     {