X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ftaxonomy%2Ftests%2Fsrc%2FFunctional%2FTermEntityReferenceTest.php;fp=web%2Fcore%2Fmodules%2Ftaxonomy%2Ftests%2Fsrc%2FFunctional%2FTermEntityReferenceTest.php;h=9d4522ec71edee1833880b562ed779053ca5b718;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/taxonomy/tests/src/Functional/TermEntityReferenceTest.php b/web/core/modules/taxonomy/tests/src/Functional/TermEntityReferenceTest.php new file mode 100644 index 000000000..9d4522ec7 --- /dev/null +++ b/web/core/modules/taxonomy/tests/src/Functional/TermEntityReferenceTest.php @@ -0,0 +1,79 @@ +createVocabulary(); + $vocabulary2 = $this->createVocabulary(); + + $term = $this->createTerm($vocabulary); + $term2 = $this->createTerm($vocabulary2); + + // Create an entity reference field. + $field_name = 'taxonomy_' . $vocabulary->id(); + $field_storage = FieldStorageConfig::create([ + 'field_name' => $field_name, + 'entity_type' => 'entity_test', + 'translatable' => FALSE, + 'settings' => [ + 'target_type' => 'taxonomy_term', + ], + 'type' => 'entity_reference', + 'cardinality' => 1, + ]); + $field_storage->save(); + $field = FieldConfig::create([ + 'field_storage' => $field_storage, + 'entity_type' => 'entity_test', + 'bundle' => 'test_bundle', + 'settings' => [ + 'handler' => 'default', + 'handler_settings' => [ + // Restrict selection of terms to a single vocabulary. + 'target_bundles' => [ + $vocabulary->id() => $vocabulary->id(), + ], + ], + ], + ]); + $field->save(); + + $handler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($field); + $result = $handler->getReferenceableEntities(); + + $expected_result = [ + $vocabulary->id() => [ + $term->id() => $term->getName(), + ], + ]; + + $this->assertIdentical($result, $expected_result, 'Terms selection restricted to a single vocabulary.'); + } + +}