Skip to content
Snippets Groups Projects
Commit 368d1ab6 authored by Derek Wright's avatar Derek Wright
Browse files

Issue #3157085 by dww: Convert Functional/PathologicTest.php to a Kernel test: translation cleanup:

- Don't use t() for the assertion messages.
- In cases we need placeholder substitution, use FormattableMarkup.

(cherry picked from commit f341179311f0228de681b149c1dccbc37636b465)
parent 1334b254
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\pathologic\Kernel;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
use Drupal\KernelTests\KernelTestBase;
......@@ -58,12 +59,12 @@ class PathologicTest extends KernelTestBase {
$this->assertSame(
'//example.com/foo/bar',
_pathologic_url_to_protocol_relative('http://example.com/foo/bar'),
t('Protocol-relative URL creation with http:// URL')
'Protocol-relative URL creation with http:// URL'
);
$this->assertSame(
'//example.org/baz',
_pathologic_url_to_protocol_relative('https://example.org/baz'),
t('Protocol-relative URL creation with https:// URL')
'Protocol-relative URL creation with https:// URL'
);
// Build some paths to check against.
......@@ -123,60 +124,60 @@ class PathologicTest extends KernelTestBase {
}
}
$t10ns = [
'@clean' => empty($script_path) ? t('Yes') : t('No'),
'@clean' => empty($script_path) ? 'Yes' : 'No',
'@ps' => $protocol_style,
];
$this->assertSame(
'<a href="' . $paths['foo'] . '"><img src="' . $paths['foo/bar'] . '" /></a>',
$this->runFilter('<a href="foo"><img src="foo/bar" /></a>'),
t('Simple paths. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('Simple paths. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertSame(
'<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>',
$this->runFilter('<a href="index.php?q=foo"></a><a href="index.php?q=foo/bar&baz=qux"></a>'),
t('D7 and earlier-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('D7 and earlier-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertSame(
'<a href="' . $paths['foo'] . '"></a><a href="' . $paths['foo/bar?baz=qux'] . '"></a>',
$this->runFilter('<a href="index.php/foo"></a><a href="index.php/foo/bar?baz=qux"></a>'),
t('D8-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('D8-style non-clean URLs. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertSame(
'<form action="' . $paths['foo/bar?baz'] . '"><IMG LONGDESC="' . $paths['foo/bar?baz=qux'] . '" /></a>',
$this->runFilter('<form action="foo/bar?baz"><IMG LONGDESC="foo/bar?baz=qux" /></a>'),
t('Paths with query string. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('Paths with query string. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertSame(
'<a href="' . $paths['foo/bar#baz'] . '">',
$this->runFilter('<a href="foo/bar#baz">'),
t('Path with fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('Path with fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertSame(
'<a href="#foo">',
$this->runFilter('<a href="#foo">'),
t('Fragment-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('Fragment-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
// @see https://drupal.org/node/2208223
$this->assertSame(
'<a href="#">',
$this->runFilter('<a href="#">'),
t('Hash-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('Hash-only href. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertSame(
'<a href="' . $paths['foo/bar?baz=qux&amp;quux=quuux#quuuux'] . '">',
$this->runFilter('<a href="foo/bar?baz=qux&amp;quux=quuux#quuuux">'),
t('Path with query string and fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('Path with query string and fragment. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertSame(
'<a href="' . $paths['foo%20bar?baz=qux%26quux'] . '">',
$this->runFilter('<a href="foo%20bar?baz=qux%26quux">'),
t('Path with URL encoded parts. Clean URLs: @clean; protocol style: @ps.', $t10ns)
new FormattableMarkup('Path with URL encoded parts. Clean URLs: @clean; protocol style: @ps.', $t10ns)
);
$this->assertSame(
'<a href="' . $paths['/'] . '"></a>',
$this->runFilter('<a href="/"></a>'),
t('Path with just slash. Clean URLs: @clean; protocol style: @ps', $t10ns)
new FormattableMarkup('Path with just slash. Clean URLs: @clean; protocol style: @ps', $t10ns)
);
}
......@@ -184,21 +185,21 @@ class PathologicTest extends KernelTestBase {
$this->assertSame(
'<a href="' . $this->pathologicContentUrl('foo', ['absolute' => FALSE]) . '">bar</a>',
$this->runFilter('<a href="' . $base_path . 'foo">bar</a>'),
t('Paths beginning with $base_path (like WYSIWYG editors like to make)')
'Paths beginning with base_path (like WYSIWYG editors like to make)'
);
global $base_url;
$this->assertSame(
'<a href="' . $this->pathologicContentUrl('foo', ['absolute' => FALSE]) . '">bar</a>',
$this->runFilter('<a href="' . $base_url . '/foo">bar</a>'),
t('Paths beginning with $base_url using @format_id', ['@format_id' => $this->formatId])
new FormattableMarkup('Paths beginning with $base_url using @format_id', ['@format_id' => $this->formatId])
);
// @see http://drupal.org/node/1617944
$this->assertSame(
'<a href="//example.com/foo">bar</a>',
$this->runFilter('<a href="//example.com/foo">bar</a>'),
t('Off-site schemeless URLs (//example.com/foo) ignored')
'Off-site schemeless URLs (//example.com/foo) ignored'
);
// Test internal: and all base paths.
......@@ -214,27 +215,27 @@ class PathologicTest extends KernelTestBase {
$this->assertSame(
'<a href="' . $this->pathologicContentUrl('foo', ['absolute' => TRUE]) . '">bar</a>',
$this->runFilter('<a href="//example.org/foo">bar</a>'),
t('On-site schemeless URLs processed')
'On-site schemeless URLs processed'
);
$this->assertSame(
'<a href="' . $this->pathologicContentUrl('foo', ['absolute' => TRUE]) . '">',
$this->runFilter('<a href="internal:foo">'),
t('Path Filter compatibility (internal:)')
'Path Filter compatibility (internal:)'
);
$this->assertSame(
'<a href="' . $this->pathologicContentUrl(\Drupal::service('file_url_generator')->generateAbsoluteString(\Drupal::config('system.file')->get('default_scheme') . '://image.jpeg'), []) . '">look</a>',
urldecode($this->runFilter('<a href="files:image.jpeg">look</a>')),
t('Path Filter compatibility (files:)')
'Path Filter compatibility (files:)'
);
$this->assertSame(
'<a href="' . $this->pathologicContentUrl('foo', ['absolute' => TRUE]) . '"><picture><source srcset="' . $this->pathologicContentUrl('bar.jpeg', ['absolute' => TRUE]) . '" /><img src="' . $this->pathologicContentUrl('bar.jpeg', ['absolute' => TRUE]) . '" longdesc="' . $this->pathologicContentUrl('baz', ['absolute' => TRUE]) . '" /></picture></a>',
$this->runFilter('<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>'),
t('"All base paths for this site" functionality')
'"All base paths for this site" functionality'
);
$this->assertSame(
'<a href="webcal:foo">bar</a>',
$this->runFilter('<a href="webcal:foo">bar</a>'),
t('URLs with likely protocols are ignored')
'URLs with likely protocols are ignored'
);
// Test hook_pathologic_alter() implementation.
$this->assertSame(
......@@ -246,12 +247,12 @@ class PathologicTest extends KernelTestBase {
],
]) . '">',
$this->runFilter('<a href="foo?test=add_foo_qpart">'),
t('hook_pathologic_alter(): Alter $url_params')
'hook_pathologic_alter(): Alter $url_params'
);
$this->assertSame(
'<a href="bar?test=use_original">',
$this->runFilter('<a href="bar?test=use_original">'),
t('hook_pathologic_alter(): Passthrough with use_original option')
'hook_pathologic_alter(): Passthrough with use_original option'
);
$this->assertSame(
'<a href="http://cdn.example.com/bar?test=external">',
......@@ -280,7 +281,7 @@ class PathologicTest extends KernelTestBase {
$this->assertSame(
'<img src="' . _pathologic_url_to_protocol_relative($this->pathologicContentUrl('foo.jpeg', ['absolute' => TRUE])) . '" />',
$this->runFilter('<img src="http://example.com/foo.jpeg" />'),
t('Use global settings when so configured on the format')
'Use global settings when so configured on the format'
);
// Test really broken URLs.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment