protected function ConditionalFieldCheckboxesTest::setUp in Conditional Fields 8
Same name and namespace in other branches
- 4.x tests/src/FunctionalJavascript/ConditionalFieldCheckboxesTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldCheckboxesTest::setUp()
Overrides ConditionalFieldTestBase::setUp
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldCheckboxesTest.php, line 43
Class
- ConditionalFieldCheckboxesTest
- Test Conditional Fields Checkboxes Plugin.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
protected function setUp() {
parent::setUp();
// Create a vocabulary with random name.
$this->taxonomyName = $this
->getRandomGenerator()
->word(8);
$vocabulary = Vocabulary::create([
'name' => $this->taxonomyName,
'vid' => $this->taxonomyName,
]);
$vocabulary
->save();
// Create a random taxonomy terms for vocabulary.
$this->termsCount = mt_rand(3, 6);
for ($i = 1; $i <= $this->termsCount; $i++) {
$termName = $this
->getRandomGenerator()
->word(8);
Term::create([
'parent' => [],
'name' => $termName,
'vid' => $this->taxonomyName,
])
->save();
}
// Add a custom field with taxonomy terms to 'Article'.
// The field label is a machine name of created vocabulary.
$handler_settings = [
'target_bundles' => [
$vocabulary
->id() => $vocabulary
->id(),
],
];
$this
->createEntityReferenceField('node', 'article', 'field_' . $this->taxonomyName, $this->taxonomyName, 'taxonomy_term', 'default', $handler_settings, -1);
EntityFormDisplay::load('node.article.default')
->setComponent('field_' . $this->taxonomyName, [
'type' => 'options_buttons',
])
->save();
}