public function CliTest::testItemTracking in Search API 8
Tests tracking of items when saving an index through the CLI.
File
- tests/
src/ Kernel/ System/ CliTest.php, line 71
Class
- CliTest
- Tests Search API functionality when executed in the CLI.
Namespace
Drupal\Tests\search_api\Kernel\SystemCode
public function testItemTracking() {
EntityTestMulRevChanged::create([
'name' => 'foo bar baz föö smile' . json_decode('"\\u1F601"'),
'body' => 'test test case Case casE',
'type' => 'entity_test_mulrev_changed',
'keywords' => [
'Orange',
'orange',
'örange',
'Orange',
],
'category' => 'item_category',
])
->save();
EntityTestMulRevChanged::create([
'name' => 'foo bar baz föö smile',
'body' => 'test test case Case casE',
'type' => 'entity_test_mulrev_changed',
'keywords' => [
'strawberry',
'llama',
],
'category' => 'item_category',
])
->save();
// Create a test index.
/** @var \Drupal\search_api\IndexInterface $index */
$index = Index::create([
'name' => 'Test index',
'id' => 'index',
'status' => 1,
'datasource_settings' => [
'entity:entity_test_mulrev_changed' => [],
],
'tracker_settings' => [
'default' => [],
],
'server' => $this->server
->id(),
'options' => [
'index_directly' => TRUE,
],
]);
$index
->save();
$total_items = $index
->getTrackerInstance()
->getTotalItemsCount();
$indexed_items = $index
->getTrackerInstance()
->getIndexedItemsCount();
$this
->assertEquals(2, $total_items, 'The 2 items are tracked.');
$this
->assertEquals(0, $indexed_items, 'No items are indexed');
EntityTestMulRevChanged::create([
'name' => 'foo bar baz föö smile',
'body' => 'test test case Case casE',
'type' => 'entity_test_mulrev_changed',
'keywords' => [
'strawberry',
'llama',
],
'category' => 'item_category',
])
->save();
EntityTestMulRevChanged::create([
'name' => 'foo bar baz föö smile',
'body' => 'test test case Case casE',
'type' => 'entity_test_mulrev_changed',
'keywords' => [
'strawberry',
'llama',
],
'category' => 'item_category',
])
->save();
$total_items = $index
->getTrackerInstance()
->getTotalItemsCount();
$indexed_items = $index
->getTrackerInstance()
->getIndexedItemsCount();
$this
->assertEquals(4, $total_items, 'All 4 items are tracked.');
$this
->assertEquals(0, $indexed_items, 'No items are indexed.');
$this
->triggerPostRequestIndexing();
$total_items = $index
->getTrackerInstance()
->getTotalItemsCount();
$indexed_items = $index
->getTrackerInstance()
->getIndexedItemsCount();
$this
->assertEquals(4, $total_items, 'All 4 items are tracked.');
$this
->assertEquals(2, $indexed_items, '2 items are indexed.');
}