public function NodeorderCrudTest::setUp in Node Order 8
Overrides TaxonomyTestBase::setUp
See also
\Drupal\taxonomy\Tests\TermTest::setUp()
File
- src/
Tests/ NodeorderCrudTest.php, line 46
Class
- NodeorderCrudTest
- Test CRUD operations that Nodeorder relies on.
Namespace
Drupal\nodeorder\TestsCode
public function setUp() {
parent::setUp();
$this->nodeOrderManager = $this->container
->get('nodeorder.manager');
$this
->drupalLogin($this
->drupalCreateUser([
'administer taxonomy',
'bypass node access',
'order nodes within categories',
]));
$this->vocabulary = $this
->createVocabulary();
$field_name = 'taxonomy_' . $this->vocabulary
->id();
\Drupal::service('entity_type.manager')
->getStorage('field_storage_config')
->create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'entity_reference',
'module' => 'taxonomy',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => 'taxonomy_term',
],
])
->save();
$this->field = \Drupal::service('entity_type.manager')
->getStorage('field_config')
->create([
'field_name' => $field_name,
'bundle' => 'article',
'entity_type' => 'node',
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$this->vocabulary
->id() => $this->vocabulary
->id(),
],
'sort' => [
'field' => '_none',
],
'auto_create' => FALSE,
],
],
]);
$this->field
->save();
\Drupal::service('entity_display.repository')
->getFormDisplay('node', 'article', 'default')
->setComponent($field_name, [
'type' => 'options_select',
])
->save();
\Drupal::service('entity_display.repository')
->getViewDisplay('node', 'article', 'default')
->setComponent($field_name, [
'type' => 'entity_reference_label',
])
->save();
}