TermEntityReferenceTest.php in Zircon Profile 8
File
core/modules/taxonomy/src/Tests/TermEntityReferenceTest.php
View source
<?php
namespace Drupal\taxonomy\Tests;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
class TermEntityReferenceTest extends TaxonomyTestBase {
public static $modules = [
'entity_reference_test',
'entity_test',
];
function testSelectionTestVocabularyRestriction() {
$vocabulary = $this
->createVocabulary();
$vocabulary2 = $this
->createVocabulary();
$term = $this
->createTerm($vocabulary);
$term2 = $this
->createTerm($vocabulary2);
$field_name = 'taxonomy_' . $vocabulary
->id();
$field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'translatable' => FALSE,
'settings' => array(
'target_type' => 'taxonomy_term',
),
'type' => 'entity_reference',
'cardinality' => 1,
));
$field_storage
->save();
$field = FieldConfig::create(array(
'field_storage' => $field_storage,
'entity_type' => 'entity_test',
'bundle' => 'test_bundle',
'settings' => array(
'handler' => 'default',
'handler_settings' => array(
'target_bundles' => array(
$vocabulary
->id() => $vocabulary
->id(),
),
),
),
));
$field
->save();
$handler = $this->container
->get('plugin.manager.entity_reference_selection')
->getSelectionHandler($field);
$result = $handler
->getReferenceableEntities();
$expected_result = array(
$vocabulary
->id() => array(
$term
->id() => $term
->getName(),
),
);
$this
->assertIdentical($result, $expected_result, 'Terms selection restricted to a single vocabulary.');
}
}