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. 10 core/modules/help/tests/src/Functional/HelpTopicSearchTest.php \Drupal\Tests\help\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_topics/tests/src/Functional/HelpTopicSearchTest.php, line 34

Class

HelpTopicSearchTest
Verifies help topic search.

Namespace

Drupal\Tests\help_topics\Functional

Code

protected function setUp() {
    parent::setUp();
    // Log in.
    $this->drupalLogin($this->createUser([
        'access administration 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->drupalPostForm('admin/config/regional/language/add', [
        'predefined_langcode' => 'en',
    ], 'Add language');
    $this->drupalPostForm('admin/config/regional/language', [
        '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.
    $this->drupalPostForm('search/help', [
        'keys' => 'notawordenglish',
    ], 'Search');
    $this->assertSearchResultsCount(0);
    // 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');
}

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