mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-24 04:03:34 -08:00
Added non-circular tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
f32bf35c22
commit
a8ddb2f44a
|
@ -33,4 +33,24 @@ class CreateLocationsTest extends TestCase
|
|||
|
||||
}
|
||||
|
||||
public function testUserCannotCreateLocationsThatAreTheirOwnParent()
|
||||
{
|
||||
$location = Location::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->patchJson(route('api.locations.update', $location), [
|
||||
'parent_id' => $location->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
->assertJson([
|
||||
'messages' => [
|
||||
'parent_id' => ['The parent id must not create a circular reference.'],
|
||||
],
|
||||
])
|
||||
->json();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
37
tests/Feature/Locations/Ui/CreateLocationsTest.php
Normal file
37
tests/Feature/Locations/Ui/CreateLocationsTest.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?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());
|
||||
}
|
||||
|
||||
|
||||
}
|
57
tests/Feature/Locations/Ui/UpdateLocationsTest.php
Normal file
57
tests/Feature/Locations/Ui/UpdateLocationsTest.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Locations\Ui;
|
||||
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateLocationsTest extends TestCase
|
||||
{
|
||||
public function testPermissionRequiredToStoreLocation()
|
||||
{
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post(route('locations.store'), [
|
||||
'name' => 'Test Location',
|
||||
])
|
||||
->assertStatus(403)
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
|
||||
public function testUserCanEditLocations()
|
||||
{
|
||||
$location = Location::factory()->create(['name' => 'Test Location']);
|
||||
$this->assertTrue(Location::where('name', 'Test Location')->exists());
|
||||
|
||||
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||
->put(route('locations.update', ['location' => $location]), [
|
||||
'name' => 'Test Location Edited',
|
||||
])
|
||||
->assertStatus(302)
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('locations.index'));
|
||||
|
||||
$this->followRedirects($response)->assertSee('Success');
|
||||
$this->assertTrue(Location::where('name', 'Test Location Edited')->exists());
|
||||
}
|
||||
|
||||
public function testUserCannotEditLocationsToMakeThemTheirOwnParent()
|
||||
{
|
||||
$location = Location::factory()->create();
|
||||
|
||||
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||
->from(route('locations.edit', ['location' => $location->id]))
|
||||
->put(route('locations.update', ['location' => $location]), [
|
||||
'name' => 'Test Location',
|
||||
'parent_id' => $location->id,
|
||||
])
|
||||
->assertRedirect(route('locations.edit', ['location' => $location]));
|
||||
|
||||
$this->followRedirects($response)->assertSee(trans('general.error'));
|
||||
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue