Commit f1fc37a4 authored by anon's avatar anon

by anon: Use separate fields for data attributes in the dialog.

parent d05f53fe
......@@ -60,23 +60,32 @@
* False to prevent further handlers.
*/
function selectHandler(event, ui) {
event.target.value = ui.item.path;
$('.linkit-link-information > span').text(ui.item.label);
return false;
}
var $form = $(event.target).closest('form');
if (ui.item.path != null) {
$('input[name="attributes[href]"]', $form).val(ui.item.path);
$('input[name="attributes[data-entity-type]"]', $form).val('');
$('input[name="attributes[data-entity-uuid]"]', $form).val('');
$('input[name="attributes[data-entity-substitution]"]', $form).val('');
event.target.value = ui.item.path;
}
else {
if (!ui.item.entity_type_id || !ui.item.entity_uuid || !ui.item.substitution_id) {
throw 'Missing data params.' + JSON.stringify(ui.item);
}
/**
* Handles an autocomplete response event.
*
* Updates the link information.
*
* @param {jQuery.Event} event
* The event triggered.
* @param {object} ui
* The jQuery UI settings object.
*/
function response(event, ui) {
$('.linkit-link-information > span').text(event.target.value);
// The href needs to be set in order for the drupallink saveCallback to
// insert new anchor elements.
$('input[name="attributes[href]"]', $form).val('#');
$('input[name="attributes[data-entity-type]"]', $form).val(ui.item.entity_type_id);
$('input[name="attributes[data-entity-uuid]"]', $form).val(ui.item.entity_uuid);
$('input[name="attributes[data-entity-substitution]"]', $form).val(ui.item.substitution_id);
event.target.value = ui.item.label;
}
$('.linkit-link-information > span', $form).text(ui.item.label);
return false;
}
/**
......@@ -175,7 +184,6 @@
renderItem: renderItem,
renderMenu: renderMenu,
select: selectHandler,
response: response,
minLength: 1
},
ajax: {
......
......@@ -78,18 +78,25 @@ function linkit_form_editor_link_dialog_alter(&$form, FormStateInterface $form_s
$input = $form_state->get('link_element') ?: [];
}
// If the filter_html filter is activated, or any other filters using
// XSS:filter(), it will remove 'entity:' from the href as it thinks it's a
// bad protocol. We therefor have to restore the URI again when editing a
// link. It is possible given that data-entity-type and data-entity-uuid is
// set on the link element.
$form['linkit'] = [
'#title' => t('Link'),
'#type' => 'linkit',
'#description' => t('Start typing to find content or paste a URL.'),
'#autocomplete_route_name' => 'linkit.autocomplete',
'#autocomplete_route_parameters' => [
'linkit_profile_id' => $linkit_profile_id,
],
"#weight" => -10,
];
// Determine what the default value of the linkit autocomplete field.
try {
if (!empty($input['data-entity-type']) && !empty($input['data-entity-uuid'])) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = \Drupal::service('entity.repository')
->loadEntityByUuid($input['data-entity-type'], $input['data-entity-uuid']);
$href = 'entity:' . $entity->getEntityTypeId() . '/' . $entity->id();
$access = !$entity->access('view', NULL, TRUE)->isForbidden();
$autocomplete_default_value = !empty($access) && $access ? $entity->label() : '';
}
}
catch (Exception $exception) {
......@@ -98,30 +105,38 @@ function linkit_form_editor_link_dialog_alter(&$form, FormStateInterface $form_s
finally {
// If the href is not set, the data- attributes might not exists, or the
// href is external. In that case, use the given href.
if (!isset($href)) {
$href = isset($input['href']) ? $input['href'] : '';
if (!isset($autocomplete_default_value)) {
$autocomplete_default_value = isset($input['href']) ? $input['href'] : '';
}
}
$form['attributes']['href'] = [
'#title' => t('Link'),
'#type' => 'linkit',
'#default_value' => $href,
'#description' => t('Start typing to find content or paste a URL.'),
'#autocomplete_route_name' => 'linkit.autocomplete',
'#autocomplete_route_parameters' => [
'linkit_profile_id' => $linkit_profile_id,
],
];
$form['linkit']['#default_value'] = $autocomplete_default_value;
$form['attributes']['link-information'] = [
$form['link-information'] = [
'#type' => 'inline_template',
'#template' => '<div class="form-item linkit-link-information"><strong>{% trans %}Links to:{% endtrans %}</strong> <span>{{ link_target }}</span></div>',
'#template' => '<div class="form-item linkit-link-information"><strong>{% trans %}Selected link:{% endtrans %}</strong> <span>{{ link_target }}</span></div>',
'#context' => [
'link_target' => !empty($entity) && !empty($access) && $access ? $entity->label() : $href,
'link_target' => !empty($entity) && !empty($access) && $access ? $entity->label() : $autocomplete_default_value,
],
"#weight" => -10,
];
$fields = [
'href',
'data-entity-type',
'data-entity-uuid',
'data-entity-substitution',
];
$form['attributes']["#weight"] = -100;
foreach ($fields as $field_name) {
$form['attributes'][$field_name] = [
'#type' => 'hidden',
'#default_value' => isset($input[$field_name]) ? $input[$field_name] : '',
];
}
// Add IMCE button if IMCE is installed and enabled for the given profile.
if (Drupal::service('module_handler')->moduleExists('imce') && $linkit_profile->getThirdPartySetting('imce', 'use', FALSE)) {
$form['imce-link'] = [
......@@ -146,57 +161,29 @@ function linkit_form_editor_link_dialog_alter(&$form, FormStateInterface $form_s
'#weight' => 10,
];
}
// Add #validate callback that generates data-entity-type and
// data-entity-uuid attributes from the href attribute when appropriate.
array_unshift($form['#validate'], 'linkit_form_editor_link_dialog_validate');
// Add #submit callback that handles the data-* attributes.
array_unshift($form['#submit'], 'linkit_form_editor_link_dialog_submit');
}
/**
* Generates data-entity-type and data-entity-uuid attributes from href.
* Handles the data-* attributes and href replacement when appropriate.
*/
function linkit_form_editor_link_dialog_validate(array &$form, FormStateInterface $form_state) {
function linkit_form_editor_link_dialog_submit(array &$form, FormStateInterface $form_state) {
$link_element = $form_state->get('link_element');
// Check if the 'href' attribute contains a entity: URI.
$href = $form_state->getValue(['attributes', 'href']);
$uri_parts = parse_url($href);
$data_entity_type = $form_state->getValue(['attributes', 'data-entity-type']);
$data_entity_uuid = $form_state->getValue(['attributes', 'data-entity-uuid']);
if (!$uri_parts || !isset($uri_parts['scheme']) || $uri_parts['scheme'] !== 'entity') {
// Only set the data attributes to an empty string if the link is edited.
// This is to prevent new links that does not point to entities to have
// empty data attributes.
if (empty($data_entity_type) || empty($data_entity_uuid)) {
if (!empty($link_element)) {
$form_state->setValue(['attributes', 'data-entity-type'], '');
$form_state->setValue(['attributes', 'data-entity-uuid'], '');
$form_state->setValue(['attributes', 'data-entity-substitution'], '');
}
return;
}
// Parse the entity: URI into an entity type ID and entity ID.
list($substitution_type, $entity_type_id, $entity_id) = explode('/', $uri_parts['path'], 3);
// Check if the given entity type exists, to prevent the entity load method
// to throw exceptions.
$definition = \Drupal::entityTypeManager()->getDefinition($entity_type_id, FALSE);
if (is_null($definition)) {
$form_state->setError($form['attributes']['href'], t('Invalid URI'));
return;
}
// Load the entity and populate the data-entity-type and data-entity-uuid
// attributes as expected by filters.
// @see \Drupal\editor\Plugin\Filter\EditorFileReference
// @see \Drupal\linkit\Plugin\Filter\LinkitFilter
$entity = \Drupal::entityTypeManager()->getStorage($entity_type_id)->load($entity_id);
if (!empty($entity)) {
$form_state->setValue(['attributes', 'data-entity-type'], $entity->getEntityTypeId());
$form_state->setValue(['attributes', 'data-entity-uuid'], $entity->uuid());
$form_state->setValue(['attributes', 'data-entity-substitution'], $substitution_type);
}
else {
$form_state->setError($form['attributes']['href'], t('Invalid URI'));
else {
$form_state->unsetValue(['attributes', 'data-entity-type']);
$form_state->unsetValue(['attributes', 'data-entity-uuid']);
$form_state->unsetValue(['attributes', 'data-entity-substitution']);
}
}
}
......@@ -41,7 +41,7 @@ class AutocompleteController implements ContainerInjectionInterface {
*
* @param \Drupal\Core\Entity\EntityStorageInterface $linkit_profile_storage
* The linkit profile storage service.
* @param SuggestionManager $suggestionManager
* @param \Drupal\linkit\SuggestionManager $suggestionManager
* The suggestion service.
*/
public function __construct(EntityStorageInterface $linkit_profile_storage, SuggestionManager $suggestionManager) {
......@@ -65,12 +65,12 @@ class AutocompleteController implements ContainerInjectionInterface {
* Like other autocomplete functions, this function inspects the 'q' query
* parameter for the string to use to search for suggestions.
*
* @param Request $request
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
* @param string $linkit_profile_id
* The linkit profile id.
*
* @return JsonResponse
* @return \Symfony\Component\HttpFoundation\JsonResponse JsonResponse
* A JSON response containing the autocomplete suggestions.
*/
public function autocomplete(Request $request, $linkit_profile_id) {
......@@ -79,6 +79,16 @@ class AutocompleteController implements ContainerInjectionInterface {
$suggestionCollection = $this->suggestionManager->getSuggestions($this->linkitProfile, $string);
/*
* If there are no suggestions from the matcher plugins, we have to add a
* special suggestion that have the same path as the given string so users
* can select it and use it anyway. This is a common use case with external
* links.
*/
if (!count($suggestionCollection->getSuggestions()) && !empty($string)) {
$suggestionCollection = $this->suggestionManager->addUnscathedSuggestion($suggestionCollection, $string);
}
return new JsonResponse($suggestionCollection);
}
......
......@@ -13,9 +13,8 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\linkit\ConfigurableMatcherBase;
use Drupal\linkit\MatcherTokensTrait;
use Drupal\linkit\SubstitutionManager;
use Drupal\linkit\SubstitutionManagerInterface;
use Drupal\linkit\Suggestion\DescriptionSuggestion;
use Drupal\linkit\Suggestion\EntitySuggestion;
use Drupal\linkit\Suggestion\SuggestionCollection;
use Drupal\linkit\Utility\LinkitXss;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -305,11 +304,13 @@ class EntityMatcher extends ConfigurableMatcherBase {
$entity = $this->entityRepository->getTranslationFromContext($entity);
$suggestion = new DescriptionSuggestion();
$suggestion = new EntitySuggestion();
$suggestion->setLabel($this->buildLabel($entity))
->setPath($this->buildPath($entity))
->setGroup($this->buildGroup($entity))
->setDescription($this->buildDescription($entity));
->setDescription($this->buildDescription($entity))
->setEntityUuid($entity->uuid())
->setEntityTypeId($entity->getEntityTypeId())
->setSubstitutionId($this->configuration['substitution_type']);
$suggestions->addSuggestion($suggestion);
}
......@@ -382,21 +383,6 @@ class EntityMatcher extends ConfigurableMatcherBase {
return LinkitXss::descriptionFilter($description);
}
/**
* Builds the path string used in the match array.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The matched entity.
*
* @return string
* The entity: URL for this entity.
*
* @see \Drupal\Core\Url::fromEntityUri()
*/
protected function buildPath(EntityInterface $entity) {
return 'entity:' . $this->configuration['substitution_type'] . '/' . $entity->getEntityTypeId() . '/' . $entity->id();
}
/**
* Builds the group string used in the match array.
*
......
<?php
namespace Drupal\linkit\Suggestion;
/**
* Defines a entity suggestion.
*/
class EntitySuggestion extends DescriptionSuggestion {
/**
* The entity uuid.
*
* @var string
*/
protected $entityUuid;
/**
* The entity type id.
*
* @var string
*/
protected $entityTypeId;
/**
* The substitution id.
*
* @var string
*/
protected $substitutionId;
/**
* Sets the entity uuid.
*
* @param string $entity_uuid
* The entity uuid.
*
* @return $this
*/
public function setEntityUuid($entity_uuid) {
$this->entityUuid = $entity_uuid;
return $this;
}
/**
* Sets the entity type id.
*
* @param string $entity_type_id
* The entity type id.
*
* @return $this
*/
public function setEntityTypeId($entity_type_id) {
$this->entityTypeId = $entity_type_id;
return $this;
}
/**
* Sets the substitution id.
*
* @param string $substitution_id
* The substitution id.
*
* @return $this
*/
public function setSubstitutionId($substitution_id) {
$this->substitutionId = $substitution_id;
return $this;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() {
return parent::jsonSerialize() + [
'entity_uuid' => $this->entityUuid,
'entity_type_id' => $this->entityTypeId,
'substitution_id' => $this->substitutionId,
];
}
}
......@@ -2,6 +2,9 @@
namespace Drupal\linkit;
use Drupal\Component\Utility\Html;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\linkit\Suggestion\DescriptionSuggestion;
use Drupal\linkit\Suggestion\SuggestionCollection;
/**
......@@ -9,6 +12,8 @@ use Drupal\linkit\Suggestion\SuggestionCollection;
*/
class SuggestionManager {
use StringTranslationTrait;
/**
* Gets the suggestions.
*
......@@ -34,4 +39,25 @@ class SuggestionManager {
return $suggestions;
}
/**
* Adds an unscathed suggestion to the given suggestion collection.
*
* @param \Drupal\linkit\Suggestion\SuggestionCollection $suggestionCollection
* A suggestion collection to add the unscathed suggestion to.
* @param string $search_string
* The string ro use in the matchers.
*
* @return \Drupal\linkit\Suggestion\SuggestionCollection
* A suggestion collection.
*/
public function addUnscathedSuggestion(SuggestionCollection $suggestionCollection, $search_string) {
$suggestion = new DescriptionSuggestion();
$suggestion->setLabel(Html::escape($search_string))
->setGroup($this->t('No results'))
->setDescription($this->t('Linkit could not find any suggestions. This URL will be used as is.'))
->setPath($search_string);
$suggestionCollection->addSuggestion($suggestion);
return $suggestionCollection;
}
}
......@@ -55,13 +55,11 @@ class LinkitAutocompleteTest extends LinkitKernelTestBase {
parent::setUp();
\Drupal::service('router.builder')->rebuild();
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test');
$this->installEntitySchema('entity_test_mul');
$this->matcherManager = $this->container->get('plugin.manager.linkit.matcher');
$this->linkitProfile = $this->createProfile();
}
......@@ -130,7 +128,8 @@ class LinkitAutocompleteTest extends LinkitKernelTestBase {
// Search for something that doesn't exists.
$data = $this->getAutocompleteResult('no_suggestions');
$this->assertEmpty(count($data), 'Autocomplete did not return any suggestions.');
$this->assertTrue(count($data) == 1, 'Autocomplete returned the expected amount of suggestions.');
$this->assertSame(Html::escape('no_suggestions'), $data[0]['label'], 'Autocomplete returned the "no result" suggestion.');
// Search for something that exists one time.
$data = $this->getAutocompleteResult('bas');
......
......@@ -7,6 +7,7 @@ use Drupal\editor\Entity\Editor;
use Drupal\editor\Form\EditorLinkDialog;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\filter\Entity\FilterFormat;
use Drupal\linkit\SubstitutionManagerInterface;
use Drupal\linkit\Tests\ProfileCreationTrait;
/**
......@@ -121,25 +122,24 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase {
$form_builder->prepareForm($form_id, $form, $form_state);
$form_builder->processForm($form_id, $form, $form_state);
$this->assertEquals('linkit.autocomplete', $form['attributes']['href']['#autocomplete_route_name'], 'Linkit is enabled on the href field.');
$this->assertEquals('', $form['attributes']['href']['#default_value'], 'The href attribute is empty.');
$this->assertEquals('', $form['attributes']['link-information']['#context']['link_target'], 'Link information is empty.');
$this->assertEquals('linkit.autocomplete', $form['linkit']['#autocomplete_route_name'], 'Linkit is enabled on the linkit field.');
$this->assertEquals('', $form['linkit']['#default_value'], 'The linkit field is empty.');
$form_state->setValue(['attributes', 'href'], 'entity:canonical/missing_entity/1');
$form_builder->submitForm($form_object, $form_state);
$this->assertNotEmpty($form_state->getErrors(), 'Got validation errors for none existing entity type.');
$form_state->setValue(['attributes', 'href'], 'url_without_schema');
$form_state->setValue('linkit', 'url_without_schema');
$form_builder->submitForm($form_object, $form_state);
$this->assertEmpty($form_state->getErrors(), 'Got no validation errors for url without schema.');
$this->assertEquals('', $form_state->getValue(['attributes', 'data-entity-type']));
$this->assertEquals('', $form_state->getValue(['attributes', 'data-entity-uuid']));
$this->assertEmpty($form_state->getValue(['attributes', 'data-entity-type']));
$this->assertEmpty($form_state->getValue(['attributes', 'data-entity-uuid']));
$form_state->setValue(['attributes', 'data-entity-type'], $entity->getEntityTypeId());
$form_state->setValue(['attributes', 'data-entity-uuid'], $entity->uuid());
$form_state->setValue(['attributes', 'data-entity-substitution'], SubstitutionManagerInterface::DEFAULT_SUBSTITUTION);
$form_state->setValue(['attributes', 'href'], 'entity:canonical/entity_test/1');
$form_builder->submitForm($form_object, $form_state);
$this->assertEmpty($form_state->getErrors(), 'Got no validation errors for correct URI.');
$this->assertEquals($entity->getEntityTypeId(), $form_state->getValue(['attributes', 'data-entity-type']), 'Attribute "data-entity-type" exists and has the correct value.');
$this->assertEquals($entity->uuid(), $form_state->getValue(['attributes', 'data-entity-uuid']), 'Attribute "data-entity-uuid" exists and has the correct value.');
$this->assertEquals(SubstitutionManagerInterface::DEFAULT_SUBSTITUTION, $form_state->getValue(['attributes', 'data-entity-substitution']), 'Attribute "data-entity-substitution" exists and has the correct value.');
}
/**
......@@ -157,9 +157,10 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase {
$input = [
'editor_object' => [
'href' => 'entity:entity_test/1',
'href' => '#',
'data-entity-type' => $entity->getEntityTypeId(),
'data-entity-uuid' => $entity->uuid(),
'data-entity-substitution' => SubstitutionManagerInterface::DEFAULT_SUBSTITUTION,
],
'dialogOptions' => [
'title' => 'Edit Link',
......@@ -185,17 +186,20 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase {
$form_builder->prepareForm($form_id, $form, $form_state);
$form_builder->processForm($form_id, $form, $form_state);
$this->assertEquals('linkit.autocomplete', $form['attributes']['href']['#autocomplete_route_name'], 'Linkit is enabled on the href field.');
$this->assertEquals('entity:entity_test/1', $form['attributes']['href']['#default_value'], 'The href attribute is empty.');
$this->assertEquals($entity->label(), $form['attributes']['link-information']['#context']['link_target'], 'Link information is empty.');
$this->assertEquals('linkit.autocomplete', $form['linkit']['#autocomplete_route_name'], 'Linkit is enabled on the linkit field.');
$this->assertEquals($entity->label(), $form['linkit']['#default_value'], 'The linkit field has the label as default value.');
$this->assertEquals($entity->getEntityTypeId(), $form_state->getValue(['attributes', 'data-entity-type']), 'Attribute "data-entity-type" exists and has the correct value.');
$this->assertEquals($entity->uuid(), $form_state->getValue(['attributes', 'data-entity-uuid']), 'Attribute "data-entity-uuid" exists and has the correct value.');
$this->assertEquals(SubstitutionManagerInterface::DEFAULT_SUBSTITUTION, $form_state->getValue(['attributes', 'data-entity-substitution']), 'Attribute "data-entity-substitution" exists and has the correct value.');
// Make sure the dialog don't display entity labels for inaccessible
// entities.
$input = [
'editor_object' => [
'href' => 'entity:entity_test/2',
'href' => '#',
'data-entity-type' => $entity_no_access->getEntityTypeId(),
'data-entity-uuid' => $entity_no_access->uuid(),
'data-entity-substitution' => SubstitutionManagerInterface::DEFAULT_SUBSTITUTION,
],
'dialogOptions' => [
'title' => 'Edit Link',
......@@ -221,9 +225,8 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase {
$form_builder->prepareForm($form_id, $form, $form_state);
$form_builder->processForm($form_id, $form, $form_state);
$this->assertEquals('linkit.autocomplete', $form['attributes']['href']['#autocomplete_route_name'], 'Linkit is enabled on the href field.');
$this->assertEquals('entity:entity_test/2', $form['attributes']['href']['#default_value'], 'The href attribute is empty.');
$this->assertEquals('entity:entity_test/2', $form['attributes']['link-information']['#context']['link_target'], 'Link information is empty.');
$this->assertEquals('linkit.autocomplete', $form['linkit']['#autocomplete_route_name'], 'Linkit is enabled on the linkit field.');
$this->assertEmpty($form['linkit']['#default_value']);
}
/**
......@@ -260,9 +263,11 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase {
$form_builder->prepareForm($form_id, $form, $form_state);
$form_builder->processForm($form_id, $form, $form_state);
$this->assertEquals('linkit.autocomplete', $form['attributes']['href']['#autocomplete_route_name'], 'Linkit is enabled on the href field.');
$this->assertEquals('http://example.com/', $form['attributes']['href']['#default_value'], 'The href attribute is empty.');
$this->assertEquals('http://example.com/', $form['attributes']['link-information']['#context']['link_target'], 'Link information is empty.');
$this->assertEquals('linkit.autocomplete', $form['linkit']['#autocomplete_route_name'], 'Linkit is enabled on the href field.');
$this->assertEquals('http://example.com/', $form['linkit']['#default_value'], 'The linkit field default value is the external URI.');
$this->assertEmpty($form['attributes']['data-entity-type']['#default_value']);
$this->assertEmpty($form['attributes']['data-entity-uuid']['#default_value']);
$this->assertEmpty($form['attributes']['data-entity-substitution']['#default_value']);
}
}
......@@ -12,8 +12,6 @@ use Drupal\Tests\linkit\Kernel\LinkitKernelTestBase;
*/
class FileMatcherTest extends LinkitKernelTestBase {
use AssertResultUriTrait;
/**
* Modules to enable.
*
......@@ -53,17 +51,6 @@ class FileMatcherTest extends LinkitKernelTestBase {
}
}
/**
* Tests the paths for results on a file matcher.
*/
public function testMatcherResultsPath() {
/** @var \Drupal\linkit\MatcherInterface $plugin */
$plugin = $this->manager->createInstance('entity:file', []);
$suggestions = $plugin->execute('image-test');
$this->assertTrue(count($suggestions->getSuggestions()), 'Got suggestions');
$this->assertResultUri($plugin, $suggestions);
}
/**
* Tests file matcher.
*/
......
......@@ -13,8 +13,6 @@ use Drupal\Tests\linkit\Kernel\LinkitKernelTestBase;
*/
class NodeMatcherTest extends LinkitKernelTestBase {
use AssertResultUriTrait;
/**
* Modules to enable.
*
......@@ -88,17 +86,6 @@ class NodeMatcherTest extends LinkitKernelTestBase {
\Drupal::currentUser()->setAccount($this->createUser([], ['access content']));
}
/**
* Tests the paths for results on a node matcher.
*/
public function testMatcherResultsPath() {
/** @var \Drupal\linkit\MatcherInterface $plugin */
$plugin = $this->manager->createInstance('entity:node', []);
$suggestions = $plugin->execute('Lorem');
$this->assertTrue(count($suggestions->getSuggestions()), 'Got suggestions');
$this->assertResultUri($plugin, $suggestions);
}
/**
* Tests node matcher.
*/
......
......@@ -16,8 +16,6 @@ use Drupal\Tests\linkit\Kernel\LinkitKernelTestBase;
*/
class TermMatcherTest extends LinkitKernelTestBase {
use AssertResultUriTrait;
/**
* Modules to enable.
*
......@@ -53,21 +51,6 @@ class TermMatcherTest extends LinkitKernelTestBase {
$this->createTerm($testing_vocabulary_2, ['name' => 'foo_baz']);
}
/**
* Tests the paths for results on a term matcher.
*/
public function testMatcherResultsPath() {
/** @var \Drupal\linkit\MatcherInterface $plugin */
$plugin = $this->manager->createInstance('entity:taxonomy_term', [
'settings' => [
'file_status' => 0,
],
]);
$suggestions = $plugin->execute('foo');
$this->assertTrue(count($suggestions->getSuggestions()), 'Got suggestions');
$this->assertResultUri($plugin, $suggestions);
}
/**
* Tests term matcher with default configuration.
*/
......
......@@ -12,8 +12,6 @@ use Drupal\user\Entity\Role;
*/
class UserMatcherTest extends LinkitKernelTestBase {
use AssertResultUriTrait;
/**
* The matcher manager.
*
......@@ -61,17 +59,6 @@ class UserMatcherTest extends LinkitKernelTestBase {
$account->save();
}
/**
* Tests the paths for results on a user matcher.
*/
public function testMatcherResultsPath() {
/** @var \Drupal\linkit\MatcherInterface $plugin */
$plugin = $this->manager->createInstance('entity:user', []);
$suggestions = $plugin->execute('Lorem');
$this->assertTrue(count($suggestions->getSuggestions()), 'Got suggestions');
$this->assertResultUri($plugin, $suggestions);
}
/**
* Tests user matcher.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment