mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
ea8d390596
Signed-off-by: snipe <snipe@snipe.net>
60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Users;
|
|
|
|
use App\Models\Location;
|
|
use App\Models\User;
|
|
use Laravel\Passport\Passport;
|
|
use Tests\TestCase;
|
|
|
|
class DeleteUsersTest extends TestCase
|
|
{
|
|
|
|
|
|
public function testDisallowUserDeletionIfStillManagingPeople()
|
|
{
|
|
$manager = User::factory()->create();
|
|
User::factory()->count(3)->create(['manager_id' => $manager->id]);
|
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
|
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())
|
|
->delete(route('users.destroy', $manager->id))
|
|
->assertStatus(302)
|
|
->assertRedirect(route('users.index'));
|
|
}
|
|
|
|
public function testDisallowUserDeletionIfStillManagingLocations()
|
|
{
|
|
$manager = User::factory()->create();
|
|
Location::factory()->count(3)->create(['manager_id' => $manager->id]);
|
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertFalse($manager->isDeletable());
|
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())
|
|
->delete(route('users.destroy', $manager->id))
|
|
->assertStatus(302)
|
|
->assertRedirect(route('users.index'));
|
|
}
|
|
|
|
public function testAllowUserDeletionIfNotManagingLocations()
|
|
{
|
|
$manager = User::factory()->create();
|
|
$this->actingAs(User::factory()->deleteUsers()->create())->assertTrue($manager->isDeletable());
|
|
|
|
$this->actingAs(User::factory()->deleteUsers()->create())
|
|
->delete(route('users.destroy', $manager->id))
|
|
->assertStatus(302)
|
|
->assertRedirect(route('users.index'));
|
|
}
|
|
|
|
public function testDisallowUserDeletionIfNoDeletePermissions()
|
|
{
|
|
$manager = User::factory()->create();
|
|
Location::factory()->create(['manager_id' => $manager->id]);
|
|
$this->actingAs(User::factory()->editUsers()->create())->assertFalse($manager->isDeletable());
|
|
}
|
|
|
|
|
|
}
|