public function DependencyRemovalTest::testSearchPluginDependency in Search API Autocomplete 8
Tests that a general search plugin dependency works correctly.
@dataProvider searchPluginDependencyDataProvider
Parameters
bool $removable: TRUE if the search plugin's dependency should be removable, FALSE otherwise.
File
- tests/
src/ Kernel/ DependencyRemovalTest.php, line 143
Class
- DependencyRemovalTest
- Tests dependency handling of the search entity.
Namespace
Drupal\Tests\search_api_autocomplete\KernelCode
public function testSearchPluginDependency($removable) {
$dependency_key = $this->dependency
->getConfigDependencyKey();
$dependency_name = $this->dependency
->getConfigDependencyName();
$this->search
->set('search_settings', [
'search_api_autocomplete_test' => [
'dependencies' => [
$dependency_key => [
$dependency_name,
],
],
],
]);
$this->search
->save();
$this
->setReturnValue('search', 'onDependencyRemoval', $removable);
// Verify that the dependencies are all included.
$dependencies = $this->search
->getDependencies();
$this
->assertArrayHasKey($dependency_key, $dependencies);
$this
->assertContains($dependency_name, $dependencies[$dependency_key]);
$this
->assertArrayHasKey('module', $dependencies);
$this
->assertContains('search_api_autocomplete_test', $dependencies['module']);
// Delete the dependency and verify that the result is as expected.
$this->dependency
->delete();
$search = Search::load($this->search
->id());
if ($removable) {
$this
->assertNotNull($search);
$dependencies = $search
->getDependencies();
$dependencies += [
$dependency_key => [],
];
$this
->assertNotContains($dependency_name, $dependencies[$dependency_key]);
}
else {
$this
->assertNull($search);
}
}