You are here

public function ContentEntityDatasourceTest::testItemDiscovery in Search API 8

Verifies that paged item discovery works correctly.

@covers ::getPartialItemIds

File

tests/src/Kernel/Datasource/ContentEntityDatasourceTest.php, line 232

Class

ContentEntityDatasourceTest
Tests correct functionality of the content entity datasource.

Namespace

Drupal\Tests\search_api\Kernel\Datasource

Code

public function testItemDiscovery() {

  // Set page size to 1 to also test paging.
  \Drupal::configFactory()
    ->getEditable('search_api.settings')
    ->set('tracking_page_size', 1)
    ->save();

  // Test item discovery with various bundle/language combinations.
  $discovered_ids = $this
    ->getItemIds();
  $this
    ->assertEquals($this->allItemIds, $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([
    'item',
  ]);
  $this
    ->assertEquals([
    '1:l0',
    '1:l1',
  ], $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([
    'item',
  ], []);
  $this
    ->assertEquals([
    '1:l0',
    '1:l1',
  ], $discovered_ids);
  $discovered_ids = $this
    ->getItemIds(NULL, [
    'l0',
  ]);
  $this
    ->assertEquals([
    '1:l0',
    '2:l0',
  ], $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([], [
    'l0',
  ]);
  $this
    ->assertEquals([
    '1:l0',
    '2:l0',
  ], $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([
    'item',
  ], [
    'l0',
  ]);
  $this
    ->assertEquals([
    '1:l0',
    '1:l1',
    '2:l0',
  ], $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([
    'item',
    'article',
  ], [
    'l0',
  ]);
  $this
    ->assertEquals($this->allItemIds, $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([
    'item',
  ], [
    'l0',
    'l1',
  ]);
  $this
    ->assertEquals($this->allItemIds, $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([
    'item',
    'article',
  ], []);
  $this
    ->assertEquals($this->allItemIds, $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([], [
    'l0',
    'l1',
  ]);
  $this
    ->assertEquals($this->allItemIds, $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([], []);
  $this
    ->assertEquals([], $discovered_ids);
  $discovered_ids = $this
    ->getItemIds([], NULL);
  $this
    ->assertEquals([], $discovered_ids);
  $discovered_ids = $this
    ->getItemIds(NULL, []);
  $this
    ->assertEquals([], $discovered_ids);
}