You are here

protected function BynderUsageTest::setUp in Bynder 8

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

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/BynderUsageTest.php, line 45

Class

BynderUsageTest
Test the Bynder media usage info.

Namespace

Drupal\Tests\bynder\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();
  $this
    ->createContentType([
    'type' => 'page',
  ]);
  $entities = [
    'node' => 'page',
    'media' => 'media_type',
  ];
  foreach ($entities as $entity => $bundle) {
    foreach ([
      'string',
      'string_long',
      'entity_reference',
    ] as $type) {
      $settings = $type == 'entity_reference' ? [
        'target_type' => 'media',
      ] : [];
      \Drupal::entityTypeManager()
        ->getStorage('field_storage_config')
        ->create([
        'field_name' => 'field_' . $type,
        'entity_type' => $entity,
        'type' => $type,
        'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
        'settings' => $settings,
      ])
        ->save();
      $settings = $type == 'entity_reference' ? [
        'handler' => 'default:media',
        'handler_settings' => [
          'target_bundles' => [
            'media_type' => 'media_type',
          ],
        ],
      ] : [];
      \Drupal::entityTypeManager()
        ->getStorage('field_config')
        ->create([
        'entity_type' => $entity,
        'bundle' => $bundle,
        'field_name' => 'field_' . $type,
        'label' => $this
          ->randomMachineName(),
        'settings' => $settings,
      ])
        ->save();
    }
  }
  $this->testRole = Role::create([
    'id' => 'editor',
  ]);
  $this->testRole
    ->grantPermission('access content');
  $this->testRole
    ->save();
  $this->testUser = $this
    ->drupalCreateUser();
  $this->testUser
    ->addRole($this->testRole
    ->id());
  $this->testUser
    ->save();
  $this
    ->drupalLogin($this->testUser);
}