Skip to content
Snippets Groups Projects
Commit 8bba2799 authored by Mark Fullmer's avatar Mark Fullmer Committed by Mark Fullmer
Browse files

Issue #3289033 by taniachque, mark_fullmer, reenaraghavan, neclimdul, Libbna,...

Issue #3289033 by taniachque, mark_fullmer, reenaraghavan, neclimdul, Libbna, omkar-pd, Rajab Natshah, yashingole, svendecabooter: Automated Drupal 10 compatibility fixes
parent 75a7ced1
No related branches found
No related tags found
No related merge requests found
{
"name": "drupal/pathologic",
"description": "Helps avoid broken links and incorrect paths in content.",
"type": "drupal-module",
"license": "GPL-2.0+",
"minimum-stability": "dev",
"require": {
"drupal/core": "^9 || ^10"
}
}
name: Pathologic
description: 'Helps avoid broken links and incorrect paths in content.'
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
package: 'Input filters'
dependencies:
- drupal:filter
......
......@@ -184,7 +184,8 @@ function _pathologic_replace($matches) {
if (isset($parts['scheme']) && $parts['scheme'] === 'files') {
// Path Filter "files:" support. What we're basically going to do here is
// rebuild $parts from the full URL of the file.
$new_parts = parse_url(file_create_url(\Drupal::config('system.file')->get('default_scheme') . '://' . $parts['path']));
$uri = \Drupal::config('system.file')->get('default_scheme') . '://' . $parts['path'];
$new_parts = parse_url(\Drupal::service('file_url_generator')->generateAbsoluteString($uri));
// If there were query parts from the original parsing, copy them over.
if (!empty($parts['query'])) {
$new_parts['query'] = $parts['query'];
......
......@@ -16,7 +16,7 @@ class PathologicSettingsCommon {
*
* @param array $defaults
* An array of default values for the configuration form fields.
* @return
* @return array
* The common form elements
*/
public function commonSettingsForm(array $defaults) {
......
name: Pathologic Test
description: Module which implements hook_pathologic_alter() for testing that functionality.
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10
package: Testing
dependencies:
- drupal:filter
......
......@@ -31,16 +31,8 @@ class PathologicTest extends BrowserTestBase {
global $script_path;
// Start by testing our function to build protocol-relative URLs
$this->assertEqual(
_pathologic_url_to_protocol_relative('http://example.com/foo/bar'),
'//example.com/foo/bar',
t('Protocol-relative URL creation with http:// URL')
);
$this->assertEqual(
_pathologic_url_to_protocol_relative('https://example.org/baz'),
'//example.org/baz',
t('Protocol-relative URL creation with https:// URL')
);
$this->assertEquals(_pathologic_url_to_protocol_relative('http://example.com/foo/bar'), '//example.com/foo/bar', t('Protocol-relative URL creation with http:// URL'));
$this->assertEquals(_pathologic_url_to_protocol_relative('https://example.org/baz'), '//example.org/baz', t('Protocol-relative URL creation with https:// URL'));
// Build some paths to check against
$test_paths =[
......@@ -98,78 +90,26 @@ class PathologicTest extends BrowserTestBase {
'@ps' => $protocol_style,
];
$this->assertEqual(
check_markup('<a href="foo"><img src="foo/bar" /></a>', $format_id),
'<a href="' . $paths['foo'] . '"><img src="' . $paths['foo/bar'] . '" /></a>',
t('Simple paths. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEqual(
check_markup('<a href="index.php?q=foo"></a><a href="index.php?q=foo/bar&baz=qux"></a>', $format_id),
'<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>',
t('D7 and earlier-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEqual(
check_markup('<a href="index.php/foo"></a><a href="index.php/foo/bar?baz=qux"></a>', $format_id),
'<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>',
t('D8-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEqual(
check_markup('<form action="foo/bar?baz"><IMG LONGDESC="foo/bar?baz=qux" /></a>', $format_id),
'<form action="' . $paths['foo/bar?baz'] . '"><IMG LONGDESC="' . $paths['foo/bar?baz=qux'] . '" /></a>',
t('Paths with query string. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEqual(
check_markup('<a href="foo/bar#baz">', $format_id),
'<a href="' . $paths['foo/bar#baz'] . '">',
t('Path with fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEqual(
check_markup('<a href="#foo">', $format_id),
'<a href="#foo">',
t('Fragment-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEquals(check_markup('<a href="foo"><img src="foo/bar" /></a>', $format_id), '<a href="' . $paths['foo'] . '"><img src="' . $paths['foo/bar'] . '" /></a>', t('Simple paths. Clean URLs: @clean; protocol style: @ps.', $t10ns));
$this->assertEquals(check_markup('<a href="index.php?q=foo"></a><a href="index.php?q=foo/bar&baz=qux"></a>', $format_id), '<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>', t('D7 and earlier-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns));
$this->assertEquals(check_markup('<a href="index.php/foo"></a><a href="index.php/foo/bar?baz=qux"></a>', $format_id), '<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>', t('D8-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns));
$this->assertEquals(check_markup('<form action="foo/bar?baz"><IMG LONGDESC="foo/bar?baz=qux" /></a>', $format_id), '<form action="' . $paths['foo/bar?baz'] . '"><IMG LONGDESC="' . $paths['foo/bar?baz=qux'] . '" /></a>', t('Paths with query string. Clean URLs: @clean; protocol style: @ps.', $t10ns));
$this->assertEquals(check_markup('<a href="foo/bar#baz">', $format_id), '<a href="' . $paths['foo/bar#baz'] . '">', t('Path with fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns));
$this->assertEquals(check_markup('<a href="#foo">', $format_id), '<a href="#foo">', t('Fragment-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns));
// @see https://drupal.org/node/2208223
$this->assertEqual(
check_markup('<a href="#">', $format_id),
'<a href="#">',
t('Hash-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEqual(
check_markup('<a href="foo/bar?baz=qux&amp;quux=quuux#quuuux">', $format_id),
'<a href="' . $paths['foo/bar?baz=qux&amp;quux=quuux#quuuux'] . '">',
t('Path with query string and fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEqual(
check_markup('<a href="foo%20bar?baz=qux%26quux">', $format_id),
'<a href="' . $paths['foo%20bar?baz=qux%26quux'] . '">',
t('Path with URL encoded parts. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertEqual(
check_markup('<a href="/"></a>', $format_id),
'<a href="' . $paths['/'] . '"></a>',
t('Path with just slash. Clean URLs: @clean; protocol style: @ps', $t10ns)
);
$this->assertEquals(check_markup('<a href="#">', $format_id), '<a href="#">', t('Hash-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns));
$this->assertEquals(check_markup('<a href="foo/bar?baz=qux&amp;quux=quuux#quuuux">', $format_id), '<a href="' . $paths['foo/bar?baz=qux&amp;quux=quuux#quuuux'] . '">', t('Path with query string and fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns));
$this->assertEquals(check_markup('<a href="foo%20bar?baz=qux%26quux">', $format_id), '<a href="' . $paths['foo%20bar?baz=qux%26quux'] . '">', t('Path with URL encoded parts. Clean URLs: @clean; protocol style: @ps.', $t10ns));
$this->assertEquals(check_markup('<a href="/"></a>', $format_id), '<a href="' . $paths['/'] . '"></a>', t('Path with just slash. Clean URLs: @clean; protocol style: @ps', $t10ns));
}
global $base_path;
$this->assertEqual(
check_markup('<a href="' . $base_path . 'foo">bar</a>', $format_id),
'<a href="' . _pathologic_content_url('foo', ['absolute' => FALSE]) .'">bar</a>',
t('Paths beginning with $base_path (like WYSIWYG editors like to make)')
);
$this->assertEquals(check_markup('<a href="' . $base_path . 'foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', ['absolute' => FALSE]) .'">bar</a>', t('Paths beginning with $base_path (like WYSIWYG editors like to make)'));
global $base_url;
$this->assertEqual(
check_markup('<a href="' . $base_url . '/foo">bar</a>', $format_id),
'<a href="' . _pathologic_content_url('foo', ['absolute' => FALSE]) .'">bar</a>',
t('Paths beginning with $base_url')
);
$this->assertEquals(check_markup('<a href="' . $base_url . '/foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', ['absolute' => FALSE]) .'">bar</a>', t('Paths beginning with $base_url'));
// @see http://drupal.org/node/1617944
$this->assertEqual(
check_markup('<a href="//example.com/foo">bar</a>', $format_id),
'<a href="//example.com/foo">bar</a>',
t('Off-site schemeless URLs (//example.com/foo) ignored')
);
$this->assertEquals(check_markup('<a href="//example.com/foo">bar</a>', $format_id), '<a href="//example.com/foo">bar</a>', t('Off-site schemeless URLs (//example.com/foo) ignored'));
// Test internal: and all base paths
$format_id = _pathologic_build_format([
......@@ -181,42 +121,14 @@ class PathologicTest extends BrowserTestBase {
]);
// @see https://drupal.org/node/2030789
$this->assertEqual(
check_markup('<a href="//example.org/foo">bar</a>', $format_id),
'<a href="' . _pathologic_content_url('foo', ['absolute' => TRUE]) . '">bar</a>',
t('On-site schemeless URLs processed')
);
$this->assertEqual(
check_markup('<a href="internal:foo">', $format_id),
'<a href="' . _pathologic_content_url('foo', ['absolute' => TRUE]) . '">',
t('Path Filter compatibility (internal:)')
);
$this->assertEqual(
check_markup('<a href="files:image.jpeg">look</a>', $format_id),
'<a href="' . _pathologic_content_url(file_create_url( \Drupal::config('system.file')->get('default_scheme') . '://image.jpeg'), ['absolute' => TRUE]) . '">look</a>',
t('Path Filter compatibility (files:)')
);
$this->assertEqual(
check_markup('<a href="http://example.com/qux/foo"><picture><source srcset="http://example.org/bar.jpeg" /><img src="http://example.org/bar.jpeg" longdesc="/bananas/baz" /></picture></a>', $format_id),
'<a href="' . _pathologic_content_url('foo', ['absolute' => TRUE]) . '"><picture><source srcset="' . _pathologic_content_url('bar.jpeg', ['absolute' => TRUE]) . '" /><img src="' . _pathologic_content_url('bar.jpeg', ['absolute' => TRUE]) . '" longdesc="' . _pathologic_content_url('baz', ['absolute' => TRUE]) . '" /></picture></a>',
t('"All base paths for this site" functionality')
);
$this->assertEqual(
check_markup('<a href="webcal:foo">bar</a>', $format_id),
'<a href="webcal:foo">bar</a>',
t('URLs with likely protocols are ignored')
);
$this->assertEquals(check_markup('<a href="//example.org/foo">bar</a>', $format_id), '<a href="' . _pathologic_content_url('foo', ['absolute' => TRUE]) . '">bar</a>', t('On-site schemeless URLs processed'));
$this->assertEquals(check_markup('<a href="internal:foo">', $format_id), '<a href="' . _pathologic_content_url('foo', ['absolute' => TRUE]) . '">', t('Path Filter compatibility (internal:)'));
$this->assertEquals(check_markup('<a href="files:image.jpeg">look</a>', $format_id), '<a href="' . _pathologic_content_url(\Drupal::service('file_url_generator')->generateAbsoluteString( \Drupal::config('system.file')->get('default_scheme') . '://image.jpeg'), ['absolute' => TRUE]) . '">look</a>', t('Path Filter compatibility (files:)'));
$this->assertEquals(check_markup('<a href="http://example.com/qux/foo"><picture><source srcset="http://example.org/bar.jpeg" /><img src="http://example.org/bar.jpeg" longdesc="/bananas/baz" /></picture></a>', $format_id), '<a href="' . _pathologic_content_url('foo', ['absolute' => TRUE]) . '"><picture><source srcset="' . _pathologic_content_url('bar.jpeg', ['absolute' => TRUE]) . '" /><img src="' . _pathologic_content_url('bar.jpeg', ['absolute' => TRUE]) . '" longdesc="' . _pathologic_content_url('baz', ['absolute' => TRUE]) . '" /></picture></a>', t('"All base paths for this site" functionality'));
$this->assertEquals(check_markup('<a href="webcal:foo">bar</a>', $format_id), '<a href="webcal:foo">bar</a>', t('URLs with likely protocols are ignored'));
// Test hook_pathologic_alter() implementation.
$this->assertEqual(
check_markup('<a href="foo?test=add_foo_qpart">', $format_id),
'<a href="' . _pathologic_content_url('foo', ['absolute' => TRUE, 'query' => ['test' => 'add_foo_qpart', 'foo' => 'bar']]) . '">',
t('hook_pathologic_alter(): Alter $url_params')
);
$this->assertEqual(
check_markup('<a href="bar?test=use_original">', $format_id),
'<a href="bar?test=use_original">',
t('hook_pathologic_alter(): Passthrough with use_original option')
);
$this->assertEquals(check_markup('<a href="foo?test=add_foo_qpart">', $format_id), '<a href="' . _pathologic_content_url('foo', ['absolute' => TRUE, 'query' => ['test' => 'add_foo_qpart', 'foo' => 'bar']]) . '">', t('hook_pathologic_alter(): Alter $url_params'));
$this->assertEquals(check_markup('<a href="bar?test=use_original">', $format_id), '<a href="bar?test=use_original">', t('hook_pathologic_alter(): Passthrough with use_original option'));
$this->assertEquals(
'<a href="http://cdn.example.com/bar?test=external">',
check_markup('<a href="bar?test=external">', $format_id),
......@@ -241,11 +153,7 @@ class PathologicTest extends BrowserTestBase {
->set('protocol_style', 'proto-rel')
->set('local_paths', 'http://example.com/')
->save();
$this->assertEqual(
check_markup('<img src="http://example.com/foo.jpeg" />', $format_id),
'<img src="' . _pathologic_url_to_protocol_relative(_pathologic_content_url('foo.jpeg', ['absolute' => TRUE])) . '" />',
t('Use global settings when so configured on the format')
);
$this->assertEquals(check_markup('<img src="http://example.com/foo.jpeg" />', $format_id), '<img src="' . _pathologic_url_to_protocol_relative(_pathologic_content_url('foo.jpeg', ['absolute' => TRUE])) . '" />', t('Use global settings when so configured on the format'));
// Test really broken URLs.
// @see https://www.drupal.org/node/2602312
......@@ -297,11 +205,11 @@ function _pathologic_content_url($path, $options) {
*
* @param $settings
* An array of settings for the Pathologic instance on the format.
* @return
* @return string
* A format machine name (consisting of random characters) for the format.
*/
function _pathologic_build_format($settings) {
$format_id = user_password();
$format_id = \Drupal::service('password_generator')->generate();
$format = FilterFormat::create([
'format' => $format_id,
'name' => $format_id,
......
......@@ -24,7 +24,7 @@ class PathologicUITest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
......@@ -45,20 +45,20 @@ class PathologicUITest extends BrowserTestBase {
*/
public function doTestSettingsForm() {
$this->drupalGet('admin/config/content/pathologic');
$this->assertText('Pathologic configuration');
$this->assertSession()->pageTextContains('Pathologic configuration');
// Test submit form.
$this->assertNoFieldChecked('edit-protocol-style-proto-rel');
$this->assertSession()->checkboxNotChecked('edit-protocol-style-proto-rel');
$edit = [
'protocol_style' => 'proto-rel',
'local_paths' => 'http://example.com/',
];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$this->assertText('The configuration options have been saved.');
$this->assertFieldChecked('edit-protocol-style-proto-rel');
$this->assertText('http://example.com/');
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$this->assertSession()->checkboxChecked('edit-protocol-style-proto-rel');
$this->assertSession()->pageTextContains('http://example.com/');
$this->clickLink('Pathologic’s documentation');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......@@ -70,26 +70,26 @@ class PathologicUITest extends BrowserTestBase {
$this->drupalGet('/admin/config/content/formats/manage/plain_text');
// Select pathologic option.
$this->assertText('Correct URLs with Pathologic');
$this->assertNoFieldChecked('edit-filters-filter-pathologic-status');
$this->drupalPostForm(NULL, [
$this->assertSession()->pageTextContains('Correct URLs with Pathologic');
$this->assertSession()->checkboxNotChecked('edit-filters-filter-pathologic-status');
$this->submitForm([
'filters[filter_html_escape][status]' => FALSE,
'filters[filter_pathologic][status]' => '1',
], t('Save configuration'));
$this->drupalGet('/admin/config/content/formats/manage/plain_text');
$this->assertRaw('In most cases, Pathologic should be the <em>last</em> filter in the &ldquo;Filter processing order&rdquo; list.');
$this->assertText('Select whether Pathologic should use the global Pathologic settings');
$this->assertFieldChecked('edit-filters-filter-pathologic-status');
$this->drupalPostForm(NULL, [
$this->assertSession()->responseContains('In most cases, Pathologic should be the <em>last</em> filter in the &ldquo;Filter processing order&rdquo; list.');
$this->assertSession()->pageTextContains('Select whether Pathologic should use the global Pathologic settings');
$this->assertSession()->checkboxChecked('edit-filters-filter-pathologic-status');
$this->submitForm([
'filters[filter_pathologic][settings][settings_source]' => 'local',
'filters[filter_pathologic][settings][local_settings][protocol_style]' => 'full',
], t('Save configuration'));
$this->drupalGet('/admin/config/content/formats/manage/plain_text');
$this->assertFieldChecked('edit-filters-filter-pathologic-settings-settings-source-local');
$this->assertFieldChecked('edit-filters-filter-pathologic-settings-local-settings-protocol-style-full');
$this->assertText('Custom settings for this text format');
$this->assertSession()->checkboxChecked('edit-filters-filter-pathologic-settings-settings-source-local');
$this->assertSession()->checkboxChecked('edit-filters-filter-pathologic-settings-local-settings-protocol-style-full');
$this->assertSession()->pageTextContains('Custom settings for this text format');
}
/**
......@@ -101,11 +101,12 @@ class PathologicUITest extends BrowserTestBase {
'title[0][value]' => 'Test pathologic',
'body[0][value]' => '<a href="node/1">Test link</a>',
];
$this->drupalPostForm('node/add/page', $edit, t('Save'));
$this->drupalGet('node/add/page');
$this->submitForm($edit, t('Save'));
// Assert that the link is processed with Pathologic.
$this->clickLink('Test link');
$this->assertTitle('Test pathologic | Drupal');
$this->assertSession()->titleEquals('Test pathologic | Drupal');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment