Tested new ownership + (delete/change) systems
This commit is contained in:
parent
b43f997dab
commit
de989ffa9a
2 changed files with 94 additions and 0 deletions
50
tests/Permissions/EntityOwnerChangeTest.php
Normal file
50
tests/Permissions/EntityOwnerChangeTest.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php namespace Tests\Permissions;
|
||||
|
||||
use BookStack\Auth\User;
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Models\Bookshelf;
|
||||
use BookStack\Entities\Models\Chapter;
|
||||
use BookStack\Entities\Models\Page;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EntityOwnerChangeTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_changing_page_owner()
|
||||
{
|
||||
$page = Page::query()->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]);
|
||||
}
|
||||
|
||||
}
|
44
tests/User/UserManagementTest.php
Normal file
44
tests/User/UserManagementTest.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php namespace Tests\User;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Auth\User;
|
||||
use BookStack\Entities\Models\Page;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserManagementTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_delete()
|
||||
{
|
||||
$editor = $this->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,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue