]> BookStack Code Mirror - bookstack/blob - tests/Permissions/EntityOwnerChangeTest.php
Merge branch 'footer-links' of git://github.com/james-geiger/BookStack into james...
[bookstack] / tests / Permissions / EntityOwnerChangeTest.php
1 <?php namespace Tests\Permissions;
2
3 use BookStack\Auth\User;
4 use BookStack\Entities\Models\Book;
5 use BookStack\Entities\Models\Bookshelf;
6 use BookStack\Entities\Models\Chapter;
7 use BookStack\Entities\Models\Page;
8 use Illuminate\Support\Str;
9 use Tests\TestCase;
10
11 class EntityOwnerChangeTest extends TestCase
12 {
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
50 }