]> BookStack Code Mirror - bookstack/blobdiff - tests/Permissions/RestrictionsTest.php
Update settings.php
[bookstack] / tests / Permissions / RestrictionsTest.php
index cc4211843c125c2d52643800443102860a2f20dd..7d6c1831afdd0eeab6ecceb36b3b5f8127f61981 100644 (file)
@@ -1,18 +1,18 @@
-<?php namespace Tests;
+<?php namespace Tests\Permissions;
 
 use BookStack\Entities\Book;
 use BookStack\Entities\Bookshelf;
 use BookStack\Entities\Chapter;
 use BookStack\Entities\Entity;
 use BookStack\Auth\User;
-use BookStack\Entities\EntityRepo;
 use BookStack\Entities\Page;
+use Tests\BrowserKitTest;
 
 class RestrictionsTest extends BrowserKitTest
 {
 
     /**
-     * @var \BookStack\Auth\User
+     * @var User
      */
     protected $user;
 
@@ -21,7 +21,7 @@ class RestrictionsTest extends BrowserKitTest
      */
     protected $viewer;
 
-    public function setUp()
+    public function setUp(): void
     {
         parent::setUp();
         $this->user = $this->getEditor();
@@ -131,12 +131,12 @@ class RestrictionsTest extends BrowserKitTest
         $bookUrl = $book->getUrl();
         $this->actingAs($this->viewer)
             ->visit($bookUrl)
-            ->dontSeeInElement('.action-buttons', 'New Page')
-            ->dontSeeInElement('.action-buttons', 'New Chapter');
+            ->dontSeeInElement('.actions', 'New Page')
+            ->dontSeeInElement('.actions', 'New Chapter');
         $this->actingAs($this->user)
             ->visit($bookUrl)
-            ->seeInElement('.action-buttons', 'New Page')
-            ->seeInElement('.action-buttons', 'New Chapter');
+            ->seeInElement('.actions', 'New Page')
+            ->seeInElement('.actions', 'New Chapter');
 
         $this->setEntityRestrictions($book, ['view', 'delete', 'update']);
 
@@ -144,8 +144,8 @@ class RestrictionsTest extends BrowserKitTest
             ->see('You do not have permission')->seePageIs('/');
         $this->forceVisit($bookUrl . '/create-page')
             ->see('You do not have permission')->seePageIs('/');
-        $this->visit($bookUrl)->dontSeeInElement('.action-buttons', 'New Page')
-            ->dontSeeInElement('.action-buttons', 'New Chapter');
+        $this->visit($bookUrl)->dontSeeInElement('.actions', 'New Page')
+            ->dontSeeInElement('.actions', 'New Chapter');
 
         $this->setEntityRestrictions($book, ['view', 'create']);
 
@@ -159,8 +159,8 @@ class RestrictionsTest extends BrowserKitTest
             ->type('test content', 'html')
             ->press('Save Page')
             ->seePageIs($bookUrl . '/page/test-page');
-        $this->visit($bookUrl)->seeInElement('.action-buttons', 'New Page')
-            ->seeInElement('.action-buttons', 'New Chapter');
+        $this->visit($bookUrl)->seeInElement('.actions', 'New Page')
+            ->seeInElement('.actions', 'New Chapter');
     }
 
     public function test_book_update_restriction()
@@ -255,13 +255,13 @@ class RestrictionsTest extends BrowserKitTest
         $chapterUrl = $chapter->getUrl();
         $this->actingAs($this->user)
             ->visit($chapterUrl)
-            ->seeInElement('.action-buttons', 'New Page');
+            ->seeInElement('.actions', 'New Page');
 
         $this->setEntityRestrictions($chapter, ['view', 'delete', 'update']);
 
         $this->forceVisit($chapterUrl . '/create-page')
             ->see('You do not have permission')->seePageIs('/');
-        $this->visit($chapterUrl)->dontSeeInElement('.action-buttons', 'New Page');
+        $this->visit($chapterUrl)->dontSeeInElement('.actions', 'New Page');
 
         $this->setEntityRestrictions($chapter, ['view', 'create']);
 
@@ -272,7 +272,7 @@ class RestrictionsTest extends BrowserKitTest
             ->press('Save Page')
             ->seePageIs($chapter->book->getUrl() . '/page/test-page');
 
-        $this->visit($chapterUrl)->seeInElement('.action-buttons', 'New Page');
+        $this->visit($chapterUrl)->seeInElement('.actions', 'New Page');
     }
 
     public function test_chapter_update_restriction()
