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