protected function HierarchicalTaxonomyMenuImageTest::setUp in Hierarchical Taxonomy Menu 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ HierarchicalTaxonomyMenuImageTest.php, line 57
Class
- HierarchicalTaxonomyMenuImageTest
- Tests the Hierarchical Taxonomy Menu images.
Namespace
Drupal\Tests\hierarchical_taxonomy_menu\FunctionalCode
protected function setUp() {
parent::setUp();
$vocabulary = $this
->createVocabulary();
$this->vocabulary = $vocabulary;
FieldStorageConfig::create([
'field_name' => 'field_icon',
'entity_type' => 'taxonomy_term',
'type' => 'image',
'settings' => [],
'cardinality' => 1,
])
->save();
$field_config = FieldConfig::create([
'field_name' => 'field_icon',
'label' => 'Icon',
'entity_type' => 'taxonomy_term',
'bundle' => $vocabulary
->id(),
'required' => TRUE,
'settings' => [],
'description' => '',
]);
$field_config
->save();
$images = $this
->getTestFiles('image');
$file1 = File::create([
'uri' => $images[0]->uri,
'status' => FILE_STATUS_PERMANENT,
]);
$file1
->save();
$file2 = File::create([
'uri' => $images[1]->uri,
'status' => FILE_STATUS_PERMANENT,
]);
$file2
->save();
$this
->createTerm($vocabulary, [
'name' => 'Term 1',
'field_icon' => [
'target_id' => $file1
->id(),
'alt' => 'First image',
],
]);
$this
->createTerm($vocabulary, [
'name' => 'Term 2',
'field_icon' => [
'target_id' => $file2
->id(),
'alt' => 'Second image',
],
]);
$block = $this
->drupalPlaceBlock('hierarchical_taxonomy_menu', [
'region' => 'content',
'label' => 'Hierarchical Taxonomy Menu',
'id' => 'hierarchicaltaxonomymenu',
]);
$block
->set('settings', [
'label' => 'Hierarchical Taxonomy Menu',
'label_display' => 'visible',
'vocabulary' => $vocabulary
->id() . '|field_icon',
'collapsible' => FALSE,
]);
$block
->save();
$this->block = $block;
}