Browse Source

Issue #3223186: Add a test for external URL

merge-requests/34/head
Chi 12 months ago
parent
commit
ce34d528ae
  1. 2
      src/TwigTweakExtension.php
  2. 5
      tests/src/Functional/TwigTweakTest.php
  3. 1
      tests/twig_tweak_test/templates/twig-tweak-test.html.twig

2
src/TwigTweakExtension.php

@ -333,7 +333,7 @@ class TwigTweakExtension extends AbstractExtension {
} }
/** /**
* Generates a URL from an internal path. * Generates a URL from an internal or external path.
* *
* @param string $user_input * @param string $user_input
* User input for a link or path. * User input for a link or path.

5
tests/src/Functional/TwigTweakTest.php

@ -265,6 +265,11 @@ final class TwigTweakTest extends BrowserTestBase {
$xpath = sprintf('//div[@class = "tt-url"]/div[@data-case="with-langcode" and text() = "%s"]', $url); $xpath = sprintf('//div[@class = "tt-url"]/div[@data-case="with-langcode" and text() = "%s"]', $url);
$this->assertXpath($xpath); $this->assertXpath($xpath);
// -- External URL.
$url = 'https://example.com/node?foo=bar&page=1#here';
$xpath = sprintf('//div[@class = "tt-url"]/div[@data-case="external" and text() = "%s"]', $url);
$this->assertXpath($xpath);
// -- Link. // -- Link.
$url = Url::fromUserInput('/node/1/edit', ['absolute' => TRUE]); $url = Url::fromUserInput('/node/1/edit', ['absolute' => TRUE]);
$link = Link::fromTextAndUrl('Edit', $url)->toString(); $link = Link::fromTextAndUrl('Edit', $url)->toString();

1
tests/twig_tweak_test/templates/twig-tweak-test.html.twig

@ -54,6 +54,7 @@
<div class="tt-url"> <div class="tt-url">
<div data-case="default">{{ drupal_url('node/1', {absolute: true}) }}</div> <div data-case="default">{{ drupal_url('node/1', {absolute: true}) }}</div>
<div data-case="with-langcode">{{ drupal_url('node/1', {absolute: true, langcode: 'ru'}) }}</div> <div data-case="with-langcode">{{ drupal_url('node/1', {absolute: true, langcode: 'ru'}) }}</div>
<div data-case="external">{{ drupal_url('https://example.com/node?foo=bar', {query: {page: 1}, fragment: 'here'}) }}</div>
</div> </div>
<div class="tt-link">{{ drupal_link('Edit', 'node/1/edit', {absolute: true}) }}</div> <div class="tt-link">{{ drupal_link('Edit', 'node/1/edit', {absolute: true}) }}</div>
<div class="tt-link-html">{% set link_text %}<b>Edit</b>{% endset %}{{ drupal_link(link_text, 'node/1/edit', {absolute: true}) }}</div> <div class="tt-link-html">{% set link_text %}<b>Edit</b>{% endset %}{{ drupal_link(link_text, 'node/1/edit', {absolute: true}) }}</div>

Loading…
Cancel
Save