// Try to use an invalid domain.
$edit =
[ 'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
'domain[en]' =>
$base_url_host,
'domain[it]' => 'it.example.com/',
];
$this->
drupalGet('admin/config/regional/language/detection/url'
);
$this->
submitForm($edit, 'Save configuration'
);
$this->
assertSession()->
statusMessageContains("The domain for Italian may only contain the domain name, not a trailing slash, protocol and/or port.", 'error'
);
// Build the link we're going to test.
$link = 'it.example.com' .
rtrim(base_path(), '/'
) . '/admin';
// Test URL in another language: http://it.example.com/admin.
// Base path gives problems on the testbot, so $correct_link is hard-coded.
// @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test).
$italian_url = Url::
fromRoute('system.admin',
[],
['language' =>
$languages['it'
]])->
toString();
$url_scheme = \Drupal::
request()->
isSecure() ? 'https://' : 'http://';
$correct_link =
$url_scheme .
$link;
$this->
assertEquals($correct_link,
$italian_url,
new FormattableMarkup('The right URL (@url) in accordance with the chosen language',
['@url' =>
$italian_url]));
// Test HTTPS via options.
$italian_url = Url::
fromRoute('system.admin',
[],
['https' => TRUE, 'language' =>
$languages['it'
]])->
toString();