You are here

public function SubstitutionPluginTest::testMediaSubstitutionWithoutFileSource in Linkit 8.5

Test the media substitution when there is no supported source field.

File

tests/src/Kernel/SubstitutionPluginTest.php, line 190

Class

SubstitutionPluginTest
Tests the substitution plugins.

Namespace

Drupal\Tests\linkit\Kernel

Code

public function testMediaSubstitutionWithoutFileSource() {

  // Set up media bundle and fields.
  $media_type = MediaType::create([
    'label' => 'test',
    'id' => 'test',
    'description' => 'Test type.',
    'source' => 'test',
  ]);
  $media_type
    ->save();
  $source_field = $media_type
    ->getSource()
    ->createSourceField($media_type);
  $source_field
    ->getFieldStorageDefinition()
    ->save();
  $source_field
    ->save();
  $media_type
    ->set('source_configuration', [
    'source_field' => $source_field
      ->getName(),
  ])
    ->save();
  $media = Media::create([
    'bundle' => 'test',
    $source_field
      ->getName() => [
      'value' => 'foobar',
    ],
  ]);
  $media
    ->save();
  $media_substitution = $this->substitutionManager
    ->createInstance('media');
  $this
    ->assertEquals('', $media_substitution
    ->getUrl($media)
    ->getGeneratedUrl());
  $this
    ->config('media.settings')
    ->set('standalone_url', TRUE)
    ->save();
  \Drupal::entityTypeManager()
    ->clearCachedDefinitions();
  $this
    ->assertEquals('/media/' . $media
    ->id(), $media_substitution
    ->getUrl($media)
    ->getGeneratedUrl());
}