diff --git a/modules/core/id_tag/tests/modules/farm_id_tag_test/config/install/asset.type.test.yml b/modules/core/id_tag/tests/modules/farm_id_tag_test/config/install/asset.type.test.yml new file mode 100644 index 000000000..a47108cd4 --- /dev/null +++ b/modules/core/id_tag/tests/modules/farm_id_tag_test/config/install/asset.type.test.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +dependencies: { } +id: test +label: Test +description: '' +workflow: asset_default +new_revision: true diff --git a/modules/core/id_tag/tests/modules/farm_id_tag_test/farm_id_tag_test.info.yml b/modules/core/id_tag/tests/modules/farm_id_tag_test/farm_id_tag_test.info.yml new file mode 100644 index 000000000..e52581643 --- /dev/null +++ b/modules/core/id_tag/tests/modules/farm_id_tag_test/farm_id_tag_test.info.yml @@ -0,0 +1,8 @@ +name: farmOS ID Tag Test +description: Module for testing farmOS ID Tag field. +type: module +package: Testing +core_version_requirement: ^9 +dependencies: + - farm:asset + - farm:farm_id_tag diff --git a/modules/core/id_tag/tests/src/Kernel/IdTagTest.php b/modules/core/id_tag/tests/src/Kernel/IdTagTest.php new file mode 100644 index 000000000..c0a280f3c --- /dev/null +++ b/modules/core/id_tag/tests/src/Kernel/IdTagTest.php @@ -0,0 +1,83 @@ +installEntitySchema('asset'); + $this->installConfig(['farm_id_tag', 'farm_id_tag_test']); + } + + /** + * Test ID tag fields. + */ + public function testIdTagField() { + + // Test creating a new asset and saving ID tag information. + $asset = Asset::create([ + 'name' => $this->randomString(), + 'type' => 'test', + 'id_tag' => [ + 'id' => '123456', + 'type' => 'other', + 'location' => 'Frame', + ], + ]); + $violations = $asset->validate(); + $this->assertEmpty($violations); + $asset->save(); + + // Confirm that the asset was created with expected ID tag values. + $assets = Asset::loadMultiple(); + $this->assertCount(1, $assets); + $this->assertEquals('123456', $assets[1]->get('id_tag')->id); + $this->assertEquals('other', $assets[1]->get('id_tag')->type); + $this->assertEquals('Frame', $assets[1]->get('id_tag')->location); + + // Confirm that all sub-fields are optional. + $asset = Asset::create([ + 'name' => $this->randomString(), + 'type' => 'test', + 'id_tag' => [], + ]); + $violations = $asset->validate(); + $this->assertEmpty($violations); + $asset = Asset::create([ + 'name' => $this->randomString(), + 'type' => 'test', + 'id_tag' => [ + 'id' => '', + 'type' => '', + 'location' => '', + ], + ]); + $violations = $asset->validate(); + $this->assertEmpty($violations); + } + +}