View source
<?php
namespace Drupal\Tests\search_api\Functional;
use Drupal\search_api_test\MethodOverrides;
use Drupal\search_api_test\PluginTestTrait;
class ConfigOverrideIntegrationTest extends SearchApiBrowserTestBase {
use PluginTestTrait;
public function setUp() {
parent::setUp();
$settings['config']['search_api.server.test_server']['name'] = (object) [
'value' => 'Overridden server',
'required' => TRUE,
];
$settings['config']['search_api.server.test_server']['status'] = (object) [
'value' => TRUE,
'required' => TRUE,
];
$settings['config']['search_api.server.test_server']['backend_config']['test'] = (object) [
'value' => 'foobar',
'required' => TRUE,
];
$settings['config']['search_api.index.test_index']['name'] = (object) [
'value' => 'Overridden index',
'required' => TRUE,
];
$this
->writeSettings($settings);
$permissions = [
'administer search_api',
'access administration pages',
'administer nodes',
'bypass node access',
'administer content types',
];
$this->adminUser = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->adminUser);
}
public function testConfigOverrideIntegration() {
$base_path = 'admin/config/search/search-api';
$new_user = $this
->drupalCreateUser();
$override = [
MethodOverrides::class,
'overrideTestBackendMethod',
];
$methods = [
'postInsert',
'preUpdate',
'postUpdate',
'addIndex',
'updateIndex',
'removeIndex',
'deleteItems',
'deleteAllIndexItems',
'search',
'isAvailable',
'getDiscouragedProcessors',
];
foreach ($methods as $method) {
$this
->setMethodOverride('backend', $method, $override);
}
$override = [
MethodOverrides::class,
'overrideTestBackendIndexItems',
];
$this
->setMethodOverride('backend', 'indexItems', $override);
$this
->drupalGet("{$base_path}/add-server");
$edit = [
'id' => 'test_server',
'name' => 'Test server',
'backend' => 'search_api_test',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The server was successfully saved.');
$this
->assertSession()
->addressEquals($base_path . '/server/test_server');
$this
->drupalGet("{$base_path}/add-index");
$edit = [
'id' => 'test_index',
'name' => 'Test index',
'server' => 'test_server',
'datasources[entity:user]' => TRUE,
'options[index_directly]' => FALSE,
];
$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($base_path . '/index/test_index');
$this
->drupalGet($base_path);
$this
->assertSession()
->pageTextContains('Overridden server');
$this
->assertSession()
->responseNotContains('Test server');
$this
->assertSession()
->pageTextContains('Overridden index');
$this
->assertSession()
->responseNotContains('Test index');
$this
->drupalGet($base_path . '/server/test_server');
$this
->assertSession()
->pageTextContains('Overridden server');
$this
->assertSession()
->responseNotContains('Test server');
$this
->assertSession()
->pageTextContains('Overridden index');
$this
->assertSession()
->responseNotContains('Test index');
$this
->assertSession()
->pageTextContains('enabled');
$this
->assertSession()
->responseNotContains('disabled');
$this
->clickLink('disable');
$this
->assertSession()
->pageTextContains('Test server');
$this
->assertSession()
->responseNotContains('Overridden server');
$this
->submitForm([], 'Disable');
$this
->drupalGet($base_path . '/server/test_server');
$this
->assertSession()
->pageTextContains('enabled');
$this
->assertSession()
->responseNotContains('disabled');
$this
->drupalGet($base_path . '/server/test_server/edit');
$this
->assertSession()
->pageTextContains('Test server');
$this
->assertSession()
->responseNotContains('Overridden server');
$this
->assertSession()
->responseNotContains('foobar');
$edit = [
'name' => 'New server name',
'backend_config[test]' => 'nonsense',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->addressEquals($base_path . '/server/test_server');
$this
->assertSession()
->pageTextContains('Overridden server');
$this
->assertSession()
->responseNotContains('New server name');
$this
->drupalGet($base_path . '/server/test_server/edit');
$this
->assertSession()
->pageTextContains('New server name');
$this
->assertSession()
->responseNotContains('Overridden server');
$this
->assertSession()
->responseContains('nonsense');
$this
->assertSession()
->responseNotContains('foobar');
$this
->drupalGet($base_path . '/server/test_server/clear');
$this
->assertSession()
->pageTextContains('Overridden server');
$this
->assertSession()
->responseNotContains('New server name');
$this
->submitForm([], 'Confirm');
$this
->drupalGet($base_path . '/index/test_index');
$this
->assertSession()
->pageTextContains('Overridden index');
$this
->assertSession()
->responseNotContains('Test index');
$this
->assertSession()
->pageTextContains('Overridden server');
$this
->assertSession()
->responseNotContains('New server name');
$this
->assertSession()
->pageTextContains('enabled');
$this
->assertSession()
->responseNotContains('disabled');
$this
->submitForm([], 'Index now');
$this
->checkForMetaRefresh();
$new_user
->delete();
foreach ([
'edit',
'fields',
'fields/add/nojs',
'processors',
'disable',
] as $tab) {
$this
->drupalGet("{$base_path}/index/test_index/{$tab}");
$this
->assertSession()
->pageTextContains('Test index');
$this
->assertSession()
->responseNotContains('Overridden index');
}
foreach ([
'reindex',
'clear',
] as $tab) {
$this
->drupalGet("{$base_path}/index/test_index/{$tab}");
$this
->assertSession()
->pageTextContains('Overridden index');
$this
->assertSession()
->responseNotContains('Test index');
}
$this
->submitForm([], 'Confirm');
$this
->drupalGet($base_path . '/server/test_server/delete');
$this
->assertSession()
->pageTextContains('Overridden server');
$this
->assertSession()
->responseNotContains('New server name');
$this
->assertSession()
->pageTextContains('Overridden index');
$this
->assertSession()
->responseNotContains('Test index');
$this
->submitForm([], 'Delete');
}
}