diff --git a/src/Entity/Server.php b/src/Entity/Server.php index fac5f8f..f7e9427 100644 --- a/src/Entity/Server.php +++ b/src/Entity/Server.php @@ -434,8 +434,8 @@ class Server extends ConfigEntityBase implements ServerInterface { parent::calculateDependencies(); // Add the backend's dependencies. - if ($this->hasValidBackend() && ($backend = $this->getBackend())) { - $this->addDependencies($backend->calculateDependencies()); + if ($this->hasValidBackend()) { + $this->calculatePluginDependencies($this->getBackend()); } return $this->dependencies; diff --git a/src/Plugin/ConfigurablePluginBase.php b/src/Plugin/ConfigurablePluginBase.php index d3edd25..0ea2a32 100644 --- a/src/Plugin/ConfigurablePluginBase.php +++ b/src/Plugin/ConfigurablePluginBase.php @@ -100,8 +100,7 @@ abstract class ConfigurablePluginBase extends PluginBase implements Configurable * {@inheritdoc} */ public function calculateDependencies() { - $this->addDependency('module', $this->getPluginDefinition()['provider']); - return $this->dependencies; + return array(); } } diff --git a/src/Tests/DependencyRemovalTest.php b/src/Tests/DependencyRemovalTest.php index 5cf1dbd..f0f082d 100644 --- a/src/Tests/DependencyRemovalTest.php +++ b/src/Tests/DependencyRemovalTest.php @@ -15,11 +15,16 @@ namespace Drupal\search_api\Tests; class DependencyRemovalTest extends WebTestBase { /** - * The ID of the search index used for this test. + * The permissions of the admin user. * - * @var string + * @var string[] */ - protected $indexId; + protected $adminUserPermissions = array( + 'administer search_api', + 'administer content types', + 'access administration pages', + 'administer modules', + ); /** * {@inheritdoc} @@ -39,18 +44,21 @@ class DependencyRemovalTest extends WebTestBase { // Login with a user that has sufficient permissions, including // uninstalling modules. - $admin_user = $this->drupalCreateUser(array( - 'administer search_api', - 'administer content types', - 'access administration pages', - 'administer modules', - )); - $this->drupalLogin($admin_user); + $this->drupalLogin($this->adminUser); // Create a server and index. $this->getTestServer(); - $index = $this->getTestIndex(); - $this->indexId = $index->id(); + $this->getTestIndex(); + } + + /** + * Tests whether removing dependencies of an index works correctly. + * + * Single test method to avoid the overhead of Drupal installation for each of + * the test methods. + */ + public function testDependencyRemoval() { + $this->checkProcessorRemoval(); } /** @@ -61,7 +69,7 @@ class DependencyRemovalTest extends WebTestBase { * removal of facets and views as well. Instead, the processor should just be * disabled and no longer be found on the processors tab. */ - public function testProcessorRemoval() { + protected function checkProcessorRemoval() { // Enable the dummy processor on the index. $this->drupalGet($this->getIndexPath('processors')); $this->assertText($this->t('Dummy processor')); @@ -89,58 +97,4 @@ class DependencyRemovalTest extends WebTestBase { $this->assertNoText('Dummy processor'); } - /** - * Tests the reaction of an index when a content type is removed. - * - * When a content type that is indexed is removed, the index shouldn't be - * removed as well. - */ - public function testContentTypeRemoval() { - // Add two articles and a page. - $this->drupalCreateNode(array('type' => 'article')); - $this->drupalCreateNode(array('type' => 'article')); - $page = $this->drupalCreateNode(array('type' => 'page')); - - // Make sure the content is indexed. - $this->drupalGet($this->getIndexPath()); - $this->assertText('3/3 indexed'); - - // Try to delete content type. - $this->drupalGet('admin/structure/types/manage/page/delete'); - $this->assertText('Page is used by 1 piece of content on your site.'); - - // Delete the only created page. - $page->delete(); - - // Delete the content type. - $this->drupalGet('admin/structure/types/manage/page/delete'); - $this->drupalPostForm(NULL, array(), $this->t('Delete')); - $this->assertText('The content type Page has been deleted'); - - // Make sure the index is still actually present. - $this->drupalGet('admin/config/search/search-api'); - $this->assertText('WebTest Index'); - - // Make sure the content is indexed. - $this->drupalGet($this->getIndexPath()); - $this->assertText('2/2 indexed'); - } - - /** - * Returns the system path for the test index. - * - * @param string|null $tab - * (optional) If set, the path suffix for a specific index tab. - * - * @return string - * A system path. - */ - protected function getIndexPath($tab = NULL) { - $path = 'admin/config/search/search-api/index/' . $this->indexId; - if ($tab) { - $path .= "/$tab"; - } - return $path; - } - } diff --git a/src/Tests/HooksTest.php b/src/Tests/HooksTest.php index bc66fff..9f7ff4f 100644 --- a/src/Tests/HooksTest.php +++ b/src/Tests/HooksTest.php @@ -20,13 +20,6 @@ class HooksTest extends WebTestBase { public static $modules = array('node', 'search_api', 'search_api_test_backend', 'search_api_test_views', 'search_api_test_hooks'); /** - * The id of the index. - * - * @var string - */ - protected $indexId; - - /** * Tests various operations via the Search API's admin UI. */ public function testHooks() { @@ -41,8 +34,7 @@ class HooksTest extends WebTestBase { // Create an index and server to work with. $this->getTestServer(); - $index = $this->getTestIndex(); - $this->indexId = $index->id(); + $this->getTestIndex(); // hook_search_api_backend_info_alter was triggered. $this->drupalGet('admin/config/search/search-api/add-server'); @@ -89,21 +81,4 @@ class HooksTest extends WebTestBase { $this->assertText('Llama'); } - /** - * Returns the system path for the test index. - * - * @param string|null $tab - * (optional) If set, the path suffix for a specific index tab. - * - * @return string - * A system path. - */ - protected function getIndexPath($tab = NULL) { - $path = 'admin/config/search/search-api/index/' . $this->indexId; - if ($tab) { - $path .= "/$tab"; - } - return $path; - } - } diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index dc46b93..06646e8 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -27,13 +27,6 @@ class IntegrationTest extends WebTestBase { protected $serverId; /** - * The ID of the search index used for this test. - * - * @var string - */ - protected $indexId; - - /** * A storage instance for indexes. * * @var \Drupal\Core\Entity\EntityStorageInterface @@ -623,21 +616,4 @@ class IntegrationTest extends WebTestBase { } } - /** - * Returns the system path for the test index. - * - * @param string|null $tab - * (optional) If set, the path suffix for a specific index tab. - * - * @return string - * A system path. - */ - protected function getIndexPath($tab = NULL) { - $path = 'admin/config/search/search-api/index/' . $this->indexId; - if ($tab) { - $path .= "/$tab"; - } - return $path; - } - } diff --git a/src/Tests/Processor/ProcessorIntegrationTest.php b/src/Tests/Processor/ProcessorIntegrationTest.php index 65b7b60..b782c11 100644 --- a/src/Tests/Processor/ProcessorIntegrationTest.php +++ b/src/Tests/Processor/ProcessorIntegrationTest.php @@ -20,13 +20,6 @@ use Drupal\search_api\Tests\WebTestBase; class ProcessorIntegrationTest extends WebTestBase { /** - * The ID of the search index used by this test. - * - * @var string - */ - protected $indexId; - - /** * {@inheritdoc} */ public function setUp() { diff --git a/src/Tests/ViewsTest.php b/src/Tests/ViewsTest.php index 04e6960..af9edf9 100644 --- a/src/Tests/ViewsTest.php +++ b/src/Tests/ViewsTest.php @@ -27,13 +27,6 @@ class ViewsTest extends WebTestBase { public static $modules = array('search_api_test_views'); /** - * A search index ID. - * - * @var string - */ - protected $indexId = 'database_search_index'; - - /** * {@inheritdoc} */ public function setUp() { @@ -41,6 +34,7 @@ class ViewsTest extends WebTestBase { $this->setUpExampleStructure(); + $this->indexId = 'database_search_index'; Utility::getIndexTaskManager()->addItemsAll(Index::load($this->indexId)); } diff --git a/src/Tests/WebTestBase.php b/src/Tests/WebTestBase.php index f19efd0..82327ef 100644 --- a/src/Tests/WebTestBase.php +++ b/src/Tests/WebTestBase.php @@ -34,6 +34,13 @@ abstract class WebTestBase extends SimpletestWebTestBase { protected $adminUser; /** + * The permissions of the admin user. + * + * @var string[] + */ + protected $adminUserPermissions = array('administer search_api', 'access administration pages'); + + /** * A user without Search API admin permission. * * @var \Drupal\Core\Session\AccountInterface @@ -55,13 +62,20 @@ abstract class WebTestBase extends SimpletestWebTestBase { protected $urlGenerator; /** + * The ID of the search index used for this test. + * + * @var string + */ + protected $indexId; + + /** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Create the users used for the tests. - $this->adminUser = $this->drupalCreateUser(array('administer search_api', 'access administration pages')); + $this->adminUser = $this->drupalCreateUser($this->adminUserPermissions); $this->unauthorizedUser = $this->drupalCreateUser(array('access administration pages')); $this->anonymousUser = $this->drupalCreateUser(); @@ -154,9 +168,27 @@ abstract class WebTestBase extends SimpletestWebTestBase { 'datasources' => array($datasource_id), )); $index->save(); + $this->indexId = $index->id(); } return $index; } + /** + * Returns the system path for the test index. + * + * @param string|null $tab + * (optional) If set, the path suffix for a specific index tab. + * + * @return string + * A system path. + */ + protected function getIndexPath($tab = NULL) { + $path = 'admin/config/search/search-api/index/' . $this->indexId; + if ($tab) { + $path .= "/$tab"; + } + return $path; + } + }