]> BookStack Code Mirror - bookstack/blobdiff - tests/Permissions/RolesTest.php
Updated entity restrictions to allow permissions, Not just restrict
[bookstack] / tests / Permissions / RolesTest.php
index baba208f118ebd60f4affe596b1175bbaa958213..8ecdb37a383b70b1a86f4fdcd250efb24a92ce74 100644 (file)
@@ -129,14 +129,14 @@ class RolesTest extends TestCase
     {
         $page = \BookStack\Page::take(1)->get()->first();
         $this->actingAs($this->user)->visit($page->getUrl())
-            ->dontSee('Restrict')
-            ->visit($page->getUrl() . '/restrict')
+            ->dontSee('Permissions')
+            ->visit($page->getUrl() . '/permissions')
             ->seePageIs('/');
         $this->giveUserPermissions($this->user, ['restrictions-manage-all']);
         $this->actingAs($this->user)->visit($page->getUrl())
-            ->see('Restrict')
-            ->click('Restrict')
-            ->see('Page Restrictions')->seePageIs($page->getUrl() . '/restrict');
+            ->see('Permissions')
+            ->click('Permissions')
+            ->see('Page Permissions')->seePageIs($page->getUrl() . '/permissions');
     }
 
     public function test_restrictions_manage_own_permission()
@@ -145,27 +145,27 @@ class RolesTest extends TestCase
         $content = $this->createEntityChainBelongingToUser($this->user);
         // Check can't restrict other's content
         $this->actingAs($this->user)->visit($otherUsersPage->getUrl())
-            ->dontSee('Restrict')
-            ->visit($otherUsersPage->getUrl() . '/restrict')
+            ->dontSee('Permissions')
+            ->visit($otherUsersPage->getUrl() . '/permissions')
             ->seePageIs('/');
         // Check can't restrict own content
         $this->actingAs($this->user)->visit($content['page']->getUrl())
-            ->dontSee('Restrict')
-            ->visit($content['page']->getUrl() . '/restrict')
+            ->dontSee('Permissions')
+            ->visit($content['page']->getUrl() . '/permissions')
             ->seePageIs('/');
 
         $this->giveUserPermissions($this->user, ['restrictions-manage-own']);
 
         // Check can't restrict other's content
         $this->actingAs($this->user)->visit($otherUsersPage->getUrl())
-            ->dontSee('Restrict')
-            ->visit($otherUsersPage->getUrl() . '/restrict')
+            ->dontSee('Permissions')
+            ->visit($otherUsersPage->getUrl() . '/permissions')
             ->seePageIs('/');
         // Check can restrict own content
         $this->actingAs($this->user)->visit($content['page']->getUrl())
-            ->see('Restrict')
-            ->click('Restrict')
-            ->seePageIs($content['page']->getUrl() . '/restrict');
+            ->see('Permissions')
+            ->click('Permissions')
+            ->seePageIs($content['page']->getUrl() . '/permissions');
     }
 
     /**
@@ -392,14 +392,28 @@ class RolesTest extends TestCase
 
         $baseUrl = $ownBook->getUrl() . '/page';
 
-        $this->checkAccessPermission('page-create-own', [
-            $baseUrl . '/create',
-            $ownChapter->getUrl() . '/create-page'
-        ], [
+        $createUrl = $baseUrl . '/create';
+        $createUrlChapter = $ownChapter->getUrl() . '/create-page';
+        $accessUrls = [$createUrl, $createUrlChapter];
+
+        foreach ($accessUrls as $url) {
+            $this->actingAs($this->user)->visit('/')->visit($url)
+                ->seePageIs('/');
+        }
+
+        $this->checkAccessPermission('page-create-own', [], [
             $ownBook->getUrl() => 'New Page',
             $ownChapter->getUrl() => 'New Page'
         ]);
 
+        $this->giveUserPermissions($this->user, ['page-create-own']);
+
+        foreach ($accessUrls as $index => $url) {
+            $this->actingAs($this->user)->visit('/')->visit($url);
+            $expectedUrl = \BookStack\Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl();
+            $this->seePageIs($expectedUrl);
+        }
+
         $this->visit($baseUrl . '/create')
             ->type('test page', 'name')
             ->type('page desc', 'html')
@@ -421,14 +435,29 @@ class RolesTest extends TestCase
         $book = \BookStack\Book::take(1)->get()->first();
         $chapter = \BookStack\Chapter::take(1)->get()->first();
         $baseUrl = $book->getUrl() . '/page';
-        $this->checkAccessPermission('page-create-all', [
-            $baseUrl . '/create',
-            $chapter->getUrl() . '/create-page'
-        ], [
+        $createUrl = $baseUrl . '/create';
+
+        $createUrlChapter = $chapter->getUrl() . '/create-page';
+        $accessUrls = [$createUrl, $createUrlChapter];
+
+        foreach ($accessUrls as $url) {
+            $this->actingAs($this->user)->visit('/')->visit($url)
+                ->seePageIs('/');
+        }
+
+        $this->checkAccessPermission('page-create-all', [], [
             $book->getUrl() => 'New Page',
             $chapter->getUrl() => 'New Page'
         ]);
 
+        $this->giveUserPermissions($this->user, ['page-create-all']);
+
+        foreach ($accessUrls as $index => $url) {
+            $this->actingAs($this->user)->visit('/')->visit($url);
+            $expectedUrl = \BookStack\Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl();
+            $this->seePageIs($expectedUrl);
+        }
+
         $this->visit($baseUrl . '/create')
             ->type('test page', 'name')
             ->type('page desc', 'html')