summaryrefslogtreecommitdiffstats
path: root/tests/src/Kernel/Matchers/AssertResultUriTrait.php
blob: 0f3da62c4d701b865ac040186d5e532b04890128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

namespace Drupal\Tests\linkit\Kernel\Matchers;

use Drupal\linkit\MatcherInterface;
use Drupal\linkit\Suggestion\SuggestionCollection;

/**
 * Provides helper methods for assertions.
 */
trait AssertResultUriTrait {

  /**
   * Assert that paths are formatted as an URI with the entity: scheme.
   *
   * @param \Drupal\linkit\MatcherInterface $plugin
   *   A matcher plugin.
   * @param \Drupal\linkit\Suggestion\SuggestionCollection $suggestions
   *   A collection of suggestions.
   */
  public function assertResultUri(MatcherInterface $plugin, SuggestionCollection $suggestions) {
    $entity_type = $plugin->getPluginDefinition()['target_entity'];
    $substitution_id = $plugin->getConfiguration()['settings']['substitution_type'];
    foreach ($suggestions->getSuggestions() as $suggestion) {
      $this->assertTrue(preg_match("/^entity:" . $substitution_id . "\\/" . $entity_type . "\\/\\w+$/i", $suggestion->getPath()), 'Result URI correct formatted.');
    }
  }

}