public function LanguageIntegrationTest::testUrlAliasTranslation in Facets 8
Tests the url alias translation.
See also
https://www.drupal.org/node/2893374
File
- tests/
src/ Functional/ LanguageIntegrationTest.php, line 140
Class
- LanguageIntegrationTest
- Tests the integration with the language module.
Namespace
Drupal\Tests\facets\FunctionalCode
public function testUrlAliasTranslation() {
$facet_id = 'barn_owl';
$facet_name = 'Barn owl';
$this
->createFacet($facet_name, $facet_id);
// Go to the search view with a language prefix and click on one of the
// facets.
$this
->drupalGet('xx-lolspeak/search-api-test-fulltext');
$this
->assertFacetBlocksAppear();
$this
->clickLink('item');
// Check that the language code is still in the url.
$this
->assertTrue((bool) strpos($this
->getUrl(), 'xx-lolspeak/'), 'Found the language code in the url');
$this
->assertTrue((bool) strpos($this
->getUrl(), 'barn_owl'), 'Found the facet in the url');
// Translate the facet.
$this
->drupalGet('admin/config/search/facets/' . $facet_id . '/edit/translate/xx-lolspeak/add');
$this
->drupalPostForm(NULL, [
'translation[config_names][facets.facet.barn_owl][url_alias]' => 'tyto_alba',
], 'Save translation');
$this
->drupalGet('admin/config/search/facets/' . $facet_id . '/edit/translate/nl/add');
$this
->drupalPostForm(NULL, [
'translation[config_names][facets.facet.barn_owl][url_alias]' => 'uil',
], 'Save translation');
$this
->drupalGet('admin/config/search/facets/' . $facet_id . '/edit/translate/es/add');
$this
->drupalPostForm(NULL, [
'translation[config_names][facets.facet.barn_owl][url_alias]' => 'buho',
], 'Save translation');
// Go to the search view again and check that we now have the translated
// facet in the url.
$this
->drupalGet('xx-lolspeak/search-api-test-fulltext');
$this
->assertFacetBlocksAppear();
$this
->clickLink('item');
$this
->assertTrue((bool) strpos($this
->getUrl(), 'xx-lolspeak/'), 'Found the language code in the url');
$this
->assertTrue((bool) strpos($this
->getUrl(), 'tyto_alba'), 'Found the facet in the url');
\Drupal::service('module_installer')
->install([
'locale',
]);
$block = $this
->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
'id' => 'test_language_block',
]);
$this
->drupalGet('xx-lolspeak/search-api-test-fulltext');
$this
->assertSession()
->pageTextContains($block
->label());
$this
->clickLink('item');
/** @var \Behat\Mink\Element\NodeElement[] $links */
$links = $this
->findFacetLink('item');
$this
->assertEquals('is-active', $links[0]
->getParent()
->getAttribute('class'));
$this
->clickLink('English');
/** @var \Behat\Mink\Element\NodeElement[] $links */
$links = $this
->findFacetLink('item');
$this
->assertEquals('is-active', $links[0]
->getParent()
->getAttribute('class'));
$this
->assertFalse((bool) strpos($this
->getUrl(), 'xx-lolspeak/'), 'Found the language code in the url');
$this
->assertFalse((bool) strpos($this
->getUrl(), 'tyto_alba'), 'Found the facet in the url');
$this
->assertTrue((bool) strpos($this
->getUrl(), 'barn_owl'), 'Found the facet in the url');
$this
->clickLink('Lolspeak');
/** @var \Behat\Mink\Element\NodeElement[] $links */
$links = $this
->findFacetLink('item');
$this
->assertEquals('is-active', $links[0]
->getParent()
->getAttribute('class'));
$this
->assertTrue((bool) strpos($this
->getUrl(), 'xx-lolspeak/'), 'Found the language code in the url');
$this
->assertTrue((bool) strpos($this
->getUrl(), 'tyto_alba'), 'Found the facet in the url');
$this
->assertFalse((bool) strpos($this
->getUrl(), 'barn_owl'), 'Found the facet in the url');
$this
->clickLink('Dutch');
/** @var \Behat\Mink\Element\NodeElement[] $links */
$links = $this
->findFacetLink('item');
$this
->assertEquals('is-active', $links[0]
->getParent()
->getAttribute('class'));
$this
->assertTrue((bool) strpos($this
->getUrl(), 'nl/'), 'Found the language code in the url');
$this
->assertTrue((bool) strpos($this
->getUrl(), 'uil'), 'Found the facet in the url');
$this
->clickLink('Spanish');
/** @var \Behat\Mink\Element\NodeElement[] $links */
$links = $this
->findFacetLink('item');
$this
->assertEquals('is-active', $links[0]
->getParent()
->getAttribute('class'));
$this
->assertTrue((bool) strpos($this
->getUrl(), 'es/'), 'Found the language code in the url');
$this
->assertTrue((bool) strpos($this
->getUrl(), 'buho'), 'Found the facet in the url');
$this
->clickLink('English');
/** @var \Behat\Mink\Element\NodeElement[] $links */
$links = $this
->findFacetLink('item');
$this
->assertEquals('is-active', $links[0]
->getParent()
->getAttribute('class'));
$this
->assertTrue((bool) strpos($this
->getUrl(), 'barn_owl'), 'Found the facet in the url');
}