]> BookStack Code Mirror - bookstack/blob - tests/Permissions/EntityOwnerChangeTest.php
Fix issue BookStackApp#5542 Sorting by name
[bookstack] / tests / Permissions / EntityOwnerChangeTest.php
1 <?php
2
3 namespace Tests\Permissions;
4
5 use BookStack\Users\Models\User;
6 use Tests\TestCase;
7
8 class EntityOwnerChangeTest extends TestCase
9 {
10     public function test_changing_page_owner()
11     {
12         $page = $this->entities->page();
13         $user = User::query()->where('id', '!=', $page->owned_by)->first();
14
15         $this->asAdmin()->put($page->getUrl('permissions'), ['owned_by' => $user->id]);
16         $this->assertDatabaseHas('pages', ['owned_by' => $user->id, 'id' => $page->id]);
17     }
18
19     public function test_changing_chapter_owner()
20     {
21         $chapter = $this->entities->chapter();
22         $user = User::query()->where('id', '!=', $chapter->owned_by)->first();
23
24         $this->asAdmin()->put($chapter->getUrl('permissions'), ['owned_by' => $user->id]);
25         $this->assertDatabaseHas('chapters', ['owned_by' => $user->id, 'id' => $chapter->id]);
26     }
27
28     public function test_changing_book_owner()
29     {
30         $book = $this->entities->book();
31         $user = User::query()->where('id', '!=', $book->owned_by)->first();
32
33         $this->asAdmin()->put($book->getUrl('permissions'), ['owned_by' => $user->id]);
34         $this->assertDatabaseHas('books', ['owned_by' => $user->id, 'id' => $book->id]);
35     }
36
37     public function test_changing_shelf_owner()
38     {
39         $shelf = $this->entities->shelf();
40         $user = User::query()->where('id', '!=', $shelf->owned_by)->first();
41
42         $this->asAdmin()->put($shelf->getUrl('permissions'), ['owned_by' => $user->id]);
43         $this->assertDatabaseHas('bookshelves', ['owned_by' => $user->id, 'id' => $shelf->id]);
44     }
45 }