protected function UsageTest::setUp in Bynder 8.3
Same name and namespace in other branches
- 8 tests/src/Functional/UsageTest.php \Drupal\Tests\bynder\Functional\UsageTest::setUp()
- 8.2 tests/src/Functional/UsageTest.php \Drupal\Tests\bynder\Functional\UsageTest::setUp()
- 4.0.x tests/src/Functional/UsageTest.php \Drupal\Tests\bynder\Functional\UsageTest::setUp()
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ UsageTest.php, line 40
Class
- UsageTest
- Tests the Bynder usage tracking.
Namespace
Drupal\Tests\bynder\FunctionalCode
protected function setUp() {
parent::setUp();
$this
->createMediaType('image', [
'id' => 'generic',
]);
// The type to host the reference.
$this
->createContentType([
'type' => 'host',
]);
// Add reference field to host content type.
foreach ([
'node',
'media',
] as $target_type) {
\Drupal::entityTypeManager()
->getStorage('field_storage_config')
->create([
'field_name' => 'field_reference_' . $target_type,
'entity_type' => 'node',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => $target_type,
],
])
->save();
\Drupal::entityTypeManager()
->getStorage('field_config')
->create([
'entity_type' => 'node',
'bundle' => 'host',
'field_name' => 'field_reference_' . $target_type,
'label' => $target_type,
'settings' => [
'handler' => 'default:' . $target_type,
'handler_settings' => [
'target_bundles' => NULL,
],
],
])
->save();
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
$form_display = $this->container
->get('entity_type.manager')
->getStorage('entity_form_display')
->load('node.host.default');
$form_display
->setComponent('field_reference_' . $target_type, [
'type' => 'entity_reference_autocomplete',
])
->save();
$display = $this->container
->get('entity_type.manager')
->getStorage('entity_view_display')
->load('node.host.default');
$display
->setComponent('field_reference_' . $target_type, [
'type' => 'entity_reference_label',
])
->save();
}
\Drupal::configFactory()
->getEditable('entity_usage.settings')
->set('track_enabled_source_entity_types', [
'node',
])
->set('track_enabled_plugins', [
'entity_reference',
])
->set('track_enabled_target_entity_types', [
'media',
])
->save();
$this
->drupalLogin($this
->drupalCreateUser([
'create host content',
'edit any host content',
'create url aliases',
'administer url aliases',
]));
}