]> BookStack Code Mirror - bookstack/blobdiff - tests/Permissions/RolesTest.php
Updated attachment links to have dropdown for open type
[bookstack] / tests / Permissions / RolesTest.php
index 5689caf7b93aa7db7fd4ace4df2dea2dec7eb2f5..fe2139e59e786f0038119ed0c4b4b3706a230b63 100644 (file)
@@ -19,7 +19,7 @@ class RolesTest extends TestCase
 {
     protected $user;
 
-    public function setUp(): void
+    protected function setUp(): void
     {
         parent::setUp();
         $this->user = $this->getViewer();
@@ -27,7 +27,7 @@ class RolesTest extends TestCase
 
     public function test_admin_can_see_settings()
     {
-        $this->asAdmin()->get('/settings')->assertSee('Settings');
+        $this->asAdmin()->get('/settings/features')->assertSee('Settings');
     }
 
     public function test_cannot_delete_admin_role()
@@ -58,7 +58,7 @@ class RolesTest extends TestCase
         $testRoleUpdateName = 'An Super Updated role';
 
         // Creation
-        $resp = $this->asAdmin()->get('/settings');
+        $resp = $this->asAdmin()->get('/settings/features');
         $resp->assertElementContains('a[href="' . url('/settings/roles') . '"]', 'Roles');
 
         $resp = $this->get('/settings/roles');
@@ -69,7 +69,7 @@ class RolesTest extends TestCase
 
         $resp = $this->post('/settings/roles/new', [
             'display_name' => $testRoleName,
-            'description' => $testRoleDesc,
+            'description'  => $testRoleDesc,
         ]);
         $resp->assertRedirect('/settings/roles');
 
@@ -78,7 +78,7 @@ class RolesTest extends TestCase
         $resp->assertSee($testRoleDesc);
         $this->assertDatabaseHas('roles', [
             'display_name' => $testRoleName,
-            'description' => $testRoleDesc,
+            'description'  => $testRoleDesc,
             'mfa_enforced' => false,
         ]);
 
@@ -93,13 +93,13 @@ class RolesTest extends TestCase
 
         $resp = $this->put('/settings/roles/' . $role->id, [
             'display_name' => $testRoleUpdateName,
-            'description' => $testRoleDesc,
+            'description'  => $testRoleDesc,
             'mfa_enforced' => 'true',
         ]);
         $resp->assertRedirect('/settings/roles');
         $this->assertDatabaseHas('roles', [
             'display_name' => $testRoleUpdateName,
-            'description' => $testRoleDesc,
+            'description'  => $testRoleDesc,
             'mfa_enforced' => true,
         ]);
 
@@ -163,6 +163,23 @@ class RolesTest extends TestCase
         $this->assertEquals($this->user->id, $roleA->users()->first()->id);
     }
 
+    public function test_copy_role_button_shown()
+    {
+        /** @var Role $role */
+        $role = Role::query()->first();
+        $resp = $this->asAdmin()->get("/settings/roles/{$role->id}");
+        $resp->assertElementContains('a[href$="/roles/new?copy_from=' . $role->id . '"]', 'Copy');
+    }
+
+    public function test_copy_from_param_on_create_prefills_with_other_role_data()
+    {
+        /** @var Role $role */
+        $role = Role::query()->first();
+        $resp = $this->asAdmin()->get("/settings/roles/new?copy_from={$role->id}");
+        $resp->assertOk();
+        $resp->assertElementExists('input[name="display_name"][value="' . ($role->display_name . ' (Copy)') . '"]');
+    }
+
     public function test_manage_user_permission()
     {
         $this->actingAs($this->user)->get('/settings/users')->assertRedirect('/');
@@ -173,11 +190,11 @@ class RolesTest extends TestCase
     public function test_manage_users_permission_shows_link_in_header_if_does_not_have_settings_manage_permision()
     {
         $usersLink = 'href="' . url('/settings/users') . '"';
-        $this->actingAs($this->user)->get('/')->assertDontSee($usersLink);
+        $this->actingAs($this->user)->get('/')->assertDontSee($usersLink, false);
         $this->giveUserPermissions($this->user, ['users-manage']);
-        $this->actingAs($this->user)->get('/')->assertSee($usersLink);
+        $this->actingAs($this->user)->get('/')->assertSee($usersLink, false);
         $this->giveUserPermissions($this->user, ['settings-manage', 'users-manage']);
-        $this->actingAs($this->user)->get('/')->assertDontSee($usersLink);
+        $this->actingAs($this->user)->get('/')->assertDontSee($usersLink, false);
     }
 
     public function test_user_cannot_change_email_unless_they_have_manage_users_permission()
@@ -230,13 +247,13 @@ class RolesTest extends TestCase
 
     public function test_settings_manage_permission()
     {
-        $this->actingAs($this->user)->get('/settings')->assertRedirect('/');
+        $this->actingAs($this->user)->get('/settings/features')->assertRedirect('/');
         $this->giveUserPermissions($this->user, ['settings-manage']);
-        $this->get('/settings')->assertOk();
+        $this->get('/settings/features')->assertOk();
 
-        $resp = $this->post('/settings', []);
-        $resp->assertRedirect('/settings');
-        $resp = $this->get('/settings');
+        $resp = $this->post('/settings/features', []);
+        $resp->assertRedirect('/settings/features');
+        $resp = $this->get('/settings/features');
         $resp->assertSee('Settings saved');
     }
 
@@ -321,7 +338,7 @@ class RolesTest extends TestCase
         ]);
 
         $this->post('/shelves', [
-            'name' => 'test shelf',
+            'name'        => 'test shelf',
             'description' => 'shelf desc',
         ])->assertRedirect('/shelves/test-shelf');
     }
