mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-28 23:19:42 -08:00
541350916d
# Conflicts: # tests/Feature/Api/Users/UpdateUserApiTest.php # tests/Feature/Notifications/AccessoryWebhookTest.php # tests/Feature/Notifications/AssetWebhookTest.php # tests/Feature/Notifications/ComponentWebhookTest.php # tests/Feature/Notifications/ConsumableWebhookTest.php # tests/Feature/Notifications/LicenseWebhookTest.php
61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
namespace Tests\Unit;
|
|
|
|
use App\Models\Category;
|
|
use App\Models\AssetModel;
|
|
use App\Models\Asset;
|
|
use Tests\TestCase;
|
|
|
|
class CategoryTest extends TestCase
|
|
{
|
|
public function testFailsEmptyValidation()
|
|
{
|
|
// An Asset requires a name, a qty, and a category_id.
|
|
$a = Category::create();
|
|
$this->assertFalse($a->isValid());
|
|
|
|
$fields = [
|
|
'name' => 'name',
|
|
'category_type' => 'category type',
|
|
];
|
|
$errors = $a->getErrors();
|
|
foreach ($fields as $field => $fieldTitle) {
|
|
$this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required.");
|
|
}
|
|
}
|
|
|
|
public function testACategoryCanHaveAssets()
|
|
{
|
|
$category = Category::factory()->assetDesktopCategory()->create();
|
|
|
|
// Generate 5 models via factory
|
|
$models = AssetModel::factory()
|
|
->mbp13Model()
|
|
->count(5)
|
|
->create(
|
|
[
|
|
'category_id' => $category->id
|
|
]
|
|
);
|
|
|
|
|
|
|
|
// Loop through the models and create 2 assets in each model
|
|
$models->each(function ($model) {
|
|
//dd($model);
|
|
$asset = Asset::factory()
|
|
->count(2)
|
|
->create(
|
|
[
|
|
'model_id' => $model->id,
|
|
]
|
|
);
|
|
//dd($asset);
|
|
});
|
|
|
|
$this->assertCount(5, $category->models);
|
|
$this->assertCount(5, $category->models);
|
|
$this->assertEquals(10, $category->itemCount());
|
|
}
|
|
}
|