You are here

public function IndexChangesTest::testTrackerChange in Search API 8

Tests correct reaction when the index's tracker changes.

File

tests/src/Kernel/Index/IndexChangesTest.php, line 272

Class

IndexChangesTest
Tests correct reactions to changes for the index.

Namespace

Drupal\Tests\search_api\Kernel\Index

Code

public function testTrackerChange() {
  $this->index
    ->save();

  /** @var \Drupal\search_api\Tracker\TrackerInterface $tracker */
  $tracker = \Drupal::getContainer()
    ->get('search_api.plugin_helper')
    ->createTrackerPlugin($this->index, 'search_api_test');
  $this->index
    ->setTracker($tracker)
    ->save();
  $this->taskManager
    ->executeAllTasks();
  $methods = $this
    ->getCalledMethods('tracker');
  $expected = [
    'trackItemsInserted',
    'trackItemsInserted',
  ];
  $this
    ->assertEquals($expected, $methods);

  /** @var \Drupal\search_api\Tracker\TrackerInterface $tracker */
  $tracker = \Drupal::getContainer()
    ->get('search_api.plugin_helper')
    ->createTrackerPlugin($this->index, 'default');
  $this->index
    ->setTracker($tracker)
    ->save();
  $this->taskManager
    ->executeAllTasks();
  $methods = $this
    ->getCalledMethods('tracker');
  $this
    ->assertEquals([
    'trackAllItemsDeleted',
  ], $methods);
  $arguments = $this
    ->getMethodArguments('tracker', 'trackAllItemsDeleted');
  $this
    ->assertEquals([], $arguments);
}