@@ -327,7 +327,7 @@ class RestrictionsTest extends BrowserKitTest
 
     public function test_page_view_restriction()
     {
-        $page = \BookStack\Entities\Page::first();
+        $page = Page::first();
 
         $pageUrl = $page->getUrl();
         $this->actingAs($this->user)
@@ -367,7 +367,7 @@ class RestrictionsTest extends BrowserKitTest
 
     public function test_page_delete_restriction()
     {
-        $page = \BookStack\Entities\Page::first();
+        $page = Page::first();
 
         $pageUrl = $page->getUrl();
         $this->actingAs($this->user)
@@ -438,7 +438,7 @@ class RestrictionsTest extends BrowserKitTest
 
     public function test_page_restriction_form()
     {
-        $page = \BookStack\Entities\Page::first();
+        $page = Page::first();
         $this->asAdmin()->visit($page->getUrl() . '/permissions')
             ->see('Page Permissions')
             ->check('restricted')
@@ -535,8 +535,8 @@ class RestrictionsTest extends BrowserKitTest
         $bookUrl = $book->getUrl();
         $this->actingAs($this->viewer)
             ->visit($bookUrl)
-            ->dontSeeInElement('.action-buttons', 'New Page')
-            ->dontSeeInElement('.action-buttons', 'New Chapter');
+            ->dontSeeInElement('.actions', 'New Page')
+            ->dontSeeInElement('.actions', 'New Chapter');
 
         $this->setEntityRestrictions($book, ['view', 'delete', 'update']);
 
@@ -544,8 +544,8 @@ class RestrictionsTest extends BrowserKitTest
             ->see('You do not have permission')->seePageIs('/');
         $this->forceVisit($bookUrl . '/create-page')
             ->see('You do not have permission')->seePageIs('/');
-        $this->visit($bookUrl)->dontSeeInElement('.action-buttons', 'New Page')
-            ->dontSeeInElement('.action-buttons', 'New Chapter');
+        $this->visit($bookUrl)->dontSeeInElement('.actions', 'New Page')
+            ->dontSeeInElement('.actions', 'New Chapter');
 
         $this->setEntityRestrictions($book, ['view', 'create']);
 
@@ -559,8 +559,8 @@ class RestrictionsTest extends BrowserKitTest
             ->type('test content', 'html')
             ->press('Save Page')
             ->seePageIs($bookUrl . '/page/test-page');
-        $this->visit($bookUrl)->seeInElement('.action-buttons', 'New Page')
-            ->seeInElement('.action-buttons', 'New Chapter');
+        $this->visit($bookUrl)->seeInElement('.actions', 'New Page')
+            ->seeInElement('.actions', 'New Chapter');
     }
 
     public function test_book_update_restriction_override()
@@ -645,11 +645,9 @@ class RestrictionsTest extends BrowserKitTest
     {
         $firstBook = Book::first();
         $secondBook = Book::find(2);
-        $thirdBook = Book::find(3);
 
         $this->setEntityRestrictions($firstBook, ['view', 'update']);
         $this->setEntityRestrictions($secondBook, ['view']);
-        $this->setEntityRestrictions($thirdBook, ['view', 'update']);
 
         // Test sort page visibility
         $this->actingAs($this->user)->visit($secondBook->getUrl() . '/sort')
@@ -657,9 +655,7 @@ class RestrictionsTest extends BrowserKitTest
                 ->seePageIs('/');
 
         // Check sort page on first book
-        $this->actingAs($this->user)->visit($firstBook->getUrl() . '/sort')
-                ->see($thirdBook->name)
-                ->dontSee($secondBook->name);
+        $this->actingAs($this->user)->visit($firstBook->getUrl() . '/sort');
     }
 
     public function test_book_sort_permission() {
@@ -669,10 +665,8 @@ class RestrictionsTest extends BrowserKitTest
         $this->setEntityRestrictions($firstBook, ['view', 'update']);
         $this->setEntityRestrictions($secondBook, ['view']);
 
-        $firstBookChapter = $this->app[EntityRepo::class]->createFromInput('chapter',
-                ['name' => 'first book chapter'], $firstBook);
-        $secondBookChapter = $this->app[EntityRepo::class]->createFromInput('chapter',
-                ['name' => 'second book chapter'], $secondBook);
+        $firstBookChapter = $this->newChapter(['name' => 'first book chapter'], $firstBook);
+        $secondBookChapter = $this->newChapter(['name' => 'second book chapter'], $secondBook);
 
         // Create request data
         $reqData = [