public function IndexLoadItemsTest::testMissingItems in Search API 8
Verifies that missing items are correctly detected and removed.
File
- tests/
src/ Kernel/ Index/ IndexLoadItemsTest.php, line 61
Class
- IndexLoadItemsTest
- Tests whether loading items works correctly.
Namespace
Drupal\Tests\search_api\Kernel\IndexCode
public function testMissingItems() {
$item_ids = [
'search_api_test/1',
'search_api_test/2',
];
$items = $this->index
->loadItemsMultiple($item_ids);
$this
->assertEquals([], $items, 'No items loaded from test datasource.');
$methods = $this
->getCalledMethods('tracker');
$this
->assertContains('trackItemsDeleted', $methods, 'Unknown items deleted from tracker.');
$args = $this
->getMethodArguments('tracker', 'trackItemsDeleted');
$this
->assertEquals([
$item_ids,
], $args, 'Correct items deleted from tracker.');
$methods = $this
->getCalledMethods('backend');
$this
->assertContains('deleteItems', $methods, 'Unknown items deleted from server.');
// If an error occurs while retrieving the datasource (which will happen for
// "unknown/1"), the items should not be deleted from tracking and the
// server.
$expected_deletions = $item_ids;
$item_ids = [
'search_api_test/1',
'search_api_test/2',
'search_api_test/3',
'unknown/1',
];
$this
->setReturnValue('datasource', 'loadMultiple', [
'3' => '',
]);
$items = $this->index
->loadItemsMultiple($item_ids);
$expected_items = [
'search_api_test/3' => '',
];
$this
->assertEquals($expected_items, $items, 'Expected items loaded from test datasource.');
$methods = $this
->getCalledMethods('tracker');
$this
->assertContains('trackItemsDeleted', $methods, 'Unknown items deleted from tracker.');
$args = $this
->getMethodArguments('tracker', 'trackItemsDeleted');
$this
->assertEquals([
$expected_deletions,
], $args, 'Correct items deleted from tracker.');
$methods = $this
->getCalledMethods('backend');
$this
->assertContains('deleteItems', $methods, 'Unknown items deleted from server.');
}