mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-14 17:44:17 -08:00
74fbc23823
Signed-off-by: snipe <snipe@snipe.net>
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Locations\Ui;
|
|
|
|
use App\Models\Location;
|
|
use App\Models\Company;
|
|
use App\Models\User;
|
|
use Tests\TestCase;
|
|
|
|
class CreateLocationsTest extends TestCase
|
|
{
|
|
public function testPermissionRequiredToCreateLocation()
|
|
{
|
|
$this->actingAs(User::factory()->create())
|
|
->post(route('locations.store'), [
|
|
'name' => 'Test Location',
|
|
'company_id' => Company::factory()->create()->id
|
|
])
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function testUserCanCreateLocations()
|
|
{
|
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
|
|
|
$this->actingAs(User::factory()->superuser()->create())
|
|
->post(route('locations.store'), [
|
|
'name' => 'Test Location',
|
|
'company_id' => Company::factory()->create()->id
|
|
])
|
|
->assertRedirect(route('locations.index'));
|
|
|
|
$this->assertTrue(Location::where('name', 'Test Location')->exists());
|
|
}
|
|
|
|
public function testUserCannotCreateLocationsWithInvalidParent()
|
|
{
|
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
|
|
|
$this->actingAs(User::factory()->superuser()->create())
|
|
->from(route('locations.create'))
|
|
->post(route('locations.store'), [
|
|
'name' => 'Test Location',
|
|
'parent_id' => '100000000'
|
|
])
|
|
->assertRedirect(route('locations.create'));
|
|
|
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
|
}
|
|
|
|
}
|