You are here

public function SearchLanguageTest::testLanguageAttributes in Drupal 9

Same name and namespace in other branches
  1. 10 core/modules/search/tests/src/Functional/SearchLanguageTest.php \Drupal\Tests\search\Functional\SearchLanguageTest::testLanguageAttributes()

Test language attribute "lang" for the search results.

File

core/modules/search/tests/src/Functional/SearchLanguageTest.php, line 160

Class

SearchLanguageTest
Tests advanced search with different languages added.

Namespace

Drupal\Tests\search\Functional

Code

public function testLanguageAttributes() {
  $this
    ->drupalGet('search/node');
  $this
    ->submitForm([
    'keys' => 'the Spanish title',
  ], 'Search');
  $node = $this->searchableNodes[1]
    ->getTranslation('es');
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "es")]');
  $this
    ->assertSession()
    ->elementTextEquals('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "es")]/a', $node
    ->getTitle());
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[@class="layout-content"]//ol/li/p[contains(@lang, "es")]');

  // Visit the search form in Spanish language.
  $this
    ->drupalGet('es/search/node');
  $this
    ->submitForm([
    'keys' => 'First node',
  ], 'Search');
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "en")]');
  $node = $this->searchableNodes[0]
    ->getTranslation('en');
  $this
    ->assertSession()
    ->elementTextEquals('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "en")]/a', $node
    ->getTitle());
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[@class="layout-content"]//ol/li/p[contains(@lang, "en")]');
}