composer.json | 2 +- js/linkit.autocomplete.js | 22 ++-- js/linkit.filter_html.admin.js | 17 +-- linkit.info.yml | 3 +- linkit.libraries.yml | 9 +- src/Plugin/Linkit/Matcher/EntityMatcher.php | 1 + src/Plugin/Linkit/Matcher/FileMatcher.php | 5 +- src/Plugin/Linkit/Matcher/NodeMatcher.php | 2 +- src/Plugin/Linkit/Substitution/File.php | 2 +- src/Plugin/Linkit/Substitution/Media.php | 2 +- tests/linkit_test/linkit_test.info.yml | 1 - tests/src/Functional/LinkitBrowserTestBase.php | 2 +- tests/src/Functional/LinkitUpdateTest.php | 121 --------------------- .../src/FunctionalJavascript/LinkitDialogTest.php | 14 ++- .../FunctionalJavascript/LinkitFormatAdminTest.php | 4 +- tests/src/Kernel/AssertLinkitFilterTrait.php | 4 +- tests/src/Kernel/EntityMatcherDeriverTest.php | 4 +- tests/src/Kernel/LinkitAutocompleteTest.php | 4 +- tests/src/Kernel/LinkitEditorLinkDialogTest.php | 11 +- tests/src/Kernel/LinkitFilterEntityTest.php | 7 +- tests/src/Kernel/LinkitKernelTestBase.php | 4 +- .../src/Kernel/Matchers/ContactFormMatcherTest.php | 6 +- tests/src/Kernel/Matchers/FileMatcherTest.php | 8 +- tests/src/Kernel/Matchers/MediaMatcherTest.php | 8 +- tests/src/Kernel/Matchers/NodeMatcherTest.php | 4 +- tests/src/Kernel/Matchers/TermMatcherTest.php | 4 +- tests/src/Kernel/Matchers/UserMatcherTest.php | 2 +- tests/src/Kernel/SubstitutionPluginTest.php | 9 +- 28 files changed, 94 insertions(+), 188 deletions(-) diff --git a/composer.json b/composer.json index 2fe695f..6f32fb5 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "source": "http://cgit.drupalcode.org/linkit" }, "require" : { - "drupal/core": "^9 || ^10" + "drupal/core": "^9.4 || ^10" }, "license": "GPL-2.0-or-later" } diff --git a/js/linkit.autocomplete.js b/js/linkit.autocomplete.js index 558278d..1416cff 100644 --- a/js/linkit.autocomplete.js +++ b/js/linkit.autocomplete.js @@ -3,7 +3,7 @@ * Linkit Autocomplete based on jQuery UI. */ -(function ($, Drupal, _) { +(function ($, Drupal, once) { 'use strict'; @@ -118,9 +118,14 @@ function renderMenu(ul, items) { var self = this.element.autocomplete('instance'); - var grouped_items = _.groupBy(items, function (item) { - return item.hasOwnProperty('group') ? item.group : ''; - }); + var grouped_items = {}; + items.forEach(function (item) { + const group = item.hasOwnProperty('group') ? item.group : ''; + if (!grouped_items.hasOwnProperty(group)) { + grouped_items[group] = []; + } + grouped_items[group].push(item); + }) $.each(grouped_items, function (group, items) { if (group.length) { @@ -156,7 +161,7 @@ Drupal.behaviors.linkit_autocomplete = { attach: function (context) { // Act on textfields with the "form-linkit-autocomplete" class. - var $autocomplete = $(context).find('input.form-linkit-autocomplete').once('linkit-autocomplete'); + var $autocomplete = $(once('linkit-autocomplete', 'input.form-linkit-autocomplete', context)); if ($autocomplete.length) { $.widget('custom.autocomplete', $.ui.autocomplete, { _create: function () { @@ -185,9 +190,8 @@ }, detach: function (context, settings, trigger) { if (trigger === 'unload') { - $(context).find('input.form-linkit-autocomplete') - .removeOnce('linkit-autocomplete') - .autocomplete('destroy'); + once.remove('linkit-autocomplete', 'input.form-linkit-autocomplete', context) + .forEach((autocomplete) => $(autocomplete).autocomplete('destroy')); } } }; @@ -212,4 +216,4 @@ } }; -})(jQuery, Drupal, _); +})(jQuery, Drupal, once); diff --git a/js/linkit.filter_html.admin.js b/js/linkit.filter_html.admin.js index 3807f6e..8295286 100644 --- a/js/linkit.filter_html.admin.js +++ b/js/linkit.filter_html.admin.js @@ -3,7 +3,7 @@ * Send events to add or remove a tags to the filter_html allowed tags. */ -(function ($, Drupal, document) { +(function ($, Drupal, document, once) { 'use strict'; @@ -19,12 +19,15 @@ attach: function (context) { var selector = '[data-drupal-selector="edit-filters-linkit-status"]'; var feature = editorFeature(); - $(context).find(selector).once('filters-linkit-status').each(function () { - $(this).on('click', function () { - var eventName = $(this).is(':checked') ? 'drupalEditorFeatureAdded' : 'drupalEditorFeatureRemoved'; - $(document).trigger(eventName, feature); + + once('filters-linkit-status', selector, context) + .forEach((checkbox) => { + const $checkbox = $(checkbox); + $checkbox.on('click', function () { + var eventName = $(this).is(':checked') ? 'drupalEditorFeatureAdded' : 'drupalEditorFeatureRemoved'; + $(document).trigger(eventName, feature); + }); }); - }); } }; @@ -48,4 +51,4 @@ return linkitFeature; } -})(jQuery, Drupal, document); +})(jQuery, Drupal, document, once); diff --git a/linkit.info.yml b/linkit.info.yml index 2753daf..56ed851 100644 --- a/linkit.info.yml +++ b/linkit.info.yml @@ -2,7 +2,8 @@ name: Linkit type: module description: 'Provides an easy interface for internal and external linking with wysiwyg editors.' package: User interface -core_version_requirement: ^8.8 || ^9 || ^10 +core_version_requirement: ^9.4 || ^10 configure: entity.linkit_profile.collection test_dependencies: - imce:imce + - drupal:ckeditor diff --git a/linkit.libraries.yml b/linkit.libraries.yml index 2750933..bb04aed 100644 --- a/linkit.libraries.yml +++ b/linkit.libraries.yml @@ -23,13 +23,17 @@ linkit.autocomplete: dependencies: - linkit/linkit.base - core/drupal.ajax - - core/jquery.ui.autocomplete - - core/underscore + - core/drupal.autocomplete + - core/once linkit.filter_html.admin: version: VERSION js: js/linkit.filter_html.admin.js: {} + dependencies: + - core/jquery + - core/drupal + - core/once ckeditor5: version: VERSION @@ -41,5 +45,4 @@ ckeditor5: dependencies: - core/jquery - core/drupal.autocomplete - - core/underscore - core/drupal.ajax diff --git a/src/Plugin/Linkit/Matcher/EntityMatcher.php b/src/Plugin/Linkit/Matcher/EntityMatcher.php index ebb9780..e48c6af 100644 --- a/src/Plugin/Linkit/Matcher/EntityMatcher.php +++ b/src/Plugin/Linkit/Matcher/EntityMatcher.php @@ -322,6 +322,7 @@ class EntityMatcher extends ConfigurableMatcherBase { public function execute($string) { $suggestions = new SuggestionCollection(); $query = $this->buildEntityQuery($string); + $query->accessCheck(TRUE); $query_result = $query->execute(); $url_results = $this->findEntityIdByUrl($string); $result = array_merge($query_result, $url_results); diff --git a/src/Plugin/Linkit/Matcher/FileMatcher.php b/src/Plugin/Linkit/Matcher/FileMatcher.php index 9d05089..cc0fba3 100644 --- a/src/Plugin/Linkit/Matcher/FileMatcher.php +++ b/src/Plugin/Linkit/Matcher/FileMatcher.php @@ -4,6 +4,7 @@ namespace Drupal\linkit\Plugin\Linkit\Matcher; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\file\FileInterface; use Drupal\image\Entity\ImageStyle; use Drupal\linkit\Utility\LinkitXss; @@ -57,7 +58,7 @@ class FileMatcher extends EntityMatcher { public function defaultConfiguration() { return [ 'file_extensions' => '', - 'file_status' => FILE_STATUS_PERMANENT, + 'file_status' => FileInterface::STATUS_PERMANENT, 'images' => [ 'show_dimensions' => FALSE, 'show_thumbnail' => FALSE, @@ -226,7 +227,7 @@ class FileMatcher extends EntityMatcher { */ protected function buildPath(EntityInterface $entity) { /** @var \Drupal\file\FileInterface $entity */ - return file_url_transform_relative(file_create_url($entity->getFileUri())); + return \Drupal::service('file_url_generator')->generateString($entity->getFileUri()); } } diff --git a/src/Plugin/Linkit/Matcher/NodeMatcher.php b/src/Plugin/Linkit/Matcher/NodeMatcher.php index f40c7c0..b098546 100644 --- a/src/Plugin/Linkit/Matcher/NodeMatcher.php +++ b/src/Plugin/Linkit/Matcher/NodeMatcher.php @@ -88,7 +88,7 @@ class NodeMatcher extends EntityMatcher { if ($this->configuration['include_unpublished'] == FALSE) { $query->condition('status', NodeInterface::PUBLISHED); } - elseif (count($this->moduleHandler->getImplementations('node_grants')) === 0) { + elseif (!$this->moduleHandler->hasImplementations('node_grants')) { if (($this->currentUser->hasPermission('bypass node access') || $this->currentUser->hasPermission('view any unpublished content'))) { // User can see all content, no check necessary. } diff --git a/src/Plugin/Linkit/Substitution/File.php b/src/Plugin/Linkit/Substitution/File.php index c441dfc..614af3a 100644 --- a/src/Plugin/Linkit/Substitution/File.php +++ b/src/Plugin/Linkit/Substitution/File.php @@ -24,7 +24,7 @@ class File extends PluginBase implements SubstitutionInterface { public function getUrl(EntityInterface $entity) { $url = new GeneratedUrl(); /** @var \Drupal\file\FileInterface $entity */ - $url->setGeneratedUrl(file_create_url($entity->getFileUri())); + $url->setGeneratedUrl(\Drupal::service('file_url_generator')->generateAbsoluteString($entity->getFileUri())); $url->addCacheableDependency($entity); return $url; } diff --git a/src/Plugin/Linkit/Substitution/Media.php b/src/Plugin/Linkit/Substitution/Media.php index 9cdcb1c..bd30f39 100644 --- a/src/Plugin/Linkit/Substitution/Media.php +++ b/src/Plugin/Linkit/Substitution/Media.php @@ -48,7 +48,7 @@ class Media extends PluginBase implements SubstitutionInterface, ContainerFactor if ($source_field && $entity->hasField($source_field->getName()) && $entity->get($source_field->getName())->entity instanceof FileInterface) { /** @var \Drupal\file\FileInterface $file */ $file = $entity->get($source_field->getName())->entity; - $url->setGeneratedUrl(file_create_url($file->getFileUri())); + $url->setGeneratedUrl(\Drupal::service('file_url_generator')->generateAbsoluteString($file->getFileUri())); $url->addCacheableDependency($entity); return $url; } diff --git a/tests/linkit_test/linkit_test.info.yml b/tests/linkit_test/linkit_test.info.yml index 3c93d6d..9cb8a0a 100644 --- a/tests/linkit_test/linkit_test.info.yml +++ b/tests/linkit_test/linkit_test.info.yml @@ -2,7 +2,6 @@ name: 'Linkit test module' description: 'Support module for Linkit testing.' package: Testing type: module -core_version_requirement: ^8.8 || ^9 dependencies: - linkit:linkit - drupal:field diff --git a/tests/src/Functional/LinkitBrowserTestBase.php b/tests/src/Functional/LinkitBrowserTestBase.php index 987ccff..7a669fe 100644 --- a/tests/src/Functional/LinkitBrowserTestBase.php +++ b/tests/src/Functional/LinkitBrowserTestBase.php @@ -14,7 +14,7 @@ abstract class LinkitBrowserTestBase extends BrowserTestBase { * * @var array */ - public static $modules = ['linkit', 'linkit_test', 'block']; + protected static $modules = ['linkit', 'linkit_test', 'block']; /** * {@inheritdoc} diff --git a/tests/src/Functional/LinkitUpdateTest.php b/tests/src/Functional/LinkitUpdateTest.php deleted file mode 100644 index 851e6eb..0000000 --- a/tests/src/Functional/LinkitUpdateTest.php +++ /dev/null @@ -1,121 +0,0 @@ -configFactory = $this->container->get('config.factory'); - } - - /** - * Set database dump files to be used. - */ - protected function setDatabaseDumpFiles() { - $this->databaseDumpFiles = [ - __DIR__ . '/../../../tests/fixtures/update/drupal-8.linkit-enabled.standard.php.gz', - __DIR__ . '/../../../tests/fixtures/update/linkit-additions.php', - ]; - } - - /** - * Tests linkit_update_X. - */ - public function testLinkitUpdate8500() { - if (version_compare(\Drupal::VERSION, '9', '>=')) { - $this->markTestSkipped('This test is only for Drupal 8'); - } - - $editor = $this->configFactory->get('editor.editor.format_1'); - $this->assertNotEmpty($editor->get('settings.plugins.linkit'), 'We got old linkit settings in the editor configuration.'); - $format_1_linkit_profile = $editor->get('settings.plugins.linkit.linkit_profile'); - - $editor = $this->configFactory->get('editor.editor.format_2'); - $this->assertNotEmpty($editor->get('settings.plugins.linkit'), 'We got old linkit settings in the editor configuration.'); - $format_2_linkit_profile = $editor->get('settings.plugins.linkit.linkit_profile'); - - $editor = $this->configFactory->get('editor.editor.format_3'); - $this->assertNotEmpty($editor->get('settings.plugins.linkit'), 'We got old linkit settings in the editor configuration.'); - $format_3_linkit_profile = $editor->get('settings.plugins.linkit.linkit_profile'); - - $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile'); - $this->assertNotNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.result_description'), 'Profile have result_description'); - $this->assertNotNull($test_profile->get('third_party_settings.imce.use'), 'Profile have imce use'); - $this->assertNotNull($test_profile->get('third_party_settings.imce.scheme'), 'Profile have imce scheme'); - - $this->runUpdates(); - - $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile'); - $this->assertEquals(NULL, $test_profile->get('attributes'), 'Attributes are deleted from the profile.'); - $this->assertEquals('canonical', $test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.substitution_type'), 'Content matcher has a substitution type of canonical.'); - $this->assertEquals('file', $test_profile->get('matchers.b8d6d672-6377-493f-b492-3cc69511cf17.settings.substitution_type'), 'File matcher has a substitution type of file.'); - $this->assertNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.result_description'), 'Profile does not have result_description'); - $this->assertNotNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.metadata'), 'Profile have metadata'); - $this->assertNull($test_profile->get('third_party_settings.imce.use'), 'Profile does not have imce use'); - $this->assertNull($test_profile->get('third_party_settings.imce.scheme'), 'Profile does not have imce scheme'); - - $editor = $this->configFactory->get('editor.editor.format_1'); - $this->assertNull($editor->get('settings.plugins.linkit'), 'Old linkit settings in the editor configuration is removed.'); - $this->assertEquals($editor->get('settings.toolbar.rows.0.1.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); - $this->assertNotEquals($editor->get('settings.toolbar.rows.0.1.items.1'), 'Linkit', 'Linkit plugin is removed from the toolbar.'); - $this->assertNotEmpty($editor->get('settings.plugins.drupallink.linkit_enabled'), 'Drupal link plugin has linkit enabled.'); - $this->assertEquals($editor->get('settings.plugins.drupallink.linkit_profile'), $format_1_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); - - $editor = $this->configFactory->get('editor.editor.format_2'); - $this->assertNull($editor->get('settings.plugins.linkit'), 'Old linkit settings in the editor configuration is removed.'); - $this->assertEquals($editor->get('settings.toolbar.rows.0.1.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); - $this->assertNotEmpty($editor->get('settings.plugins.drupallink.linkit_enabled'), 'Drupal link plugin has linkit enabled.'); - $this->assertEquals($editor->get('settings.plugins.drupallink.linkit_profile'), $format_2_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); - - $editor = $this->configFactory->get('editor.editor.format_3'); - $this->assertNull($editor->get('settings.plugins.linkit'), 'Old linkit settings in the editor configuration is removed.'); - $this->assertEquals($editor->get('settings.toolbar.rows.0.0.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); - $this->assertNotEmpty($editor->get('settings.plugins.drupallink.linkit_enabled'), 'Drupal link plugin has linkit enabled.'); - $this->assertEquals($editor->get('settings.plugins.drupallink.linkit_profile'), $format_3_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); - - $format = $this->configFactory->get('filter.format.format_1'); - $this->assertNotNull($format->get('filters.linkit'), 'Linkit filter is enabled.'); - $this->assertTrue($format->get('filters.linkit.weight') < $format->get('filters.filter_html.weight'), 'Linkit filter is running before filter_html.'); - - $format = $this->configFactory->get('filter.format.format_2'); - $this->assertNotNull($format->get('filters.linkit'), 'Linkit filter is enabled.'); - - $format = $this->configFactory->get('filter.format.format_3'); - $this->assertNotNull($format->get('filters.linkit'), 'Linkit filter is enabled.'); - - $htmlRestrictions = FilterFormat::load('format_1')->getHtmlRestrictions(); - $this->assertArrayHasKey("data-entity-type", $htmlRestrictions['allowed']['a']); - $this->assertArrayHasKey("data-entity-uuid", $htmlRestrictions['allowed']['a']); - $this->assertArrayHasKey("data-entity-substitution", $htmlRestrictions['allowed']['a']); - - $htmlRestrictions = FilterFormat::load('format_3')->getHtmlRestrictions(); - $this->assertArrayHasKey("data-entity-type", $htmlRestrictions['allowed']['a']); - $this->assertArrayHasKey("data-entity-uuid", $htmlRestrictions['allowed']['a']); - } - -} diff --git a/tests/src/FunctionalJavascript/LinkitDialogTest.php b/tests/src/FunctionalJavascript/LinkitDialogTest.php index 26eb74e..b53ccea 100644 --- a/tests/src/FunctionalJavascript/LinkitDialogTest.php +++ b/tests/src/FunctionalJavascript/LinkitDialogTest.php @@ -27,9 +27,8 @@ class LinkitDialogTest extends WebDriverTestBase { * * @var array */ - public static $modules = [ + protected static $modules = [ 'node', - 'ckeditor', 'filter', 'linkit', 'entity_test', @@ -58,9 +57,15 @@ class LinkitDialogTest extends WebDriverTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); + if (!in_array('ckeditor', $this->container->get('extension.list.module')->reset()->getList(), TRUE)) { + $this->markTestSkipped('CKEditor 4 module not available to install, skipping test.'); + } + $this->container->get('module_installer')->install(['ckeditor']); + $this->container = \Drupal::getContainer(); + $matcherManager = $this->container->get('plugin.manager.linkit.matcher'); /** @var \Drupal\linkit\MatcherInterface $plugin */ @@ -160,6 +165,9 @@ class LinkitDialogTest extends WebDriverTestBase { // Wait for the form to load. $web_assert->assertWaitOnAjaxRequest(); + // The dialog is not tall enough to allow the autocomplete to be visible. + $this->getSession()->executeScript("document.getElementById('drupal-modal').style.height = '200px';"); + // Find the href field. $href_field = $page->findField('attributes[href]'); diff --git a/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php b/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php index 7ab46ff..f7f4bd2 100644 --- a/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php +++ b/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php @@ -16,7 +16,7 @@ class LinkitFormatAdminTest extends WebDriverTestBase { * * @var array */ - public static $modules = ['editor', 'filter', 'linkit']; + protected static $modules = ['editor', 'filter', 'linkit']; /** * {@inheritdoc} @@ -26,7 +26,7 @@ class LinkitFormatAdminTest extends WebDriverTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $account = $this->drupalCreateUser([ diff --git a/tests/src/Kernel/AssertLinkitFilterTrait.php b/tests/src/Kernel/AssertLinkitFilterTrait.php index 24ca822..f098a33 100644 --- a/tests/src/Kernel/AssertLinkitFilterTrait.php +++ b/tests/src/Kernel/AssertLinkitFilterTrait.php @@ -29,7 +29,7 @@ trait AssertLinkitFilterTrait { protected function assertLinkitFilter(EntityInterface $entity, $langcode = LanguageInterface::LANGCODE_SITE_DEFAULT) { if ($entity->getEntityTypeId() === "file") { /** @var \Drupal\file\Entity\File $entity */ - $href = file_create_url($entity->getFileUri()); + $href = \Drupal::service('file_url_generator')->generateAbsoluteString($entity->getFileUri()); } else { $href = $entity->toUrl()->toString(); @@ -51,7 +51,7 @@ trait AssertLinkitFilterTrait { protected function assertLinkitFilterWithTitle(EntityInterface $entity, $langcode = LanguageInterface::LANGCODE_SITE_DEFAULT) { if ($entity->getEntityTypeId() === "file") { /** @var \Drupal\file\Entity\File $entity */ - $href = file_create_url($entity->getFileUri()); + $href = \Drupal::service('file_url_generator')->generateAbsoluteString($entity->getFileUri()); } else { $href = $entity->toUrl()->toString(); diff --git a/tests/src/Kernel/EntityMatcherDeriverTest.php b/tests/src/Kernel/EntityMatcherDeriverTest.php index cf3832a..c8c4c55 100644 --- a/tests/src/Kernel/EntityMatcherDeriverTest.php +++ b/tests/src/Kernel/EntityMatcherDeriverTest.php @@ -12,7 +12,7 @@ class EntityMatcherDeriverTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['block', 'block_content', 'node', 'field']; + protected static $modules = ['block', 'block_content', 'node', 'field']; /** * The matcher manager. @@ -24,7 +24,7 @@ class EntityMatcherDeriverTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installConfig(['block_content']); diff --git a/tests/src/Kernel/LinkitAutocompleteTest.php b/tests/src/Kernel/LinkitAutocompleteTest.php index 5eae284..a559571 100644 --- a/tests/src/Kernel/LinkitAutocompleteTest.php +++ b/tests/src/Kernel/LinkitAutocompleteTest.php @@ -24,7 +24,7 @@ class LinkitAutocompleteTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = ['entity_test', 'language']; + protected static $modules = ['entity_test', 'language']; /** * The linkit profile. @@ -50,7 +50,7 @@ class LinkitAutocompleteTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create user 1 who has special permissions. diff --git a/tests/src/Kernel/LinkitEditorLinkDialogTest.php b/tests/src/Kernel/LinkitEditorLinkDialogTest.php index 16d0645..6c48b58 100644 --- a/tests/src/Kernel/LinkitEditorLinkDialogTest.php +++ b/tests/src/Kernel/LinkitEditorLinkDialogTest.php @@ -38,16 +38,21 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = ['editor', 'ckeditor', 'entity_test']; + protected static $modules = ['editor', 'entity_test']; /** * Sets up the test. */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); + if (!in_array('ckeditor', $this->container->get('extension.list.module')->reset()->getList(), TRUE)) { + $this->markTestSkipped('CKEditor 4 module not available to install, skipping test.'); + } + $this->enableModules(['ckeditor']); + + $this->installEntitySchema('entity_test'); - $this->installSchema('system', ['key_value_expire']); // Create a profile. $this->linkitProfile = $this->createProfile(); diff --git a/tests/src/Kernel/LinkitFilterEntityTest.php b/tests/src/Kernel/LinkitFilterEntityTest.php index 945b747..1de2c45 100644 --- a/tests/src/Kernel/LinkitFilterEntityTest.php +++ b/tests/src/Kernel/LinkitFilterEntityTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\linkit\Kernel; use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTestMul; use Drupal\file\Entity\File; +use Drupal\file\FileInterface; use Drupal\filter\FilterPluginCollection; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\Traits\Core\PathAliasTestTrait; @@ -26,7 +27,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = [ + protected static $modules = [ 'filter', 'entity_test', 'path', @@ -38,7 +39,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installEntitySchema('entity_test'); @@ -122,7 +123,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', 'filemime' => 'text/plain', - 'status' => FILE_STATUS_PERMANENT, + 'status' => FileInterface::STATUS_PERMANENT, ]); $file->save(); diff --git a/tests/src/Kernel/LinkitKernelTestBase.php b/tests/src/Kernel/LinkitKernelTestBase.php index d04a2bc..b54e917 100644 --- a/tests/src/Kernel/LinkitKernelTestBase.php +++ b/tests/src/Kernel/LinkitKernelTestBase.php @@ -16,7 +16,7 @@ abstract class LinkitKernelTestBase extends KernelTestBase { * * @var array */ - public static $modules = [ + protected static $modules = [ 'system', 'user', 'filter', @@ -28,7 +28,7 @@ abstract class LinkitKernelTestBase extends KernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installSchema('system', 'sequences'); $this->installEntitySchema('user'); diff --git a/tests/src/Kernel/Matchers/ContactFormMatcherTest.php b/tests/src/Kernel/Matchers/ContactFormMatcherTest.php index 7d80503..37db55f 100644 --- a/tests/src/Kernel/Matchers/ContactFormMatcherTest.php +++ b/tests/src/Kernel/Matchers/ContactFormMatcherTest.php @@ -17,7 +17,7 @@ class ContactFormMatcherTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = ['contact']; + protected static $modules = ['contact']; /** * The matcher manager. @@ -29,13 +29,13 @@ class ContactFormMatcherTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create user 1 who has special permissions. $this->createUser(); - \Drupal::currentUser()->setAccount($this->createUser([], ['access site-wide contact form', 'view test entity translations'])); + \Drupal::currentUser()->setAccount($this->createUser([], ['access site-wide contact form'])); $this->manager = $this->container->get('plugin.manager.linkit.matcher'); diff --git a/tests/src/Kernel/Matchers/FileMatcherTest.php b/tests/src/Kernel/Matchers/FileMatcherTest.php index d5829d1..1c90f1c 100644 --- a/tests/src/Kernel/Matchers/FileMatcherTest.php +++ b/tests/src/Kernel/Matchers/FileMatcherTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\linkit\Kernel\Matchers; use Drupal\file\Entity\File; +use Drupal\file\FileInterface; use Drupal\Tests\linkit\Kernel\LinkitKernelTestBase; /** @@ -17,7 +18,7 @@ class FileMatcherTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = ['file_test', 'file']; + protected static $modules = ['file_test', 'file']; /** * The matcher manager. @@ -29,11 +30,10 @@ class FileMatcherTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installEntitySchema('file'); - $this->installSchema('system', ['key_value_expire']); $this->installSchema('file', ['file_usage']); $this->manager = $this->container->get('plugin.manager.linkit.matcher'); @@ -45,7 +45,7 @@ class FileMatcherTest extends LinkitKernelTestBase { 'filename' => 'image-test.' . $ext, 'uri' => 'public://image-test.' . $ext, 'filemime' => 'text/plain', - 'status' => FILE_STATUS_PERMANENT, + 'status' => FileInterface::STATUS_PERMANENT, ]); $file->save(); } diff --git a/tests/src/Kernel/Matchers/MediaMatcherTest.php b/tests/src/Kernel/Matchers/MediaMatcherTest.php index 1302bdf..64013a6 100644 --- a/tests/src/Kernel/Matchers/MediaMatcherTest.php +++ b/tests/src/Kernel/Matchers/MediaMatcherTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\linkit\Kernel\Matchers; use Drupal\file\Entity\File; +use Drupal\file\FileInterface; use Drupal\media\Entity\Media; use Drupal\media\Entity\MediaType; use Drupal\Tests\linkit\Kernel\LinkitKernelTestBase; @@ -19,7 +20,7 @@ class MediaMatcherTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = ['file_test', 'file', 'media', 'image', 'field']; + protected static $modules = ['file_test', 'file', 'media', 'image', 'field']; /** * The matcher manager. @@ -31,13 +32,12 @@ class MediaMatcherTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { 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'); @@ -64,7 +64,7 @@ class MediaMatcherTest extends LinkitKernelTestBase { 'filename' => 'image-test.' . $ext, 'uri' => 'public://image-test.' . $ext, 'filemime' => 'text/plain', - 'status' => FILE_STATUS_PERMANENT, + 'status' => FileInterface::STATUS_PERMANENT, ]); $file->save(); diff --git a/tests/src/Kernel/Matchers/NodeMatcherTest.php b/tests/src/Kernel/Matchers/NodeMatcherTest.php index f225eaf..4ee67a8 100644 --- a/tests/src/Kernel/Matchers/NodeMatcherTest.php +++ b/tests/src/Kernel/Matchers/NodeMatcherTest.php @@ -18,7 +18,7 @@ class NodeMatcherTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = ['field', 'node', 'content_moderation', 'workflows']; + protected static $modules = ['field', 'node', 'content_moderation', 'workflows']; /** * The matcher manager. @@ -30,7 +30,7 @@ class NodeMatcherTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installEntitySchema('node'); diff --git a/tests/src/Kernel/Matchers/TermMatcherTest.php b/tests/src/Kernel/Matchers/TermMatcherTest.php index c3a3a68..98d7020 100644 --- a/tests/src/Kernel/Matchers/TermMatcherTest.php +++ b/tests/src/Kernel/Matchers/TermMatcherTest.php @@ -20,7 +20,7 @@ class TermMatcherTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = ['taxonomy']; + protected static $modules = ['taxonomy']; /** * The matcher manager. @@ -32,7 +32,7 @@ class TermMatcherTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create user 1 who has special permissions. diff --git a/tests/src/Kernel/Matchers/UserMatcherTest.php b/tests/src/Kernel/Matchers/UserMatcherTest.php index fbe7060..d2ef802 100644 --- a/tests/src/Kernel/Matchers/UserMatcherTest.php +++ b/tests/src/Kernel/Matchers/UserMatcherTest.php @@ -22,7 +22,7 @@ class UserMatcherTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create user 1 who has special permissions. diff --git a/tests/src/Kernel/SubstitutionPluginTest.php b/tests/src/Kernel/SubstitutionPluginTest.php index 0bc6202..1037b09 100644 --- a/tests/src/Kernel/SubstitutionPluginTest.php +++ b/tests/src/Kernel/SubstitutionPluginTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\linkit\Kernel; use Drupal\Core\Site\Settings; use Drupal\entity_test\Entity\EntityTest; use Drupal\file\Entity\File; +use Drupal\file\FileInterface; use Drupal\linkit\Plugin\Linkit\Substitution\Canonical as CanonicalSubstitutionPlugin; use Drupal\linkit\Plugin\Linkit\Substitution\File as FileSubstitutionPlugin; use Drupal\linkit\Plugin\Linkit\Substitution\Media as MediaSubstitutionPlugin; @@ -38,7 +39,7 @@ class SubstitutionPluginTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = [ + protected static $modules = [ 'file', 'entity_test', 'media', @@ -50,7 +51,7 @@ class SubstitutionPluginTest extends LinkitKernelTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $this->substitutionManager = $this->container->get('plugin.manager.linkit.substitution'); $this->entityTypeManager = $this->container->get('entity_type.manager'); @@ -106,7 +107,7 @@ class SubstitutionPluginTest extends LinkitKernelTestBase { 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', 'filemime' => 'text/plain', - 'status' => FILE_STATUS_PERMANENT, + 'status' => FileInterface::STATUS_PERMANENT, ]); $file->save(); $this->assertEquals($GLOBALS['base_url'] . '/' . $this->siteDirectory . '/files/druplicon.txt', $fileSubstitution->getUrl($file)->getGeneratedUrl()); @@ -158,7 +159,7 @@ class SubstitutionPluginTest extends LinkitKernelTestBase { 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', 'filemime' => 'text/plain', - 'status' => FILE_STATUS_PERMANENT, + 'status' => FileInterface::STATUS_PERMANENT, ]); $file->save();