diff --git a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php index 3ca91e9821..83ffce7c91 100644 --- a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php @@ -68,9 +68,7 @@ class UpdateAssetModelsTest extends TestCase $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]); @@ -87,8 +85,8 @@ class UpdateAssetModelsTest extends TestCase 'add_default_values' => '1', 'fieldset_id' => $customFieldset->id, 'default_values' => [ - $customFieldOne->id => 'changed value', - $customFieldTwo->id => 'changed value', + $customFieldOne->id => 'first changed value', + $customFieldTwo->id => 'second changed value', ], ]); @@ -100,4 +98,40 @@ class UpdateAssetModelsTest extends TestCase '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); + } }