protectedfunctionassertIndexCounts(int $remaining, int $total, string $message): void { // Check status via plugin method call.
$status = $this->plugin->indexStatus(); $this->assertEquals($remaining, $status['remaining'], 'Remaining items ' . $message . ' is ' . $remaining); $this->assertEquals($total, $status['total'], 'Total items ' . $message . ' is ' . $total);
// Check text in progress section of Search settings page. Note that this
// test avoids using
// \Drupal\Core\StringTranslation\TranslationInterface::formatPlural(), so
// it tests for fragments of text.
$indexed = $total - $remaining; $percent = ($total > 0) ? floor(100 * $indexed / $total) : 100; $this->drupalGet('admin/config/search/pages'); $this->assertSession()->pageTextContains($percent . '% of the site has been 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' => 'not-a-word-english'], 'Search'); $this->assertSearchResultsCount(1);