You are here

public function TaskTest::testTaskIgnored in Search API 8

Tests ignored task execution.

File

tests/src/Kernel/System/TaskTest.php, line 128

Class

TaskTest
Tests whether the Search API task system works correctly.

Namespace

Drupal\Tests\search_api\Kernel\System

Code

public function testTaskIgnored() {
  $task = $this
    ->addTask('ignore', NULL, $this->index, 'foobar');
  $type = $task
    ->getType();
  $this
    ->assertEquals(1, $this->taskManager
    ->getTasksCount());
  try {
    $this->taskManager
      ->executeAllTasks([
      'type' => [
        $type,
        'unknown',
      ],
      'index_id' => $this->index
        ->id(),
    ]);
    $this
      ->fail('Exception expected');
  } catch (SearchApiException $e) {
    $id = $task
      ->id();
    $this
      ->assertEquals("Could not execute task #{$id} of type '{$type}'. Type seems to be unknown.", $e
      ->getMessage());
  }
  $this
    ->assertEquals(1, $this->taskManager
    ->getTasksCount());
  $this
    ->assertEquals($task
    ->toArray(), $this->taskWorker
    ->getEventLog()[0]);
}