You are here

public function LanguageIntegrationTest::testUrlAliasTranslation in Search API Pages 8

Tests the url alias translation.

See also

https://www.drupal.org/node/2893374

File

tests/src/Functional/LanguageIntegrationTest.php, line 94

Class

LanguageIntegrationTest
Provides web tests for Search API Pages with language integration.

Namespace

Drupal\Tests\search_api_page\Functional

Code

public function testUrlAliasTranslation() {
  $page = SearchApiPage::create([
    'label' => 'Owl Display',
    'id' => 'owl_display',
    'index' => $this->index
      ->id(),
    'path' => 'bird_owl',
    'show_all_when_no_keys' => TRUE,
  ]);
  $page
    ->save();
  \Drupal::service('module_installer')
    ->install([
    'locale',
  ]);
  $block = $this
    ->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
    'id' => 'test_language_block',
  ]);
  $this
    ->drupalGet('bird_owl');
  $this
    ->assertSession()
    ->pageTextContains($block
    ->label());
  $this
    ->assertSession()
    ->pageTextContains('50 results found');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->clickLink('Spanish');
  $this
    ->assertSession()
    ->pageTextContains($block
    ->label());
  $this
    ->assertTrue((bool) strpos($this
    ->getUrl(), '/es/'), 'Found the language code in the url');
  $this
    ->assertSession()
    ->pageTextContains('1 result found');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->clickLink('Dutch');
  $this
    ->assertSession()
    ->pageTextContains($block
    ->label());
  $this
    ->assertTrue((bool) strpos($this
    ->getUrl(), '/nl/'), 'Found the language code in the url');
  $this
    ->assertSession()
    ->pageTextContains('1 result found');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->clickLink('English');
  $this
    ->assertSession()
    ->pageTextContains($block
    ->label());
  $this
    ->assertSession()
    ->pageTextContains('50 results found');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Test that keys are properly preserved when switching languages.
  $this
    ->drupalGet('/search');
  $this
    ->drupalPostForm(NULL, [
    'keys' => 'bird',
  ], 'Search');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('1 result found');
  $this
    ->assertSession()
    ->pageTextContains('Hawk');
  $this
    ->clickLink('Spanish');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('1 result found');
  $this
    ->assertSession()
    ->pageTextContains('Halcon');
  $this
    ->clickLink('Dutch');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('1 result found');
  $this
    ->assertSession()
    ->pageTextContains('Havik');
  $this
    ->clickLink('English');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('1 result found');
  $this
    ->assertSession()
    ->pageTextContains('Hawk');
}