You are here

protected function UsageTest::setUp in Bynder 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/UsageTest.php \Drupal\Tests\bynder\Functional\UsageTest::setUp()
  2. 8.2 tests/src/Functional/UsageTest.php \Drupal\Tests\bynder\Functional\UsageTest::setUp()
  3. 4.0.x tests/src/Functional/UsageTest.php \Drupal\Tests\bynder\Functional\UsageTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/UsageTest.php, line 31

Class

UsageTest
Tests the Bynder usage tracking.

Namespace

Drupal\Tests\bynder\Functional

Code

protected function setUp() {
  parent::setUp();
  MediaBundle::create([
    'id' => 'generic',
    'label' => 'Generic media bundle',
    'type' => 'generic',
  ])
    ->save();
  $this
    ->createContentType([
    'type' => 'reference',
  ]);

  // 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();
  }
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'create host content',
    'edit any host content',
    'create url aliases',
    'administer url aliases',
  ]));
}