]> BookStack Code Mirror - bookstack/commitdiff
Notifications: Fixed issues causing failing tests
authorDan Brown <redacted>
Thu, 17 Aug 2023 13:59:28 +0000 (14:59 +0100)
committerDan Brown <redacted>
Thu, 17 Aug 2023 13:59:28 +0000 (14:59 +0100)
- Ensured watch options passed in all meta template usage to fix failing
  scenarios where watch options did not exist.
- Fixed testing issue caused by guest user permission caching.

app/Users/Models/User.php
resources/views/books/show.blade.php
resources/views/chapters/show.blade.php
resources/views/pages/revision.blade.php
resources/views/pages/show.blade.php
resources/views/shelves/show.blade.php
tests/Activity/WatchTest.php
tests/Helpers/UserRoleProvider.php
tests/TestCase.php

index 08cab69fb9206c793cde08cf08518f345188e5a0..be3e9b9b38e468ea0003de1cba22ebdd3976c2aa 100644 (file)
@@ -88,8 +88,6 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
 
     /**
      * This holds the default user when loaded.
 
     /**
      * This holds the default user when loaded.
-     *
-     * @var null|User
      */
     protected static ?User $defaultUser = null;
 
      */
     protected static ?User $defaultUser = null;
 
@@ -107,6 +105,11 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
         return static::$defaultUser;
     }
 
         return static::$defaultUser;
     }
 
+    public static function clearDefault(): void
+    {
+        static::$defaultUser = null;
+    }
+
     /**
      * Check if the user is the default public user.
      */
     /**
      * Check if the user is the default public user.
      */
index 0fb98e304d3cb754e064e802038e65dab5132979..75b01a379242cd97666172d8f7f0da72fc984a27 100644 (file)
@@ -70,7 +70,7 @@
     <div class="mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="blended-links">
     <div class="mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="blended-links">
-            @include('entities.meta', ['entity' => $book])
+            @include('entities.meta', ['entity' => $book, 'watchOptions' => $watchOptions])
             @if($book->hasPermissions())
                 <div class="active-restriction">
                     @if(userCan('restrictions-manage', $book))
             @if($book->hasPermissions())
                 <div class="active-restriction">
                     @if(userCan('restrictions-manage', $book))
index 67a8b9fa544c646e1484ce75286f1fd6c9c804ac..3cb512ccc532ae565ccc392a0ab75e0f18a099d5 100644 (file)
@@ -67,7 +67,7 @@
     <div class="mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="blended-links">
     <div class="mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="blended-links">
-            @include('entities.meta', ['entity' => $chapter])
+            @include('entities.meta', ['entity' => $chapter, 'watchOptions' => $watchOptions])
 
             @if($book->hasPermissions())
                 <div class="active-restriction">
 
             @if($book->hasPermissions())
                 <div class="active-restriction">
index b3208c21131ef67890167b8fd8ec724e5191b45e..c0831ef595c7931e80446b7c49c37677f8ac2032 100644 (file)
@@ -4,7 +4,7 @@
     <div id="revision-details" class="entity-details mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="body text-small text-muted">
     <div id="revision-details" class="entity-details mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="body text-small text-muted">
-            @include('entities.meta', ['entity' => $revision])
+            @include('entities.meta', ['entity' => $revision, 'watchOptions' => null])
         </div>
     </div>
 @stop
         </div>
     </div>
 @stop
index 7d44f677d0720c5a90a78e74309b1c80c0e86329..1cbb819804f27a09ee934a24ffb047ac3610d80f 100644 (file)
@@ -81,7 +81,7 @@
     <div id="page-details" class="entity-details mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="blended-links">
     <div id="page-details" class="entity-details mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="blended-links">
-            @include('entities.meta', ['entity' => $page])
+            @include('entities.meta', ['entity' => $page, 'watchOptions' => $watchOptions])
 
             @if($book->hasPermissions())
                 <div class="active-restriction">
 
             @if($book->hasPermissions())
                 <div class="active-restriction">
index 25b7a14fc1f1d0e983f60a061afe69c200f49ec0..8019a557f601ea17b589681b146780f1a842747e 100644 (file)
@@ -79,7 +79,7 @@
     <div id="details" class="mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="blended-links">
     <div id="details" class="mb-xl">
         <h5>{{ trans('common.details') }}</h5>
         <div class="blended-links">
-            @include('entities.meta', ['entity' => $shelf])
+            @include('entities.meta', ['entity' => $shelf, 'watchOptions' => null])
             @if($shelf->hasPermissions())
                 <div class="active-restriction">
                     @if(userCan('restrictions-manage', $shelf))
             @if($shelf->hasPermissions())
                 <div class="active-restriction">
                     @if(userCan('restrictions-manage', $shelf))
index d68bd271f3a5d06c76f2abf457838dd482ab20a1..e8cb3cbd8b104567eb66354776173412c557eda2 100644 (file)
@@ -102,6 +102,7 @@ class WatchTest extends TestCase
         ]);
 
         $this->assertPermissionError($resp);
         ]);
 
         $this->assertPermissionError($resp);
+        $guest->unsetRelations();
     }
 
     public function test_watch_detail_display_reflects_state()
     }
 
     public function test_watch_detail_display_reflects_state()
index 2b7a3623de7f4f0c699a78c6945a83b588949d3e..3b2da369de5235251e23574e0eb5bc80d07f2d90 100644 (file)
@@ -55,7 +55,7 @@ class UserRoleProvider
      */
     public function guest(): User
     {
      */
     public function guest(): User
     {
-        return User::where('system_name', '=', 'public')->firstOrFail();
+        return User::getDefault();
     }
 
     /**
     }
 
     /**
index 322ab037032f76ea9adb7b3002f7c2f845f1309d..0ab0792bd00228dfb306b7216e7f61a66be894e3 100644 (file)
@@ -5,6 +5,7 @@ namespace Tests;
 use BookStack\Entities\Models\Entity;
 use BookStack\Settings\SettingService;
 use BookStack\Uploads\HttpFetcher;
 use BookStack\Entities\Models\Entity;
 use BookStack\Settings\SettingService;
 use BookStack\Uploads\HttpFetcher;
+use BookStack\Users\Models\User;
 use GuzzleHttp\Client;
 use GuzzleHttp\Handler\MockHandler;
 use GuzzleHttp\HandlerStack;
 use GuzzleHttp\Client;
 use GuzzleHttp\Handler\MockHandler;
 use GuzzleHttp\HandlerStack;
@@ -46,6 +47,7 @@ abstract class TestCase extends BaseTestCase
         $this->permissions = new PermissionsProvider($this->users);
         $this->files = new FileProvider();
 
         $this->permissions = new PermissionsProvider($this->users);
         $this->files = new FileProvider();
 
+        User::clearDefault();
         parent::setUp();
 
         // We can uncomment the below to run tests with failings upon deprecations.
         parent::setUp();
 
         // We can uncomment the below to run tests with failings upon deprecations.