]> BookStack Code Mirror - bookstack/blobdiff - tests/BrowserKitTest.php
Update search.js
[bookstack] / tests / BrowserKitTest.php
index 62fa4a1907e272600b2932cff919ed00521e838e..98259dea94b587a7792da7bea8b8c7231ce575d6 100644 (file)
@@ -1,6 +1,8 @@
 <?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;
@@ -24,7 +26,7 @@ abstract class BrowserKitTest extends TestCase
 
     public function tearDown()
     {
-        \DB::disconnect('mysql_testing');
+        \DB::disconnect();
         parent::tearDown();
     }
 
@@ -105,11 +107,9 @@ abstract class BrowserKitTest extends TestCase
     {
         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];
+        $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,
@@ -118,6 +118,16 @@ abstract class BrowserKitTest extends 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