snipe-it/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php
snipe 16d65631aa Removed duplicate tests
Signed-off-by: snipe <snipe@snipe.net>
2024-07-05 07:54:22 +01:00

66 lines
2.4 KiB
PHP

<?php
namespace Tests\Feature\AssetModels\Ui;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\User;
use Tests\TestCase;
class UpdateAssetModelsTest extends TestCase
{
public function testPermissionRequiredToStoreAssetModel()
{
$this->actingAs(User::factory()->create())
->post(route('models.store'), [
'name' => 'Test Model',
'category_id' => Category::factory()->create()->id
])
->assertStatus(403)
->assertForbidden();
}
public function testUserCanEditAssetModels()
{
$category = Category::factory()->forAssets()->create();
$model = AssetModel::factory()->create(['name' => 'Test Model', 'category_id' => $category->id]);
$this->assertTrue(AssetModel::where('name', 'Test Model')->exists());
$response = $this->actingAs(User::factory()->superuser()->create())
->put(route('models.update', ['model' => $model]), [
'name' => 'Test Model Edited',
'category_id' => $model->category_id,
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('models.index'));
$this->followRedirects($response)->assertSee('Success');
$this->assertTrue(AssetModel::where('name', 'Test Model Edited')->exists());
}
public function testUserCannotChangeAssetModelCategoryType()
{
$category = Category::factory()->forAssets()->create();
$model = AssetModel::factory()->create(['name' => 'Test Model', 'category_id' => $category->id]);
$this->assertTrue(AssetModel::where('name', 'Test Model')->exists());
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('models.edit', ['model' => $model->id]))
->put(route('models.update', ['model' => $model]), [
'name' => 'Test Model Edited',
'category_id' => Category::factory()->forAccessories()->create()->id,
])
->assertSessionHasErrors(['category_type'])
->assertInvalid(['category_type'])
->assertStatus(302)
->assertRedirect(route('models.edit', ['model' => $model->id]));
$this->followRedirects($response)->assertSee(trans('general.error'));
$this->assertFalse(AssetModel::where('name', 'Test Model Edited')->exists());
}
}