protected function TaskTest::addTask in Search API 8
Adds a new pending task.
Parameters
string $type: The type of task, without "search_api_test_tasks." prefix.
\Drupal\search_api\ServerInterface|null $server: (optional) The search server associated with the task, if any.
\Drupal\search_api\IndexInterface|null $index: (optional) The search index associated with the task, if any.
mixed|null $data: (optional) Additional, type-specific data to save with the task.
bool $duplicate: (optional) TRUE if the task is expected to be a duplicate and not created.
Return value
\Drupal\search_api\Task\TaskInterface The task returned by the task manager.
6 calls to TaskTest::addTask()
- TaskTest::testMultipleTasks in tests/
src/ Kernel/ System/ TaskTest.php - Tests that multiple pending tasks are treated correctly.
- TaskTest::testTaskDuplicates in tests/
src/ Kernel/ System/ TaskTest.php - Tests that duplicate tasks won't be created.
- TaskTest::testTaskFail in tests/
src/ Kernel/ System/ TaskTest.php - Tests failed task execution.
- TaskTest::testTaskIgnored in tests/
src/ Kernel/ System/ TaskTest.php - Tests ignored task execution.
- TaskTest::testTaskSuccess in tests/
src/ Kernel/ System/ TaskTest.php - Tests successful task execution.
File
- tests/
src/ Kernel/ System/ TaskTest.php, line 312
Class
- TaskTest
- Tests whether the Search API task system works correctly.
Namespace
Drupal\Tests\search_api\Kernel\SystemCode
protected function addTask($type, ServerInterface $server = NULL, IndexInterface $index = NULL, $data = NULL, bool $duplicate = FALSE) {
$type = "search_api_test_tasks.{$type}";
$count_before = $this->taskManager
->getTasksCount();
$conditions = [
'type' => $type,
'server_id' => $server ? $server
->id() : NULL,
'index_id' => $index ? $index
->id() : NULL,
];
$conditions = array_filter($conditions);
$count_before_conditions = $this->taskManager
->getTasksCount($conditions);
$task = $this->taskManager
->addTask($type, $server, $index, $data);
$delta = $duplicate ? 0 : 1;
$count_after = $this->taskManager
->getTasksCount();
$this
->assertEquals($count_before + $delta, $count_after);
$count_after_conditions = $this->taskManager
->getTasksCount($conditions);
$this
->assertEquals($count_before_conditions + $delta, $count_after_conditions);
return $task;
}