diff --git a/tests/Permissions/EntityOwnerChangeTest.php b/tests/Permissions/EntityOwnerChangeTest.php new file mode 100644 index 000000000..2f06bff2e --- /dev/null +++ b/tests/Permissions/EntityOwnerChangeTest.php @@ -0,0 +1,50 @@ +first(); + $user = User::query()->where('id', '!=', $page->owned_by)->first(); + + $this->asAdmin()->put($page->getUrl('permissions'), ['owned_by' => $user->id]); + $this->assertDatabaseHas('pages', ['owned_by' => $user->id, 'id' => $page->id]); + } + + public function test_changing_chapter_owner() + { + $chapter = Chapter::query()->first(); + $user = User::query()->where('id', '!=', $chapter->owned_by)->first(); + + $this->asAdmin()->put($chapter->getUrl('permissions'), ['owned_by' => $user->id]); + $this->assertDatabaseHas('chapters', ['owned_by' => $user->id, 'id' => $chapter->id]); + } + + public function test_changing_book_owner() + { + $book = Book::query()->first(); + $user = User::query()->where('id', '!=', $book->owned_by)->first(); + + $this->asAdmin()->put($book->getUrl('permissions'), ['owned_by' => $user->id]); + $this->assertDatabaseHas('books', ['owned_by' => $user->id, 'id' => $book->id]); + } + + public function test_changing_shelf_owner() + { + $shelf = Bookshelf::query()->first(); + $user = User::query()->where('id', '!=', $shelf->owned_by)->first(); + + $this->asAdmin()->put($shelf->getUrl('permissions'), ['owned_by' => $user->id]); + $this->assertDatabaseHas('bookshelves', ['owned_by' => $user->id, 'id' => $shelf->id]); + } + +} \ No newline at end of file diff --git a/tests/User/UserManagementTest.php b/tests/User/UserManagementTest.php new file mode 100644 index 000000000..d99d61401 --- /dev/null +++ b/tests/User/UserManagementTest.php @@ -0,0 +1,44 @@ +getEditor(); + $resp = $this->asAdmin()->delete("settings/users/{$editor->id}"); + $resp->assertRedirect("/settings/users"); + $resp = $this->followRedirects($resp); + + $resp->assertSee("User successfully removed"); + $this->assertActivityExists(ActivityType::USER_DELETE); + + $this->assertDatabaseMissing('users', ['id' => $editor->id]); + } + + public function test_delete_offers_migrate_option() + { + $editor = $this->getEditor(); + $resp = $this->asAdmin()->get("settings/users/{$editor->id}/delete"); + $resp->assertSee("Migrate Ownership"); + $resp->assertSee("new_owner_id"); + } + + public function test_delete_with_new_owner_id_changes_ownership() + { + $page = Page::query()->first(); + $owner = $page->ownedBy; + $newOwner = User::query()->where('id', '!=' , $owner->id)->first(); + + $this->asAdmin()->delete("settings/users/{$owner->id}", ['new_owner_id' => $newOwner->id]); + $this->assertDatabaseHas('pages', [ + 'id' => $page->id, + 'owned_by' => $newOwner->id, + ]); + } +} \ No newline at end of file