You are here

protected function MediaMatcherTest::setUp in Linkit 8.5

Overrides LinkitKernelTestBase::setUp

File

tests/src/Kernel/Matchers/MediaMatcherTest.php, line 34

Class

MediaMatcherTest
Tests media matcher.

Namespace

Drupal\Tests\linkit\Kernel\Matchers

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('file');
  $this
    ->installEntitySchema('media');
  $this
    ->installConfig([
    'media',
  ]);
  $this
    ->installSchema('system', [
    'key_value_expire',
  ]);
  $this
    ->installSchema('file', [
    'file_usage',
  ]);
  $this->manager = $this->container
    ->get('plugin.manager.linkit.matcher');

  // Set up media bundle and fields.
  $media_type = MediaType::create([
    'label' => 'test',
    'id' => 'test',
    'description' => 'Test type.',
    'source' => 'file',
  ]);
  $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();

  // Linkit doesn't care about the actual resource, only the entity.
  foreach ([
    'gif',
    'jpg',
    'png',
  ] as $ext) {
    $file = File::create([
      'uid' => 1,
      'filename' => 'image-test.' . $ext,
      'uri' => 'public://image-test.' . $ext,
      'filemime' => 'text/plain',
      'status' => FILE_STATUS_PERMANENT,
    ]);
    $file
      ->save();
    $media = Media::create([
      'bundle' => 'test',
      $source_field
        ->getName() => [
        'target_id' => $file
          ->id(),
      ],
    ]);
    $media
      ->save();
  }

  // Create user 1 who has special permissions.
  \Drupal::currentUser()
    ->setAccount($this
    ->createUser([
    'uid' => 1,
  ]));
}