]> BookStack Code Mirror - bookstack/blobdiff - tests/Permissions/RestrictionsTest.php
Finished migration of last angular code
[bookstack] / tests / Permissions / RestrictionsTest.php
index 0aa1389a6e293b87e1f489f13793275601e23fd6..faceab92c7322dd7c00f662e70673a2ceb8eae9a 100644 (file)
@@ -1,6 +1,6 @@
-<?php
+<?php namespace Tests;
 
-class RestrictionsTest extends TestCase
+class RestrictionsTest extends BrowserKitTest
 {
     protected $user;
     protected $viewer;
@@ -9,9 +9,9 @@ class RestrictionsTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $this->user = $this->getNewUser();
+        $this->user = $this->getEditor();
         $this->viewer = $this->getViewer();
-        $this->restrictionService = $this->app[\BookStack\Services\RestrictionService::class];
+        $this->restrictionService = $this->app[\BookStack\Services\PermissionService::class];
     }
 
     protected function getViewer()
@@ -23,30 +23,30 @@ class RestrictionsTest extends TestCase
     }
 
     /**
-     * Manually set some restrictions on an entity.
+     * Manually set some permissions on an entity.
      * @param \BookStack\Entity $entity
      * @param $actions
      */
     protected function setEntityRestrictions(\BookStack\Entity $entity, $actions)
     {
         $entity->restricted = true;
-        $entity->restrictions()->delete();
+        $entity->permissions()->delete();
         $role = $this->user->roles->first();
         $viewerRole = $this->viewer->roles->first();
         foreach ($actions as $action) {
-            $entity->restrictions()->create([
+            $entity->permissions()->create([
                 'role_id' => $role->id,
                 'action' => strtolower($action)
             ]);
-            $entity->restrictions()->create([
+            $entity->permissions()->create([
                 'role_id' => $viewerRole->id,
                 'action' => strtolower($action)
             ]);
         }
         $entity->save();
-        $entity->load('restrictions');
-        $this->restrictionService->buildEntityPermissionsForEntity($entity);
         $entity->load('permissions');
+        $this->restrictionService->buildJointPermissionsForEntity($entity);
+        $entity->load('jointPermissions');
     }
 
     public function test_book_view_restriction()
@@ -65,9 +65,9 @@ class RestrictionsTest extends TestCase
         $this->forceVisit($bookUrl)
             ->see('Book not found');
         $this->forceVisit($bookPage->getUrl())
-            ->see('Book not found');
+            ->see('Page not found');
         $this->forceVisit($bookChapter->getUrl())
-            ->see('Book not found');
+            ->see('Chapter not found');
 
         $this->setEntityRestrictions($book, ['view']);
 
@@ -226,6 +226,7 @@ class RestrictionsTest extends TestCase
             ->type('test content', 'html')
             ->press('Save Page')
             ->seePageIs($chapter->book->getUrl() . '/page/test-page');
+
         $this->visit($chapterUrl)->seeInElement('.action-buttons', 'New Page');
     }
 
@@ -348,7 +349,7 @@ class RestrictionsTest extends TestCase
             ->check('restrictions[2][view]')
             ->press('Save Permissions')
             ->seeInDatabase('books', ['id' => $book->id, 'restricted' => true])
-            ->seeInDatabase('restrictions', [
+            ->seeInDatabase('entity_permissions', [
                 'restrictable_id' => $book->id,
                 'restrictable_type' => 'BookStack\Book',
                 'role_id' => '2',
@@ -365,7 +366,7 @@ class RestrictionsTest extends TestCase
             ->check('restrictions[2][update]')
             ->press('Save Permissions')
             ->seeInDatabase('chapters', ['id' => $chapter->id, 'restricted' => true])
-            ->seeInDatabase('restrictions', [
+            ->seeInDatabase('entity_permissions', [
                 'restrictable_id' => $chapter->id,
                 'restrictable_type' => 'BookStack\Chapter',
                 'role_id' => '2',
@@ -382,7 +383,7 @@ class RestrictionsTest extends TestCase
             ->check('restrictions[2][delete]')
             ->press('Save Permissions')
             ->seeInDatabase('pages', ['id' => $page->id, 'restricted' => true])
-            ->seeInDatabase('restrictions', [
+            ->seeInDatabase('entity_permissions', [
                 'restrictable_id' => $page->id,
                 'restrictable_type' => 'BookStack\Page',
                 'role_id' => '2',
@@ -522,4 +523,21 @@ class RestrictionsTest extends TestCase
             ->see('Delete Chapter');
     }
 
+    public function test_page_visible_if_has_permissions_when_book_not_visible()
+    {
+        $book = \BookStack\Book::first();
+        $bookChapter = $book->chapters->first();
+        $bookPage = $bookChapter->pages->first();
+
+        $this->setEntityRestrictions($book, []);
+        $this->setEntityRestrictions($bookPage, ['view']);
+
+        $this->actingAs($this->viewer);
+        $this->get($bookPage->getUrl());
+        $this->assertResponseOk();
+        $this->see($bookPage->name);
+        $this->dontSee(substr($book->name, 0, 15));
+        $this->dontSee(substr($bookChapter->name, 0, 15));
+    }
+
 }