function DevelGenerateSetupTrait::setUpData
Same name in other branches
- 5.x devel_generate/tests/src/Traits/DevelGenerateSetupTrait.php \Drupal\Tests\devel_generate\Traits\DevelGenerateSetupTrait::setUpData()
General set-up for all tests.
2 calls to DevelGenerateSetupTrait::setUpData()
- DevelGenerateBrowserTestBase::setUp in devel_generate/
tests/ src/ Functional/ DevelGenerateBrowserTestBase.php - Prepares the testing environment.
- DevelGenerateCommandsTest::setUp in devel_generate/
tests/ src/ Functional/ DevelGenerateCommandsTest.php - Prepares the testing environment.
File
-
devel_generate/
tests/ src/ Traits/ DevelGenerateSetupTrait.php, line 39
Class
- DevelGenerateSetupTrait
- Provides methods to assist Devel Generate testing.
Namespace
Drupal\Tests\devel_generate\TraitsCode
public function setUpData() {
// Create user with devel_generate permissions and access to admin/content.
$admin_user = $this->drupalCreateUser([
'administer devel_generate',
'access devel information',
'access content overview',
]);
$this->drupalLogin($admin_user);
$entity_type_manager = $this->container
->get('entity_type.manager');
// Create Basic page and Article node types.
if ($this->profile != 'standard') {
$this->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic Page',
]);
$this->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this->addDefaultCommentField('node', 'article');
}
// Enable translation for article content type (but not for page).
\Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
// Create languages for generated translations.
ConfigurableLanguage::createFromLangcode('ca')->save();
ConfigurableLanguage::createFromLangcode('de')->save();
ConfigurableLanguage::createFromLangcode('fr')->save();
// Creating a vocabulary to associate taxonomy terms generated.
$this->vocabulary = Vocabulary::create([
'name' => 'Vocab 1 ' . $this->randomString(15),
'description' => $this->randomMachineName(),
'vid' => 'vocab_1_' . mb_strtolower($this->randomMachineName()),
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
]);
$this->vocabulary
->save();
// Enable translation for terms in this vocabulary.
\Drupal::service('content_translation.manager')->setEnabled('taxonomy_term', $this->vocabulary
->id(), TRUE);
// Creates a field of an entity reference field storage on article.
$field_name = 'taxonomy_' . $this->vocabulary
->id();
$handler_settings = [
'target_bundles' => [
$this->vocabulary
->id() => $this->vocabulary
->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$entity_type_manager->getStorage('entity_form_display')
->load('node.article.default')
->setComponent($field_name, [
'type' => 'options_select',
])
->save();
$entity_type_manager->getStorage('entity_view_display')
->load('node.article.default')
->setComponent($field_name, [
'type' => 'entity_reference_label',
])
->save();
// Create the second vocabulary.
$this->vocabulary2 = Vocabulary::create([
'name' => 'Vocab 2 ' . $this->randomString(15),
'vid' => 'vocab_2_' . mb_strtolower($this->randomMachineName()),
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
]);
$this->vocabulary2
->save();
}