mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-14 17:44:17 -08:00
1f28bf14c1
Signed-off-by: snipe <snipe@snipe.net>
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Categories\Ui;
|
|
|
|
use App\Models\AssetModel;
|
|
use App\Models\Category;
|
|
use App\Models\User;
|
|
use Tests\TestCase;
|
|
|
|
class CreateCategoriesTest extends TestCase
|
|
{
|
|
public function testPermissionRequiredToCreateCategories()
|
|
{
|
|
$this->actingAs(User::factory()->create())
|
|
->post(route('categories.store'), [
|
|
'name' => 'Test Category',
|
|
'category_type' => 'asset',
|
|
])
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function testUserCanCreateCategories()
|
|
{
|
|
$this->assertFalse(Category::where('name', 'Test Category')->exists());
|
|
|
|
$this->actingAs(User::factory()->superuser()->create())
|
|
->post(route('categories.store'), [
|
|
'name' => 'Test Category',
|
|
'category_type' => 'asset'
|
|
])
|
|
->assertRedirect(route('categories.index'));
|
|
|
|
$this->assertTrue(Category::where('name', 'Test Category')->exists());
|
|
}
|
|
|
|
public function testUserCannotCreateCategoriesWithInvalidType()
|
|
{
|
|
$this->assertFalse(Category::where('name', 'Test Category')->exists());
|
|
|
|
$this->actingAs(User::factory()->superuser()->create())
|
|
->from(route('categories.create'))
|
|
->post(route('categories.store'), [
|
|
'name' => 'Test Category',
|
|
'category_type' => 'invalid'
|
|
])
|
|
->assertRedirect(route('categories.create'));
|
|
|
|
$this->assertFalse(Category::where('name', 'Test Category')->exists());
|
|
}
|
|
|
|
}
|