mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Moved tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
7e3d66ec53
commit
acaceb4103
97
tests/Feature/Users/DeleteUserTest.php
Normal file
97
tests/Feature/Users/DeleteUserTest.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Users;
|
||||
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
use App\Notifications\CurrentInventory;
|
||||
|
||||
class DeleteUserTest extends TestCase
|
||||
{
|
||||
|
||||
public function testUserWithoutCompanyPermissionsCannotViewPrintAllInventoryPage()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
//$this->withoutExceptionHandling();
|
||||
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$superuser = User::factory()->superuser()->create();
|
||||
$user = User::factory()->for($companyB)->create();
|
||||
|
||||
$this->actingAs(User::factory()->viewUsers()->for($companyA)->create())
|
||||
->get(route('users.print', ['userId' => $user->id]))
|
||||
->assertStatus(403);
|
||||
|
||||
$this->actingAs(User::factory()->viewUsers()->for($companyB)->create())
|
||||
->get(route('users.print', ['userId' => $user->id]))
|
||||
->assertStatus(200);
|
||||
|
||||
$this->actingAs($superuser)
|
||||
->get(route('users.print', ['userId' => $user->id]))
|
||||
->assertOk()
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
public function testUserWithoutCompanyPermissionsCannotSendInventory()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$superuser = User::factory()->superuser()->create();
|
||||
$user = User::factory()->for($companyB)->create();
|
||||
|
||||
$this->actingAs(User::factory()->viewUsers()->for($companyA)->create())
|
||||
->post(route('users.email', ['userId' => $user->id]))
|
||||
->assertStatus(403);
|
||||
|
||||
$this->actingAs(User::factory()->viewUsers()->for($companyB)->create())
|
||||
->post(route('users.email', ['userId' => $user->id]))
|
||||
->assertStatus(302);
|
||||
|
||||
$this->actingAs($superuser)
|
||||
->post(route('users.email', ['userId' => $user->id]))
|
||||
->assertStatus(302);
|
||||
|
||||
Notification::assertSentTo(
|
||||
[$user], CurrentInventory::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testUserWithoutCompanyPermissionsCannotDeleteUser()
|
||||
{
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$superuser = User::factory()->superuser()->create();
|
||||
$userFromA = User::factory()->for($companyA)->create();
|
||||
$userFromB = User::factory()->for($companyB)->create();
|
||||
|
||||
$this->followingRedirects()->actingAs(User::factory()->deleteUsers()->for($companyA)->create())
|
||||
->delete(route('users.destroy', ['user' => $userFromB->id]))
|
||||
->assertStatus(403);
|
||||
|
||||
$this->actingAs(User::factory()->deleteUsers()->for($companyA)->create())
|
||||
->delete(route('users.destroy', ['user' => $userFromA->id]))
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('users.index'));
|
||||
|
||||
$this->actingAs($superuser)
|
||||
->post(route('users.email', ['userId' => $userFromA->id]))
|
||||
->assertStatus(302);
|
||||
|
||||
$this->actingAs($superuser)
|
||||
->post(route('users.email', ['userId' => $userFromB->id]))
|
||||
->assertStatus(302);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -55,6 +55,7 @@ class ViewUserTest extends TestCase
|
|||
|
||||
public function testUserWithoutCompanyPermissionsCannotSendInventory()
|
||||
{
|
||||
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
@ -81,26 +82,4 @@ class ViewUserTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testUserWithoutCompanyPermissionsCannotDeleteUser()
|
||||
{
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$superuser = User::factory()->superuser()->create();
|
||||
$userFromA = User::factory()->for($companyA)->create();
|
||||
$userFromB = User::factory()->for($companyB)->create();
|
||||
|
||||
$this->followingRedirects()->actingAs(User::factory()->deleteUsers()->for($companyA)->create())
|
||||
->delete(route('users.destroy', ['user' => $userFromB->id]))
|
||||
->assertStatus(403);
|
||||
|
||||
$this->actingAs(User::factory()->deleteUsers()->for($companyA)->create())
|
||||
->delete(route('users.destroy', ['user' => $userFromA->id]))
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('users.index'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue