mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 13:57:41 -08:00
Add test case
This commit is contained in:
parent
bcace9d019
commit
663b2fd844
|
@ -68,9 +68,7 @@ class UpdateAssetModelsTest extends TestCase
|
||||||
$this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL');
|
$this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL');
|
||||||
|
|
||||||
$assetModel = AssetModel::factory()->create();
|
$assetModel = AssetModel::factory()->create();
|
||||||
|
|
||||||
$customFieldset = CustomFieldset::factory()->create();
|
$customFieldset = CustomFieldset::factory()->create();
|
||||||
|
|
||||||
[$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create();
|
[$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create();
|
||||||
|
|
||||||
$customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]);
|
$customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]);
|
||||||
|
@ -87,8 +85,8 @@ class UpdateAssetModelsTest extends TestCase
|
||||||
'add_default_values' => '1',
|
'add_default_values' => '1',
|
||||||
'fieldset_id' => $customFieldset->id,
|
'fieldset_id' => $customFieldset->id,
|
||||||
'default_values' => [
|
'default_values' => [
|
||||||
$customFieldOne->id => 'changed value',
|
$customFieldOne->id => 'first changed value',
|
||||||
$customFieldTwo->id => 'changed value',
|
$customFieldTwo->id => 'second changed value',
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -100,4 +98,40 @@ class UpdateAssetModelsTest extends TestCase
|
||||||
'Default field values were changed unexpectedly.'
|
'Default field values were changed unexpectedly.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_default_values_can_be_updated()
|
||||||
|
{
|
||||||
|
$this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL');
|
||||||
|
|
||||||
|
$assetModel = AssetModel::factory()->create();
|
||||||
|
$customFieldset = CustomFieldset::factory()->create();
|
||||||
|
[$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]);
|
||||||
|
$customFieldset->fields()->attach($customFieldTwo, ['order' => 2, 'required' => false]);
|
||||||
|
|
||||||
|
$assetModel->fieldset()->associate($customFieldset);
|
||||||
|
|
||||||
|
$assetModel->defaultValues()->attach($customFieldOne, ['default_value' => 'first default value']);
|
||||||
|
$assetModel->defaultValues()->attach($customFieldTwo, ['default_value' => 'second default value']);
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->put(route('models.update', ['model' => $assetModel]), [
|
||||||
|
// should trigger validation error without name, etc, and NOT remove or change default values
|
||||||
|
'name' => 'Test Model Edited',
|
||||||
|
'category_id' => $assetModel->category_id,
|
||||||
|
'add_default_values' => '1',
|
||||||
|
'fieldset_id' => $customFieldset->id,
|
||||||
|
'default_values' => [
|
||||||
|
$customFieldOne->id => 'first changed value',
|
||||||
|
$customFieldTwo->id => 'second changed value',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$potentiallyChangedDefaultValues = $assetModel->defaultValues->pluck('pivot.default_value');
|
||||||
|
|
||||||
|
$this->assertCount(2, $potentiallyChangedDefaultValues);
|
||||||
|
$this->assertContains('first changed value', $potentiallyChangedDefaultValues);
|
||||||
|
$this->assertContains('second changed value', $potentiallyChangedDefaultValues);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue