You are here

protected function BynderFormatterTest::setUp in Bynder 8.3

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

Overrides BrowserTestBase::setUp

File

tests/src/Functional/BynderFormatterTest.php, line 37

Class

BynderFormatterTest
Tests the Bynder formatter.

Namespace

Drupal\Tests\bynder\Functional

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'view media',
    'administer content types',
    'administer node display',
    'administer media types',
    'administer media display',
    'create media',
    'administer media form display',
    'administer node form display',
    'view bynder media usage',
  ]));
  $this
    ->createContentType([
    'type' => 'page',
  ]);
  $entities = [
    'node' => 'page',
    'media' => 'media_type',
  ];

  // Attach fields to node and media entities to test is applicable logic.
  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();
    }
  }
}