Skip to content
Snippets Groups Projects

Bug #2418369: Internal URL handling (language prefixes, base://, ...) (patch...

Open Bug #2418369: Internal URL handling (language prefixes, base://, ...) (patch...
4 unresolved threads
4 unresolved threads
Files
2
@@ -9,6 +9,7 @@ use Drupal\Tests\BrowserTestBase;
@@ -9,6 +9,7 @@ use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\pathologic\Traits\PathologicFormatTrait;
use Drupal\Tests\pathologic\Traits\PathologicFormatTrait;
 
use Drupal\Tests\Traits\Core\PathAliasTestTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
/**
@@ -20,6 +21,7 @@ class PathologicLanguageTest extends BrowserTestBase {
@@ -20,6 +21,7 @@ class PathologicLanguageTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use ContentTypeCreationTrait;
use NodeCreationTrait;
use NodeCreationTrait;
 
use PathAliasTestTrait;
use PathologicFormatTrait;
use PathologicFormatTrait;
use UserCreationTrait;
use UserCreationTrait;
@@ -32,6 +34,8 @@ class PathologicLanguageTest extends BrowserTestBase {
@@ -32,6 +34,8 @@ class PathologicLanguageTest extends BrowserTestBase {
'language',
'language',
'locale',
'locale',
'node',
'node',
 
'path',
 
'path_alias',
'pathologic',
'pathologic',
'text',
'text',
'user',
'user',
@@ -94,7 +98,7 @@ class PathologicLanguageTest extends BrowserTestBase {
@@ -94,7 +98,7 @@ class PathologicLanguageTest extends BrowserTestBase {
'title' => 'Reference page',
'title' => 'Reference page',
]);
]);
// Add translations for the reference node, and try a whole
// Add translations and path aliases for the reference node, and try a whole
// series of possible input texts to see how they are handled.
// series of possible input texts to see how they are handled.
$node_to_reference->addTranslation('fr', [
$node_to_reference->addTranslation('fr', [
'title' => 'Page de référence en français',
'title' => 'Page de référence en français',
@@ -103,6 +107,10 @@ class PathologicLanguageTest extends BrowserTestBase {
@@ -103,6 +107,10 @@ class PathologicLanguageTest extends BrowserTestBase {
'title' => 'Página de referência em Português',
'title' => 'Página de referência em Português',
])->save();
])->save();
 
$this->createPathAlias('/node/' . $node_to_reference->id(), '/reference-en', 'en');
 
$this->createPathAlias('/node/' . $node_to_reference->id(), '/reference-fr', 'fr');
 
$this->createPathAlias('/node/' . $node_to_reference->id(), '/referencia-pt', 'pt-br');
 
global $base_path;
global $base_path;
$nid = $node_to_reference->id();
$nid = $node_to_reference->id();
@@ -115,19 +123,19 @@ class PathologicLanguageTest extends BrowserTestBase {
@@ -115,19 +123,19 @@ class PathologicLanguageTest extends BrowserTestBase {
"$langcode: file links do not get a language prefix",
"$langcode: file links do not get a language prefix",
);
);
$this->assertSame(
$this->assertSame(
    • Comment on lines 116 to 117
      Suggested change
      124 );
      125 $this->assertSame(
      124 );
      125 $this->assertSame(
      126 '<a href="' . $base_path . 'sites/default/files/styles/thumbnail/public/test.png">Test file link</a>',
      127 $this->runFilter('<a href="/sites/default/files/styles/thumbnail/public/test.png">Test file link</a>', $langcode),
      128 "$langcode: image derivative links do not get a language prefix",
      129 );
      130 $this->assertSame(
      131 '<a href="' . $base_path . 's3/aws/test.png">Test file link</a>',
      132 $this->runFilter('<a href="/s3/aws/test.png">Test file link</a>', $langcode),
      133 "$langcode: links to externally-hosted files do not get a language prefix",
      134 );
      135 $this->assertSame(

      These test cases cover file scenarios mentioned in the issue thread.

Please register or sign in to reply
'<a href="' . $base_path . 'node/' . $nid . '">Test node link</a>',
'<a href="' . $base_path . 'reference-en">Test node link</a>',
$this->runFilter('<a href="/node/' . $nid . '">Test node link</a>', $langcode),
$this->runFilter('<a href="/node/' . $nid . '">Test node link</a>', $langcode),
"$langcode: node/N link should be unchanged"
"$langcode: node/N link uses EN alias",
);
);
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'fr/node/' . $nid . '">Test node link</a>',
'<a href="' . $base_path . 'fr/reference-fr">Test node link</a>',
$this->runFilter('<a href="/fr/node/' . $nid . '">Test node link</a>', $langcode),
$this->runFilter('<a href="/fr/node/' . $nid . '">Test node link</a>', $langcode),
"$langcode: fr/node/N link should be unchanged",
"$langcode: fr/node/N link uses the FR alias",
);
);
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'pt-br/node/' . $nid . '">Test node link</a>',
'<a href="' . $base_path . 'pt-br/referencia-pt">Test node link</a>',
$this->runFilter('<a href="/pt-br/node/' . $nid . '">Test node link</a>', $langcode),
$this->runFilter('<a href="/pt-br/node/' . $nid . '">Test node link</a>', $langcode),
"$langcode: pt-br/node/N link should be unchanged",
"$langcode: pt-br/node/N link uses the PT-BR alias",
);
);
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'reference-en">Test node link</a>',
'<a href="' . $base_path . 'reference-en">Test node link</a>',
@@ -161,19 +169,19 @@ class PathologicLanguageTest extends BrowserTestBase {
@@ -161,19 +169,19 @@ class PathologicLanguageTest extends BrowserTestBase {
"$langcode: file links do not get a language prefix",
"$langcode: file links do not get a language prefix",
);
);
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'node/' . $nid . '">Test node link</a>',
'<a href="' . $base_path . 'reference-en">Test node link</a>',
$this->runFilter('<a href="/node/' . $nid . '">Test node link</a>', $langcode),
$this->runFilter('<a href="/node/' . $nid . '">Test node link</a>', $langcode),
"$langcode: node/N link is unchanged"
"$langcode: node/N link uses EN alias",
);
);
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'node/' . $nid . '">Test node link</a>',
'<a href="' . $base_path . 'fr/reference-fr">Test node link</a>',
$this->runFilter('<a href="/fr/node/' . $nid . '">Test node link</a>', $langcode),
$this->runFilter('<a href="/fr/node/' . $nid . '">Test node link</a>', $langcode),
"$langcode: fr/node/N link should have no langcode prefix"
"$langcode: fr/node/N link should use the FR alias with langcode, even if prefix is stripped",
);
);
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'node/' . $nid . '">Test node link</a>',
'<a href="' . $base_path . 'pt-br/referencia-pt">Test node link</a>',
$this->runFilter('<a href="/pt-br/node/' . $nid . '">Test node link</a>', $langcode),
$this->runFilter('<a href="/pt-br/node/' . $nid . '">Test node link</a>', $langcode),
"$langcode: pt-br/node/N link should have no langcode prefix"
"$langcode: pt-br/node/N link should use the PT-BR alias with langcode, even if the prefix is stripped",
);
);
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'reference-en">Test node link</a>',
'<a href="' . $base_path . 'reference-en">Test node link</a>',
@@ -183,12 +191,12 @@ class PathologicLanguageTest extends BrowserTestBase {
@@ -183,12 +191,12 @@ class PathologicLanguageTest extends BrowserTestBase {
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'reference-fr">Test node link</a>',
'<a href="' . $base_path . 'reference-fr">Test node link</a>',
$this->runFilter('<a href="/fr/reference-fr">Test node link</a>', $langcode),
$this->runFilter('<a href="/fr/reference-fr">Test node link</a>', $langcode),
"$langcode: fr/reference-fr link should have no langcode prefix",
"$langcode: fr/reference-fr link (no URL processing) uses the FR alias with langcode removed",
);
);
$this->assertSame(
$this->assertSame(
'<a href="' . $base_path . 'referencia-pt">Test node link</a>',
'<a href="' . $base_path . 'referencia-pt">Test node link</a>',
$this->runFilter('<a href="/pt-br/referencia-pt">Test node link</a>', $langcode),
$this->runFilter('<a href="/pt-br/referencia-pt">Test node link</a>', $langcode),
"$langcode: pt-br/referencia-pt link should have no langcode prefix",
"$langcode: pt-br/referencia-pt link (no URL processing) uses the PT-BR alias with langcode removed",
);
);
}
}
}
}
Loading