protected function HelpTopicSearchTest::setUp in Drupal 9
Same name and namespace in other branches
- 8 core/modules/help_topics/tests/src/Functional/HelpTopicSearchTest.php \Drupal\Tests\help_topics\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\FunctionalCode
protected function setUp() : void {
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
->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' => 'notawordenglish',
], 'Search');
$this
->assertSearchResultsCount(0);
$this
->assertSession()
->pageTextContains('is not fully indexed');
// 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' => 'notawordenglish',
], 'Search');
$this
->assertSearchResultsCount(1);
$this
->assertSession()
->pageTextNotContains('is not fully indexed');
}