function SearchLanguageTest::testLanguageAttributes

Same name in other branches
  1. 9 core/modules/search/tests/src/Functional/SearchLanguageTest.php \Drupal\Tests\search\Functional\SearchLanguageTest::testLanguageAttributes()
  2. 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 165

Class

SearchLanguageTest
Tests advanced search with different languages added.

Namespace

Drupal\Tests\search\Functional

Code

public function testLanguageAttributes() : void {
    $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")]');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.