You are here

public function MediaMatcherTest::testMediaMatcherWithDefaultConfiguration in Linkit 8.5

Tests media matcher.

File

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

Class

MediaMatcherTest
Tests media matcher.

Namespace

Drupal\Tests\linkit\Kernel\Matchers

Code

public function testMediaMatcherWithDefaultConfiguration() {

  /** @var \Drupal\linkit\MatcherInterface $plugin */
  $plugin = $this->manager
    ->createInstance('entity:media', []);
  $suggestions = $plugin
    ->execute('image-test');
  $this
    ->assertEquals(3, count($suggestions
    ->getSuggestions()), 'Correct number of suggestions.');

  // Verify suggestion paths.
  foreach ($suggestions
    ->getSuggestions() as $key => $suggestion) {
    $this
      ->assertEquals('/media/' . ($key + 1), $suggestion
      ->getPath());
  }

  // Enable stand-alone URLs for media entities.
  $config = \Drupal::service('config.factory')
    ->getEditable('media.settings');
  $config
    ->set('standalone_url', TRUE)
    ->save();
  drupal_flush_all_caches();
  $suggestions = $plugin
    ->execute('image-test');

  // Re-verify suggestion paths, they should not contain /edit.
  foreach ($suggestions
    ->getSuggestions() as $key => $suggestion) {
    $this
      ->assertEquals('/media/' . ($key + 1), $suggestion
      ->getPath());
  }
}