indexStatus example

$status = $this->t('Default');
    }
    elseif ($entity->status()) {
      $status = $this->t('Enabled');
    }
    else {
      $status = $this->t('Disabled');
    }
    $row['status']['#markup'] = $status;

    if ($entity->isIndexable()) {
      $status = $entity->getPlugin()->indexStatus();
      $row['progress']['#markup'] = $this->t('%num_indexed of %num_total indexed', [
        '%num_indexed' => $status['total'] - $status['remaining'],
        '%num_total' => $status['total'],
      ]);
    }
    else {
      $row['progress']['#markup'] = $this->t('Does not use index');
    }

    return $row + parent::buildRow($entity);
  }

  

  protected function assertIndexCounts(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.');
    
    $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);
    
Home | Imprint | This part of the site doesn't use cookies.