@@ -402,7 +419,7 @@ class RolesTest extends TestCase
         ]);
 
         $this->post('/books', [
-            'name' => 'test book',
+            'name'        => 'test book',
             'description' => 'book desc',
         ])->assertRedirect('/books/test-book');
     }
@@ -480,7 +497,7 @@ class RolesTest extends TestCase
         ]);
 
         $this->post($ownBook->getUrl('/create-chapter'), [
-            'name' => 'test chapter',
+            'name'        => 'test chapter',
             'description' => 'chapter desc',
         ])->assertRedirect($ownBook->getUrl('/chapter/test-chapter'));
 
@@ -499,7 +516,7 @@ class RolesTest extends TestCase
         ]);
 
         $this->post($book->getUrl('/create-chapter'), [
-            'name' => 'test chapter',
+            'name'        => 'test chapter',
             'description' => 'chapter desc',
         ])->assertRedirect($book->getUrl('/chapter/test-chapter'));
     }
@@ -745,7 +762,7 @@ class RolesTest extends TestCase
 
     public function test_public_role_visible_in_default_role_setting()
     {
-        $this->asAdmin()->get('/settings')
+        $this->asAdmin()->get('/settings/registration')
             ->assertElementExists('[data-system-role-name="admin"]')
             ->assertElementExists('[data-system-role-name="public"]');
     }
@@ -769,10 +786,10 @@ class RolesTest extends TestCase
         $this->giveUserPermissions($this->user, ['image-update-all']);
         /** @var Page $page */
         $page = Page::query()->first();
-        $image = factory(Image::class)->create([
+        $image = Image::factory()->create([
             'uploaded_to' => $page->id,
-            'created_by' => $this->user->id,
-            'updated_by' => $this->user->id,
+            'created_by'  => $this->user->id,
+            'updated_by'  => $this->user->id,
         ]);
 
         $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403);
@@ -789,7 +806,7 @@ class RolesTest extends TestCase
         $admin = $this->getAdmin();
         /** @var Page $page */
         $page = Page::query()->first();
-        $image = factory(Image::class)->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);
+        $image = Image::factory()->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);
 
         $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403);
 
@@ -825,14 +842,14 @@ class RolesTest extends TestCase
     {
         $admin = $this->getAdmin();
         // Book links
-        $book = factory(Book::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);
+        $book = Book::factory()->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);
         $this->regenEntityPermissions($book);
         $this->actingAs($this->getViewer())->get($book->getUrl())
             ->assertDontSee('Create a new page')
             ->assertDontSee('Add a chapter');
 
         // Chapter links
-        $chapter = factory(Chapter::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id, 'book_id' => $book->id]);
+        $chapter = Chapter::factory()->create(['created_by' => $admin->id, 'updated_by' => $admin->id, 'book_id' => $book->id]);
         $this->regenEntityPermissions($chapter);
         $this->actingAs($this->getViewer())->get($chapter->getUrl())
             ->assertDontSee('Create a new page')
@@ -926,13 +943,15 @@ class RolesTest extends TestCase
 
     private function addComment(Page $page): TestResponse
     {
-        $comment = factory(Comment::class)->make();
+        $comment = Comment::factory()->make();
+
         return $this->postJson("/comment/$page->id", $comment->only('text', 'html'));
     }
 
     private function updateComment(Comment $comment): TestResponse
     {
-        $commentData = factory(Comment::class)->make();
+        $commentData = Comment::factory()->make();
+
         return $this->putJson("/comment/{$comment->id}", $commentData->only('text', 'html'));
     }