View source
<?php
namespace Drupal\Tests\search_api\Kernel\System;
use Drupal\entity_test\Entity\EntityTestMulRevChanged;
use Drupal\KernelTests\KernelTestBase;
use Drupal\search_api\Entity\Index;
use Drupal\search_api\Entity\Server;
use Drupal\search_api\Utility\Utility;
use Drupal\Tests\search_api\Kernel\PostRequestIndexingTrait;
class CliTest extends KernelTestBase {
use PostRequestIndexingTrait;
protected $server;
public static $modules = [
'search_api',
'search_api_test',
'user',
'system',
'entity_test',
];
public function setUp() {
parent::setUp();
$this
->installSchema('search_api', [
'search_api_item',
]);
$this
->installEntitySchema('entity_test_mulrev_changed');
$this
->installEntitySchema('search_api_task');
$this
->installConfig('search_api');
$this->server = Server::create([
'name' => 'Test server',
'id' => 'test',
'status' => 1,
'backend' => 'search_api_test',
]);
$this->server
->save();
if (!Utility::isRunningInCli()) {
\Drupal::state()
->set('search_api_use_tracking_batch', FALSE);
}
}
public function testItemTracking() {
EntityTestMulRevChanged::create([
'name' => 'foo bar baz föö smile' . json_decode('"\\u1F601"'),
'body' => 'test test case Case casE',
'type' => 'entity_test_mulrev_changed',
'keywords' => [
'Orange',
'orange',
'örange',
'Orange',
],
'category' => 'item_category',
])
->save();
EntityTestMulRevChanged::create([
'name' => 'foo bar baz föö smile',
'body' => 'test test case Case casE',
'type' => 'entity_test_mulrev_changed',
'keywords' => [
'strawberry',
'llama',
],
'category' => 'item_category',
])
->save();
$index = Index::create([
'name' => 'Test index',
'id' => 'index',
'status' => 1,
'datasource_settings' => [
'entity:entity_test_mulrev_changed' => [],
],
'tracker_settings' => [
'default' => [],
],
'server' => $this->server
->id(),
'options' => [
'index_directly' => TRUE,
],
]);
$index
->save();
$total_items = $index
->getTrackerInstance()
->getTotalItemsCount();
$indexed_items = $index
->getTrackerInstance()
->getIndexedItemsCount();
$this
->assertEquals(2, $total_items, 'The 2 items are tracked.');
$this
->assertEquals(0, $indexed_items, 'No items are indexed');
EntityTestMulRevChanged::create([
'name' => 'foo bar baz föö smile',
'body' => 'test test case Case casE',
'type' => 'entity_test_mulrev_changed',
'keywords' => [
'strawberry',
'llama',
],
'category' => 'item_category',
])
->save();
EntityTestMulRevChanged::create([
'name' => 'foo bar baz föö smile',
'body' => 'test test case Case casE',
'type' => 'entity_test_mulrev_changed',
'keywords' => [
'strawberry',
'llama',
],
'category' => 'item_category',
])
->save();
$total_items = $index
->getTrackerInstance()
->getTotalItemsCount();
$indexed_items = $index
->getTrackerInstance()
->getIndexedItemsCount();
$this
->assertEquals(4, $total_items, 'All 4 items are tracked.');
$this
->assertEquals(0, $indexed_items, 'No items are indexed.');
$this
->triggerPostRequestIndexing();
$total_items = $index
->getTrackerInstance()
->getTotalItemsCount();
$indexed_items = $index
->getTrackerInstance()
->getIndexedItemsCount();
$this
->assertEquals(4, $total_items, 'All 4 items are tracked.');
$this
->assertEquals(2, $indexed_items, '2 items are indexed.');
}
}