function HelpTopicSearchTest::setUp

Same name in other branches
  1. 9 core/modules/help_topics/tests/src/Functional/HelpTopicSearchTest.php \Drupal\Tests\help_topics\Functional\HelpTopicSearchTest::setUp()
  2. 8.9.x core/modules/help_topics/tests/src/Functional/HelpTopicSearchTest.php \Drupal\Tests\help_topics\Functional\HelpTopicSearchTest::setUp()
  3. 11.x core/modules/help/tests/src/Functional/HelpTopicSearchTest.php \Drupal\Tests\help\Functional\HelpTopicSearchTest::setUp()

Overrides HelpTopicTranslatedTestBase::setUp

File

core/modules/help/tests/src/Functional/HelpTopicSearchTest.php, line 40

Class

HelpTopicSearchTest
Verifies help topic search.

Namespace

Drupal\Tests\help\Functional

Code

protected function setUp() : void {
    parent::setUp();
    // Log in.
    $this->drupalLogin($this->createUser([
        'access help pages',
        'administer site configuration',
        'view the administration theme',
        'administer permissions',
        'administer languages',
        'administer search',
        'access test help',
        'search content',
    ]));
    // Add English language and set to default.
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm([
        'predefined_langcode' => 'en',
    ], 'Add language');
    $this->drupalGet('admin/config/regional/language');
    $this->submitForm([
        'site_default_language' => 'en',
    ], 'Save configuration');
    // When default language is changed, the container is rebuilt in the child
    // site, so a rebuild in the main site is required to use the new container
    // here.
    $this->rebuildContainer();
    // Before running cron, verify that a search returns no results and shows
    // warning.
    $this->drupalGet('search/help');
    $this->submitForm([
        'keys' => 'not-a-word-english',
    ], 'Search');
    $this->assertSearchResultsCount(0);
    $this->assertSession()
        ->statusMessageContains('Help search is not fully indexed', 'warning');
    // Run cron until the topics are fully indexed, with a limit of 100 runs
    // to avoid infinite loops.
    $num_runs = 100;
    $plugin = HelpSearch::create($this->container, [], 'help_search', []);
    do {
        $this->cronRun();
        $remaining = $plugin->indexStatus()['remaining'];
    } while (--$num_runs && $remaining);
    $this->assertNotEmpty($num_runs);
    $this->assertEmpty($remaining);
    // Visit the Search settings page and verify it says 100% indexed.
    $this->drupalGet('admin/config/search/pages');
    $this->assertSession()
        ->pageTextContains('100% of the site has been indexed');
    // Search and verify there is no warning.
    $this->drupalGet('search/help');
    $this->submitForm([
        'keys' => 'not-a-word-english',
    ], 'Search');
    $this->assertSearchResultsCount(1);
    $this->assertSession()
        ->statusMessageNotContains('Help search is not fully indexed');
}

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