View source
<?php
namespace Drupal\Tests\search_api\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;
use Drupal\search_api\Entity\Index;
use Drupal\search_api\Entity\Server;
use Drupal\search_api\IndexInterface;
use Drupal\search_api\Plugin\search_api\tracker\Basic;
use Drupal\search_api\SearchApiException;
use Drupal\search_api\Utility\Utility;
use Drupal\search_api_test\Plugin\search_api\tracker\TestTracker;
use Drupal\search_api_test\PluginTestTrait;
use Drupal\Tests\search_api\Kernel\PostRequestIndexingTrait;
class IntegrationTest extends SearchApiBrowserTestBase {
use PluginTestTrait;
use PostRequestIndexingTrait;
protected $adminUser2;
protected $serverBackend = 'search_api_test';
protected $serverId;
protected $indexStorage;
public static $modules = [
'node',
'search_api',
'search_api_test',
'search_api_test_no_ui',
'field_ui',
'link',
'image',
];
public function setUp() {
parent::setUp();
$this->indexStorage = \Drupal::entityTypeManager()
->getStorage('search_api_index');
$permissions = [
'administer search_api',
'access administration pages',
'administer nodes',
'bypass node access',
'administer content types',
'administer node fields',
];
$this->adminUser = $this
->drupalCreateUser($permissions);
$this->adminUser2 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->adminUser);
}
public function testFramework() {
$this
->createServer();
$this
->createServerDuplicate();
$this
->checkServerAvailability();
$this
->createIndex();
$this
->createIndexDuplicate();
$this
->editServer();
$this
->editIndex();
$this
->checkUserIndexCreation();
$this
->checkContentEntityTracking();
$this
->enableAllProcessors();
$this
->checkFieldLabels();
$this
->addFieldsToIndex();
$this
->checkDataTypesTable();
$this
->removeFieldsFromIndex();
$this
->checkReferenceFieldsNonBaseFields();
$this
->configureFilter();
$this
->configureFilterPage();
$this
->checkProcessorChanges();
$this
->changeProcessorFieldBoost();
$this
->setReadOnly();
$this
->disableEnableIndex();
$this
->changeIndexDatasource();
$this
->changeIndexServer();
$this
->checkIndexing();
$this
->checkIndexActions();
$this
->deleteServer();
}
public function testIntegerIndex() {
Server::create([
'id' => 456,
'name' => 789,
'description' => 'WebTest server description',
'backend' => $this->serverBackend,
'backend_config' => [],
])
->save();
$this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalGet('admin/config/search/search-api/add-index');
$this->indexId = 123;
$edit = [
'name' => $this->indexId,
'id' => $this->indexId,
'status' => 1,
'description' => 'test Index:: 123~',
'server' => 456,
'datasources[entity:node]' => TRUE,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Please configure the used datasources.');
$this
->submitForm([], 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this
->assertEquals(2, $this
->countTrackedItems());
$this
->enableAllProcessors();
$this
->checkFieldLabels();
$this
->addFieldsToIndex();
$this
->addFieldsWithDependenciesToIndex();
$this
->removeFieldsDependencies();
$this
->removeFieldsFromIndex();
$this
->checkUnsavedChanges();
$this
->configureFilter();
$this
->configureFilterPage();
$this
->checkProcessorChanges();
$this
->changeProcessorFieldBoost();
$this
->setReadOnly();
$this
->disableEnableIndex();
$this
->changeIndexDatasource();
$this
->changeIndexServer();
$this
->checkIndexing();
$this
->checkIndexActions();
}
protected function createServer($server_id = '_test_server') {
$this->serverId = $server_id;
$server_name = 'Search API &{}<>! Server';
$server_description = 'A >server< used for testing &.';
$settings_path = 'admin/config/search/search-api/add-server';
$this
->drupalGet($settings_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains('No UI backend');
$edit = [
'name' => '',
'status' => 1,
'description' => 'A server used for testing.',
'backend' => $this->serverBackend,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains(new FormattableMarkup('@name field is required.', [
'@name' => 'Server name',
]));
$edit = [
'name' => $server_name,
'status' => 1,
'description' => $server_description,
'backend' => $this->serverBackend,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains(new FormattableMarkup('@name field is required.', [
'@name' => 'Machine-readable name',
]));
$edit += [
'id' => $this->serverId,
];
$this
->configureBackendAndSave($edit);
$this
->assertSession()
->pageTextContains('The server was successfully saved.');
$this
->assertSession()
->addressEquals('admin/config/search/search-api/server/' . $this->serverId);
$this
->assertHtmlEscaped($server_name);
$this
->assertHtmlEscaped($server_description);
$this
->drupalGet('admin/config/search/search-api');
$this
->assertHtmlEscaped($server_name);
$this
->assertHtmlEscaped($server_description);
}
protected function configureBackendAndSave(array $edit) {
$this
->submitForm($edit, 'Save');
}
protected function createServerDuplicate() {
$server_add_page = 'admin/config/search/search-api/add-server';
$this
->drupalGet($server_add_page);
$edit = [
'name' => $this->serverId,
'id' => $this->serverId,
'backend' => $this->serverBackend,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
}
protected function createIndex() {
$settings_path = 'admin/config/search/search-api/add-index';
$this->indexId = 'test_index';
$index_description = 'An >index< used for &! tęsting.';
$index_name = 'Search >API< test &!^* index';
$index_datasource = 'entity:node';
$this
->drupalGet($settings_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains('No UI datasource');
$this
->assertSession()
->pageTextNotContains('No UI tracker');
$this
->assertHtmlEscaped('"Test" tracker');
$this
->assertHtmlEscaped('"String label" test tracker');
$this
->assertHtmlEscaped('"Test" datasource');
$dummy_index = Index::create();
foreach ([
'createDatasourcePlugins',
'createTrackerPlugins',
] as $method) {
$plugins = \Drupal::getContainer()
->get('search_api.plugin_helper')
->{$method}($dummy_index);
foreach ($plugins as $plugin) {
if ($plugin
->isHidden()) {
continue;
}
$description = Utility::escapeHtml($plugin
->getDescription());
$this
->assertSession()
->responseContains($description);
}
}
$edit = [
'status' => 1,
'description' => $index_description,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Index name field is required.');
$this
->assertSession()
->pageTextContains('Machine-readable name field is required.');
$this
->assertSession()
->pageTextContains('Datasources field is required.');
$edit = [
'name' => $index_name,
'id' => $this->indexId,
'status' => 1,
'description' => $index_description,
'server' => $this->serverId,
'datasources[' . $index_datasource . ']' => TRUE,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Please configure the used datasources.');
$this
->submitForm([], 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this
->assertSession()
->addressEquals($this
->getIndexPath());
$this
->assertHtmlEscaped($index_name);
$this
->drupalGet($this
->getIndexPath('edit'));
$this
->assertHtmlEscaped($index_name);
$index = $this
->getIndex(TRUE);
$this
->assertInstanceOf(IndexInterface::class, $index, 'Index was correctly created.');
$this
->assertEquals($edit['name'], $index
->label(), 'Name correctly inserted.');
$this
->assertEquals($edit['id'], $index
->id(), 'Index ID correctly inserted.');
$this
->assertTrue($index
->status(), 'Index status correctly inserted.');
$this
->assertEquals($edit['description'], $index
->getDescription(), 'Index ID correctly inserted.');
$this
->assertEquals($edit['server'], $index
->getServerId(), 'Index server ID correctly inserted.');
$this
->assertEquals($index_datasource, $index
->getDatasourceIds()[0], 'Index datasource id correctly inserted.');
$index2_id = 'test_index2';
$edit['id'] = $index2_id;
unset($edit['server']);
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save and add fields');
$this
->assertSession()
->pageTextContains('Please configure the used datasources.');
$this
->submitForm([], 'Save and add fields');
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this->indexStorage
->resetCache([
$index2_id,
]);
$index = $this->indexStorage
->load($index2_id);
$this
->assertSession()
->addressEquals($index
->toUrl('add-fields'));
$this
->drupalGet('admin/config/search/search-api');
$this
->assertHtmlEscaped($index_name);
$this
->assertHtmlEscaped($index_description);
}
protected function createIndexDuplicate() {
$index_add_page = 'admin/config/search/search-api/add-index';
$this
->drupalGet($index_add_page);
$edit = [
'name' => $this->indexId,
'id' => $this->indexId,
'server' => $this->serverId,
'datasources[entity:node]' => TRUE,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
$this
->submitForm($edit, 'datasources_configure');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
$this
->submitForm($edit, 'datasources_configure');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
}
protected function editServer() {
$path = 'admin/config/search/search-api/server/' . $this->serverId . '/edit';
$this
->drupalGet($path);
$elements = $this
->xpath('//form[@id="search-api-server-edit-form"]/div[contains(@class, "form-item-id")]/input[@disabled]');
$this
->assertEquals(1, count($elements), 'Machine name cannot be changed.');
$tracked_items_before = $this
->countTrackedItems();
$edit = [
'name' => 'Test server',
];
$this
->submitForm($edit, 'Save');
$index = $this->indexStorage
->load($this->indexId);
$remaining = $index
->getTrackerInstance()
->getRemainingItemsCount();
$this
->assertEquals(0, $remaining, 'Index was not scheduled for re-indexing when saving its server.');
$this
->setReturnValue('backend', 'postUpdate', TRUE);
$this
->drupalGet($path);
$this
->submitForm($edit, 'Save');
$tracked_items = $this
->countTrackedItems();
$remaining = $index
->getTrackerInstance()
->getRemainingItemsCount();
$this
->assertEquals($tracked_items, $remaining, 'Backend could trigger re-indexing upon save.');
$this
->assertEquals($tracked_items_before, $tracked_items, 'Items are still tracked after re-indexing was triggered.');
}
protected function editIndex() {
$tracked_items = $this
->countTrackedItems();
$edit_path = 'admin/config/search/search-api/index/' . $this->indexId . '/edit';
$this
->drupalGet($edit_path);
$elements = $this
->xpath('//form[@id="search-api-index-edit-form"]/div[contains(@class, "form-item-id")]/input[@disabled]');
$this
->assertEquals(1, count($elements), 'Machine name cannot be changed.');
$edit = [
'tracker' => 'search_api_test',
];
$this
->submitForm($edit, 'tracker_configure');
$edit['tracker_config[foo]'] = 'foobar';
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$index = $this
->getIndex(TRUE);
$tracker = $index
->getTrackerInstance();
$this
->assertInstanceOf(TestTracker::class, $tracker, get_class($tracker));
$this
->assertInstanceOf(TestTracker::class, $tracker, 'Tracker was successfully switched.');
$configuration = [
'foo' => 'foobar',
'dependencies' => [],
];
$this
->assertEquals($configuration, $tracker
->getConfiguration(), 'Tracker config was successfully saved.');
$this
->assertEquals($tracked_items, $this
->countTrackedItems(), 'Items are still correctly tracked.');
$this
->drupalGet($edit_path);
$edit = [
'tracker' => 'default',
];
$this
->submitForm($edit, 'tracker_configure');
$edit['tracker_config[indexing_order]'] = 'fifo';
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$index = $this
->getIndex(TRUE);
$tracker = $index
->getTrackerInstance();
$this
->assertInstanceOf(Basic::class, $tracker, 'Tracker was successfully switched.');
}
protected function checkUserIndexCreation() {
$edit = [
'name' => 'IndexName',
'id' => 'user_index',
'datasources[entity:user]' => TRUE,
];
$this
->drupalGet('admin/config/search/search-api/add-index');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Please configure the used datasources.');
$this
->submitForm([], 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this
->assertSession()
->pageTextContains($edit['name']);
}
protected function checkServerAvailability() {
$this
->drupalGet('admin/config/search/search-api/server/' . $this->serverId . '/edit');
$this
->drupalGet('admin/config/search/search-api');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('Enabled');
$this
->setReturnValue('backend', 'isAvailable', FALSE);
$this
->drupalGet('admin/config/search/search-api');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('Unavailable');
$this
->setReturnValue('backend', 'isAvailable', TRUE);
}
protected function checkContentEntityTracking() {
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(0, $tracked_items, 'No items are tracked yet.');
$article1 = $this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalCreateNode([
'type' => 'page',
]);
$page2 = Node::create([
'body' => [
[
'value' => $this
->randomMachineName(32),
'format' => filter_default_format(),
],
],
'title' => $this
->randomMachineName(8),
'type' => 'page',
'uid' => \Drupal::currentUser()
->id(),
]);
$page2->search_api_skip_tracking = TRUE;
$page2
->save();
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(3, $tracked_items, 'Three items are tracked.');
$this
->getCalledMethods('backend');
$page2
->delete();
$methods = $this
->getCalledMethods('backend');
$this
->assertEquals([], $methods, 'Tracking of a delete operation could successfully be prevented.');
$settings_path = $this
->getIndexPath('edit');
$this
->drupalGet($settings_path);
$edit = [
'status' => FALSE,
'datasource_configs[entity:node][bundles][default]' => 0,
'datasource_configs[entity:node][bundles][selected][article]' => FALSE,
'datasource_configs[entity:node][bundles][selected][page]' => FALSE,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(0, $tracked_items, 'No items are tracked.');
$this
->drupalGet($settings_path);
$edit = [
'status' => TRUE,
'datasource_configs[entity:node][bundles][default]' => 0,
'datasource_configs[entity:node][bundles][selected][article]' => TRUE,
'datasource_configs[entity:node][bundles][selected][page]' => TRUE,
];
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(3, $tracked_items, 'Three items are tracked.');
$edit = [
'status' => TRUE,
'datasource_configs[entity:node][bundles][default]' => 0,
'datasource_configs[entity:node][bundles][selected][article]' => FALSE,
'datasource_configs[entity:node][bundles][selected][page]' => FALSE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(0, $tracked_items, 'No items are tracked.');
$edit = [
'status' => TRUE,
'datasource_configs[entity:node][bundles][default]' => 0,
'datasource_configs[entity:node][bundles][selected][article]' => TRUE,
'datasource_configs[entity:node][bundles][selected][page]' => FALSE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(2, $tracked_items, 'Two items are tracked.');
$edit = [
'status' => TRUE,
'datasource_configs[entity:node][bundles][default]' => 0,
'datasource_configs[entity:node][bundles][selected][article]' => FALSE,
'datasource_configs[entity:node][bundles][selected][page]' => TRUE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(1, $tracked_items, 'One item is tracked.');
$edit = [
'status' => TRUE,
'datasource_configs[entity:node][bundles][default]' => 1,
'datasource_configs[entity:node][bundles][selected][article]' => TRUE,
'datasource_configs[entity:node][bundles][selected][page]' => FALSE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(1, $tracked_items, 'One item is tracked.');
$edit = [
'status' => TRUE,
'datasource_configs[entity:node][bundles][default]' => 1,
'datasource_configs[entity:node][bundles][selected][article]' => FALSE,
'datasource_configs[entity:node][bundles][selected][page]' => TRUE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(2, $tracked_items, 'Two items are tracked.');
$this
->triggerPostRequestIndexing();
$this
->getCalledMethods('backend');
$article1
->save();
$methods = $this
->getCalledMethods('backend');
$this
->assertEquals([], $methods, 'No items were indexed right away (before end of page request).');
$this
->triggerPostRequestIndexing();
$methods = $this
->getCalledMethods('backend');
$this
->assertEquals([
'indexItems',
], $methods, 'Update successfully tracked.');
$article1->search_api_skip_tracking = TRUE;
$article1
->save();
$methods = $this
->getCalledMethods('backend');
$this
->assertEquals([], $methods, 'Tracking of entity update successfully prevented.');
unset($article1->search_api_skip_tracking);
$article1
->delete();
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(1, $tracked_items, 'One item is tracked.');
}
protected function countTrackedItems() {
return $this
->getIndex()
->getTrackerInstance()
->getTotalItemsCount();
}
protected function countRemainingItems() {
return $this
->getIndex()
->getTrackerInstance()
->getRemainingItemsCount();
}
protected function countItemsOnServer() {
$key = 'search_api_test.backend.indexed.' . $this->indexId;
return count(\Drupal::state()
->get($key, []));
}
public function enableAllProcessors() {
$this
->drupalGet($this
->getIndexPath('processors'));
$edit = [
'status[content_access]' => 1,
'status[entity_status]' => 1,
'status[highlight]' => 1,
'status[html_filter]' => 1,
'status[ignorecase]' => 1,
'status[ignore_character]' => 1,
'status[stopwords]' => 1,
'status[tokenizer]' => 1,
'status[transliteration]' => 1,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The indexing workflow was successfully edited.');
}
protected function checkFieldLabels() {
$content_type_name = '&%@Content()_=';
$edit = [
'name' => $content_type_name,
'type' => '_content_',
];
$this
->drupalGet('admin/structure/types/add');
$this
->assertSession()
->statusCodeEquals(200);
$this
->submitForm($edit, 'Save and manage fields');
$entity_bundle_info = $this->container
->get('entity_type.bundle.info');
$entity_bundle_info
->clearCachedBundles();
$bundles = $entity_bundle_info
->getBundleInfo('node');
$this
->assertArrayHasKey('_content_', $bundles);
$field_name = '^6%{[*>.<"field';
FieldStorageConfig::create([
'field_name' => 'field__field_',
'type' => 'string',
'entity_type' => 'node',
])
->save();
FieldConfig::create([
'field_name' => 'field__field_',
'entity_type' => 'node',
'bundle' => '_content_',
'label' => $field_name,
])
->save();
$url_options['query']['datasource'] = 'entity:node';
$this
->drupalGet($this
->getIndexPath('fields/add/nojs'), $url_options);
$this
->assertHtmlEscaped($field_name);
$this
->assertSession()
->responseContains('(<code>field__field_</code>)');
$this
->addField('entity:node', 'field__field_', $field_name);
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->assertHtmlEscaped($field_name);
$this
->assertHtmlEscaped('"Test" data type');
$this
->assertSession()
->responseContains('Dummy <em>data type</em> implementation');
$this
->submitForm([], 'Save changes');
$edit = [
'datasource_configs[entity:node][bundles][default]' => 1,
];
$this
->drupalGet($this
->getIndexPath('edit'));
$this
->assertHtmlEscaped($content_type_name);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this
->addField(NULL, 'rendered_item', 'Rendered HTML output');
$this
->assertHtmlEscaped($content_type_name);
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains(' The field configuration was successfully saved.');
$this
->addField(NULL, 'aggregated_field', 'Aggregated field');
$this
->assertHtmlEscaped($field_name);
$this
->submitForm([
'fields[entity:node/field__field_]' => TRUE,
], 'Save');
$this
->assertSession()
->pageTextContains(' The field configuration was successfully saved.');
}
protected function addFieldsToIndex() {
$url_options['query']['datasource'] = '';
$this
->drupalGet($this
->getIndexPath('fields/add/nojs'), $url_options);
$this
->assertSession()
->pageTextNotContains('Node access information');
$fields = [
'nid' => 'ID',
'title' => 'Title',
'body' => 'Body',
'revision_log' => 'Revision log message',
'uid:entity:name' => 'Authored by » User » Name',
];
foreach ($fields as $property_path => $label) {
$this
->addField('entity:node', $property_path, $label);
}
$this
->assertSession()
->pageTextNotContains('No UI data type');
$index = $this
->getIndex(TRUE);
$fields = $index
->getFields();
$this
->assertArrayNotHasKey('nid', $fields, 'Field changes have not been persisted.');
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->submitForm([], 'Save changes');
$this
->assertSession()
->pageTextContains('The changes were successfully saved.');
$index = $this
->getIndex(TRUE);
$fields = $index
->getFields();
$this
->assertArrayHasKey('nid', $fields, 'nid field is indexed.');
$path = $this
->getIndexPath('fields/add/nojs');
$url_options = [
'query' => [
'datasource' => 'entity:node',
],
];
$this
->drupalGet($path, $url_options);
$this
->assertSession()
->responseNotContains('property_path=type');
$this
->assertArrayHasKey('uid', $fields, 'uid field is indexed.');
$this
->assertTrue($fields['uid']
->isIndexedLocked(), 'uid field is locked.');
$this
->assertTrue($fields['uid']
->isTypeLocked(), 'uid field is type-locked.');
$this
->assertEquals('integer', $fields['uid']
->getType(), 'uid field has type integer.');
$this
->assertArrayHasKey('status', $fields, 'status field is indexed.');
$this
->assertTrue($fields['status']
->isIndexedLocked(), 'status field is locked.');
$this
->assertTrue($fields['status']
->isTypeLocked(), 'status field is type-locked.');
$this
->assertEquals('boolean', $fields['status']
->getType(), 'status field has type boolean.');
$this
->assertArrayHasKey('body', $fields, 'body field is indexed.');
$this
->assertEquals('text', $fields['body']
->getType(), 'Complex field mapping relationship works.');
$edit = [
'fields[title][title]' => 'new_title',
'fields[title][id]' => 'new_id',
'fields[title][type]' => 'text',
'fields[title][boost]' => Utility::formatBoostFactor(21),
'fields[revision_log][type]' => 'search_api_test',
];
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->submitForm($edit, 'Save changes');
$this
->assertSession()
->pageTextContains('The changes were successfully saved.');
$index = $this
->getIndex(TRUE);
$fields = $index
->getFields();
$this
->assertArrayHasKey('new_id', $fields, 'title field is indexed.');
$this
->assertEquals($edit['fields[title][title]'], $fields['new_id']
->getLabel(), 'title field title is saved.');
$this
->assertEquals($edit['fields[title][id]'], $fields['new_id']
->getFieldIdentifier(), 'title field id value is saved.');
$this
->assertEquals($edit['fields[title][type]'], $fields['new_id']
->getType(), 'title field type is text.');
$this
->assertEquals($edit['fields[title][boost]'], $fields['new_id']
->getBoost(), 'title field boost value is 21.');
$this
->assertArrayHasKey('revision_log', $fields, 'revision_log field is indexed.');
$this
->assertEquals($edit['fields[revision_log][type]'], $fields['revision_log']
->getType(), 'revision_log field type is search_api_test.');
$edit = [
'fields[new_id][title]' => 'Title',
'fields[new_id][id]' => 'title',
];
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->submitForm($edit, 'Save changes');
$this
->assertSession()
->pageTextContains('The changes were successfully saved.');
$this
->assertSession()
->pageTextContains('uid:entity:name');
$index = $this
->getIndex(TRUE);
$index
->getField('title')
->setBoost(4.0);
$index
->save();
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->submitForm([], 'Save changes');
$this
->assertSession()
->pageTextContains('The changes were successfully saved.');
$index = $this
->getIndex(TRUE);
$this
->assertEquals(4.0, $index
->getField('title')
->getBoost());
}
protected function checkDataTypesTable() {
$this
->drupalGet($this
->getIndexPath('fields'));
$rows = $this
->xpath('//*[@id="search-api-data-types-table"]//table/tbody/tr');
$this
->assertIsArray($rows);
$this
->assertNotEmpty($rows);
foreach ($rows as $row) {
$columns = $row
->findAll('xpath', '/td');
$label = $columns[0]
->getText();
$icon = basename($columns[2]
->find('xpath', '/img')
->getAttribute('src'));
$fallback = $columns[3]
->getText();
if (strpos($label, 'Unsupported') === 0) {
$this
->assertEquals('error.svg', $icon, 'An error icon is shown for unsupported data types.');
$this
->assertNotEquals($fallback, '', 'The fallback data type label is not empty for unsupported data types.');
}
else {
$this
->assertEquals('check.svg', $icon, 'A check icon is shown for supported data types.');
$this
->assertEquals('', $fallback, 'The fallback data type label is empty for supported data types.');
}
}
}
protected function addField($datasource_id, $property_path, $label = NULL) {
$path = $this
->getIndexPath('fields/add/nojs');
$url_options = [
'query' => [
'datasource' => $datasource_id,
],
];
list($parent_path) = Utility::splitPropertyPath($property_path);
if ($parent_path) {
$url_options['query']['property_path'] = $parent_path;
}
if ($this
->getUrl() !== $this
->buildUrl($path, $url_options)) {
$this
->drupalGet($path, $url_options);
}
$combined_property_path = Utility::createCombinedId($datasource_id, $property_path);
$this
->assertSession()
->responseContains('name="' . $combined_property_path . '"');
$this
->submitForm([], $combined_property_path);
if ($label) {
$args['%label'] = $label;
$this
->assertSession()
->responseContains(new FormattableMarkup('Field %label was added to the index.', $args));
}
}
protected function addFieldsWithDependenciesToIndex() {
FieldStorageConfig::create([
'field_name' => 'field_link',
'type' => 'link',
'entity_type' => 'node',
])
->save();
FieldConfig::create([
'field_name' => 'field_link',
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Link',
])
->save();
FieldStorageConfig::create([
'field_name' => 'field_image',
'type' => 'image',
'entity_type' => 'node',
])
->save();
FieldConfig::create([
'field_name' => 'field_image',
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Image',
])
->save();
FieldConfig::create([
'field_name' => 'field_image',
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'Image',
])
->save();
$fields = [
'field_link' => 'Link',
'field_image' => 'Image',
];
foreach ($fields as $property_path => $label) {
$this
->addField('entity:node', $property_path, $label);
}
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->submitForm([], 'Save changes');
$field_dependencies = (array) \Drupal::config('search_api.index.' . $this->indexId)
->get('dependencies.config');
$this
->assertTrue(in_array('field.storage.node.field_link', $field_dependencies), 'The link field has been added as a dependency of the index.');
$this
->assertTrue(in_array('field.storage.node.field_image', $field_dependencies), 'The image field has been added as a dependency of the index.');
}
protected function removeFieldsDependencies() {
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.field_link/delete');
$this
->assertSession()
->pageTextNotContains('The listed configuration will be deleted.');
$this
->assertSession()
->pageTextContains('Search index');
$this
->submitForm([], 'Delete');
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image/delete');
$this
->submitForm([], 'Delete');
$this
->assertNotNull($this
->getIndex(), 'Index was not deleted.');
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains('field_link');
$this
->assertSession()
->fieldExists('fields[field_image][id]');
$this
->assertSession()
->fieldValueEquals('fields[field_image][id]', 'field_image');
$field_dependencies = \Drupal::config('search_api.index.' . $this->indexId)
->get('dependencies.config');
$this
->assertFalse(in_array('field.storage.node.field_link', (array) $field_dependencies), "The link field has been removed from the index's dependencies.");
$this
->assertTrue(in_array('field.storage.node.field_image', (array) $field_dependencies), "The image field has been removed from the index's dependencies.");
}
protected function removeFieldsFromIndex() {
$links = $this
->xpath('//a[@data-drupal-selector=:id]', [
':id' => 'edit-fields-body-remove',
]);
$this
->assertNotEmpty($links, 'Found "Remove" link for body field');
$this
->assertIsArray($links);
$url_target = $this
->getAbsoluteUrl($links[0]
->getAttribute('href'));
$this
->drupalGet($url_target);
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->submitForm([], 'Save changes');
$index = $this
->getIndex(TRUE);
$fields = $index
->getFields();
$this
->assertArrayNotHasKey('body', $fields);
}
protected function checkUnsavedChanges() {
$this
->addField('entity:node', 'changed', 'Changed');
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->assertSession()
->pageTextContains('You have unsaved changes.');
$this
->drupalLogin($this->adminUser2);
$username = [
'#theme' => 'username',
'#account' => $this->adminUser,
];
$args = [
'@user' => \Drupal::getContainer()
->get('renderer')
->renderPlain($username),
':url' => $this
->getIndex()
->toUrl('break-lock-form')
->toString(),
];
$message = (string) new FormattableMarkup('This index is being edited by user @user, and is therefore locked from editing by others. This lock is @age old. Click here to <a href=":url">break this lock</a>.', $args);
$message_parts = explode('@age', $message);
$this
->drupalGet($this
->getIndexPath('fields/add/nojs'));
$this
->assertSession()
->responseContains($message_parts[0]);
$this
->assertSession()
->responseContains($message_parts[1]);
$this
->assertSession()
->elementNotExists('xpath', '//input[not(@disabled)]');
$this
->drupalGet($this
->getIndexPath('fields/edit/rendered_item'));
$this
->assertSession()
->responseContains($message_parts[0]);
$this
->assertSession()
->responseContains($message_parts[1]);
$this
->assertSession()
->elementNotExists('xpath', '//input[not(@disabled)]');
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->assertSession()
->responseContains($message_parts[0]);
$this
->assertSession()
->responseContains($message_parts[1]);
$this
->assertSession()
->elementNotExists('xpath', '//input[not(@disabled)]');
$this
->clickLink('break this lock');
$this
->assertSession()
->responseContains(new FormattableMarkup('By breaking this lock, any unsaved changes made by @user will be lost.', $args));
$this
->submitForm([], 'Break lock');
$this
->assertSession()
->pageTextContains('The lock has been broken. You may now edit this search index.');
$index = $this
->getIndex(TRUE);
$fields = $index
->getFields();
$this
->assertArrayNotHasKey('changed', $fields);
$links = $this
->xpath('//a[@data-drupal-selector=:id]', [
':id' => 'edit-fields-title-remove',
]);
$this
->assertNotEmpty($links, 'Found "Remove" link for title field');
$this
->assertIsArray($links);
$url_target = $this
->getAbsoluteUrl($links[0]
->getAttribute('href'));
$this
->drupalGet($url_target);
$this
->assertSession()
->pageTextContains('You have unsaved changes.');
$this
->submitForm([], 'Cancel');
$this
->assertArrayHasKey('title', $fields, 'The title field has not been removed from the index.');
}
protected function checkReferenceFieldsNonBaseFields() {
$field_label = 'reference_field';
FieldStorageConfig::create([
'field_name' => 'field__reference_field_',
'type' => 'entity_reference',
'entity_type' => 'node',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'allowed_values' => [
[
'target_type' => 'node',
],
],
],
])
->save();
FieldConfig::create([
'field_name' => 'field__reference_field_',
'entity_type' => 'node',
'bundle' => 'article',
'label' => $field_label,
])
->save();
EntityFormDisplay::load('node.article.default')
->setComponent('field__reference_field_', [
'type' => 'entity_reference_autocomplete',
])
->save();
$node_label = $this
->getIndex()
->getDatasource('entity:node')
->label();
$field_label = "{$field_label} » {$node_label} » {$field_label}";
$this
->addField('entity:node', 'field__reference_field_:entity:field__reference_field_', $field_label);
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->submitForm([], 'Save changes');
$this
->drupalGet('node/2/edit');
$edit = [
'field__reference_field_[0][target_id]' => 'Something (2)',
];
$this
->drupalGet('node/2/edit');
$this
->submitForm($edit, 'Save');
$indexed_values = \Drupal::state()
->get("search_api_test.backend.indexed.{$this->indexId}", []);
$this
->assertEquals([
2,
], $indexed_values['entity:node/2:en']['field__reference_field_'], 'Correct value indexed for nested non-base field.');
}
protected function configureFilter() {
$edit = [
'status[ignorecase]' => 1,
'processors[ignorecase][settings][fields][title]' => 'title',
'processors[ignorecase][settings][fields][field__field_]' => FALSE,
];
$this
->drupalGet($this
->getIndexPath('processors'));
$this
->submitForm($edit, 'Save');
$index = $this
->getIndex(TRUE);
try {
$configuration = $index
->getProcessor('ignorecase')
->getConfiguration();
unset($configuration['weights']);
$expected = [
'fields' => [
'title',
],
'all_fields' => FALSE,
];
$this
->assertEquals($expected, $configuration, 'Title field enabled for ignore case filter.');
} catch (SearchApiException $e) {
$this
->fail('"Ignore case" processor not enabled.');
}
$this
->assertSession()
->pageTextContains('The indexing workflow was successfully edited.');
}
public function configureFilterPage() {
$this
->drupalGet($this
->getIndexPath('processors'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains('No values were changed.');
}
protected function checkProcessorChanges() {
$edit = [
'status[ignorecase]' => 1,
'processors[ignorecase][settings][fields][title]' => 'title',
];
$this
->drupalGet($this
->getIndexPath('processors'));
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('No values were changed.');
$this
->assertSession()
->pageTextNotContains('All content was scheduled for reindexing so the new settings can take effect.');
$edit['processors[ignorecase][settings][fields][title]'] = FALSE;
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('All content was scheduled for reindexing so the new settings can take effect.');
$this
->assertSession()
->responseContains($this
->getIndex()
->toUrl('canonical')
->toString());
}
protected function changeProcessorFieldBoost() {
$this
->addField(NULL, 'search_api_url', 'URI');
$fields_path = $this
->getIndexPath('fields');
$this
->drupalGet($fields_path);
$this
->submitForm([
'fields[url][boost]' => Utility::formatBoostFactor(8),
], 'Save changes');
$this
->assertSession()
->pageTextContains('The changes were successfully saved.');
$option_field = $this
->assertSession()
->optionExists('edit-fields-url-boost', Utility::formatBoostFactor(8));
$this
->assertTrue($option_field
->hasAttribute('selected'), 'Boost is correctly saved.');
$this
->drupalGet($fields_path);
$this
->submitForm([
'fields[url][type]' => 'text',
], 'Save changes');
$this
->assertSession()
->pageTextContains('The changes were successfully saved.');
$option_field = $this
->assertSession()
->optionExists('edit-fields-url-type', 'text');
$this
->assertTrue($option_field
->hasAttribute('selected'), 'Type is correctly saved.');
}
protected function setReadOnly() {
$index = $this
->getIndex(TRUE);
$index
->reindex();
$index_path = $this
->getIndexPath();
$settings_path = $index_path . '/edit';
$edit = [
'status' => TRUE,
'read_only' => TRUE,
'datasource_configs[entity:node][bundles][default]' => 0,
'datasource_configs[entity:node][bundles][selected][article]' => TRUE,
'datasource_configs[entity:node][bundles][selected][page]' => TRUE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$index = $this
->getIndex(TRUE);
$remaining_before = $this
->countRemainingItems();
$this
->drupalGet($index_path);
$this
->assertSession()
->pageTextNotContains('Index now');
$indexed = $this
->indexItems();
$this
->assertEquals(0, $indexed, 'No items were indexed after setting the index to "read only".');
$remaining_after = $this
->countRemainingItems();
$this
->assertEquals($remaining_before, $remaining_after, 'No items were indexed after setting the index to "read only".');
$edit = [
'read_only' => FALSE,
'datasource_configs[entity:node][bundles][default]' => 1,
'datasource_configs[entity:node][bundles][selected][article]' => FALSE,
'datasource_configs[entity:node][bundles][selected][page]' => FALSE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this
->drupalGet($index_path);
$this
->submitForm([], 'Index now');
$this
->checkForMetaRefresh();
$remaining_after = $index
->getTrackerInstance()
->getRemainingItemsCount();
$this
->assertEquals(0, $remaining_after, 'Items were indexed after removing the "read only" flag.');
}
protected function disableEnableIndex() {
$settings_path = $this
->getIndexPath('edit');
$edit = [
'status' => FALSE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(0, $tracked_items, 'No items are tracked after disabling the index.');
$tracked_items = \Drupal::database()
->select('search_api_item', 'i')
->countQuery()
->execute()
->fetchField();
$this
->assertEquals(0, $tracked_items, 'No items left in tracking table.');
$edit = [
'status' => TRUE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals(2, $tracked_items, 'After enabling the index, 2 items are tracked.');
}
protected function changeIndexDatasource() {
$index = $this
->getIndex(TRUE);
$index
->reindex();
$user_count = \Drupal::entityQuery('user')
->accessCheck(FALSE)
->count()
->execute();
$node_count = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->count()
->execute();
$settings_path = $this
->getIndexPath('edit');
$edit = [
'datasources[entity:user]' => TRUE,
'datasources[entity:node]' => TRUE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Please configure the used datasources.');
$this
->submitForm([], 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals($user_count + $node_count, $tracked_items, 'Correct number of items tracked after enabling the "User" datasource.');
$edit = [
'datasources[entity:user]' => FALSE,
'datasources[entity:node]' => TRUE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this
->executeTasks();
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals($node_count, $tracked_items, 'Correct number of items tracked after disabling the "User" datasource.');
}
protected function changeIndexServer() {
$node_count = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->count()
->execute();
$this
->assertEquals($node_count, $this
->countTrackedItems(), 'All nodes are correctly tracked by the index.');
$this
->indexItems();
$remaining_items = $this
->countRemainingItems();
$this
->assertEquals(0, $remaining_items, 'All items have been successfully indexed.');
$this
->createServer('test_server_2');
$settings_path = $this
->getIndexPath('edit');
$edit = [
'server' => $this->serverId,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$remaining_items = $this
->countRemainingItems();
$this
->assertEquals($node_count, $remaining_items, 'All items still need to be indexed.');
}
protected function checkIndexing() {
$node = $this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalCreateNode([
'type' => 'article',
]);
$key = 'search_api_test.backend.indexItems.skip';
\Drupal::state()
->set($key, [
'entity:node/' . $node
->id() . ':' . $node
->language()
->getId(),
]);
$this
->getIndex()
->reindex();
$this
->drupalGet($this
->getIndexPath());
$this
->submitForm([], 'Index now');
$this
->assertSession()
->statusCodeEquals(200);
$this
->checkForMetaRefresh();
$count = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->count()
->execute() - 1;
$this
->assertSession()
->pageTextContains("Successfully indexed {$count} items.");
$this
->assertSession()
->pageTextContains('1 item could not be indexed.');
$this
->assertSession()
->pageTextNotContains("Couldn't index items.");
$this
->assertSession()
->pageTextNotContains('An error occurred');
$this
->drupalGet($this
->getIndexPath());
$this
->submitForm([], 'Index now');
$this
->assertSession()
->statusCodeEquals(200);
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains("Couldn't index items.");
$this
->assertSession()
->pageTextNotContains('An error occurred');
\Drupal::state()
->set($key, []);
$this
->setError('backend', 'indexItems');
$this
->drupalGet($this
->getIndexPath());
$this
->submitForm([], 'Index now');
$this
->assertSession()
->statusCodeEquals(200);
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains("Couldn't index items.");
$this
->assertSession()
->pageTextNotContains('An error occurred');
$this
->setError('backend', 'indexItems', FALSE);
$this
->drupalGet($this
->getIndexPath());
$this
->submitForm([], 'Index now');
$this
->assertSession()
->statusCodeEquals(200);
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains("Successfully indexed 1 item.");
$this
->assertSession()
->pageTextNotContains('could not be indexed.');
$this
->assertSession()
->pageTextNotContains("Couldn't index items.");
$this
->assertSession()
->pageTextNotContains('An error occurred');
}
protected function checkIndexActions() {
$assert_session = $this
->assertSession();
$index = $this
->getIndex();
$tracker = $index
->getTrackerInstance();
$label = $index
->label();
$this
->indexItems();
$deleted = \Drupal::database()
->delete('search_api_item')
->condition('index_id', $index
->id())
->condition('item_id', Utility::createCombinedId('entity:node', '2:en'))
->execute();
$this
->assertEquals(1, $deleted);
$manipulated_items_count = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->count()
->execute() - 1;
$this
->assertEquals($manipulated_items_count, $tracker
->getIndexedItemsCount());
$this
->assertEquals($manipulated_items_count, $tracker
->getTotalItemsCount());
$this
->assertEquals($manipulated_items_count + 1, $this
->countItemsOnServer());
$this
->drupalGet($this
->getIndexPath('reindex'));
$this
->submitForm([], 'Confirm');
$assert_session
->pageTextContains("The search index {$label} was successfully queued for reindexing.");
$this
->assertEquals(0, $tracker
->getIndexedItemsCount());
$this
->assertEquals($manipulated_items_count, $tracker
->getTotalItemsCount());
$this
->assertEquals($manipulated_items_count + 1, $this
->countItemsOnServer());
$this
->indexItems();
$this
->drupalGet($this
->getIndexPath('clear'));
$this
->submitForm([], 'Confirm');
$assert_session
->pageTextContains("All items were successfully deleted from search index {$label}.");
$this
->assertEquals(0, $tracker
->getIndexedItemsCount());
$this
->assertEquals($manipulated_items_count, $tracker
->getTotalItemsCount());
$this
->assertEquals(0, $this
->countItemsOnServer());
$this
->indexItems();
$this
->drupalGet($this
->getIndexPath('rebuild-tracker'));
$this
->submitForm([], 'Confirm');
$assert_session
->pageTextContains("The tracking information for search index {$label} will be rebuilt.");
$this
->assertEquals(0, $tracker
->getIndexedItemsCount());
$this
->assertEquals($manipulated_items_count + 1, $tracker
->getTotalItemsCount());
$this
->assertEquals($manipulated_items_count, $this
->countItemsOnServer());
$this
->indexItems();
}
protected function deleteServer() {
$server = Server::load($this->serverId);
$this
->drupalGet('admin/config/search/search-api/server/' . $this->serverId . '/delete');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains(new FormattableMarkup('Are you sure you want to delete the search server %name?', [
'%name' => $server
->label(),
]));
$this
->assertSession()
->pageTextContains('Deleting a server will disable all its indexes and their searches.');
$this
->submitForm([], 'Delete');
$this
->assertSession()
->responseContains(new FormattableMarkup('The search server %name has been deleted.', [
'%name' => $server
->label(),
]));
$this
->assertNull(Server::load($this->serverId), 'Server could not be found anymore.');
$this
->assertSession()
->addressEquals('admin/config/search/search-api');
$this->indexStorage
->resetCache([
$this->indexId,
]);
$index = $this->indexStorage
->load($this->indexId);
$this
->assertInstanceOf(IndexInterface::class, $index, 'The index associated with the server was not deleted.');
$this
->assertFalse($index
->status(), 'The index associated with the server was disabled.');
$this
->assertNull($index
->getServerId(), 'The index was removed from the server.');
}
protected function getIndex($reset = FALSE) {
if ($reset) {
$this->indexStorage
->resetCache([
$this->indexId,
]);
}
return $this->indexStorage
->load($this->indexId);
}
protected function indexItems() {
$index = Index::load($this->indexId);
return $index
->indexItems();
}
protected function assertHtmlEscaped($string) {
$this
->assertSession()
->responseContains(Html::escape($string));
$this
->assertSession()
->responseNotContains(Html::escape(Html::escape($string)));
$this
->assertSession()
->responseNotContains($string);
}
}