コード例 #1
0
 /**
  * Tests whether module dependencies are handled correctly.
  */
 public function testModuleDependency()
 {
     // Test with all types of plugins at once.
     $datasources['search_api_test_dependencies'] = \Drupal::getContainer()->get('plugin.manager.search_api.datasource')->createInstance('search_api_test_dependencies', array('index' => $this->index));
     $datasources['entity:user'] = \Drupal::getContainer()->get('plugin.manager.search_api.datasource')->createInstance('entity:user', array('index' => $this->index));
     $this->index->setDatasources($datasources);
     $processor = \Drupal::getContainer()->get('plugin.manager.search_api.processor')->createInstance('search_api_test_dependencies');
     $this->index->addProcessor($processor);
     $tracker = \Drupal::getContainer()->get('plugin.manager.search_api.tracker')->createInstance('search_api_test_dependencies');
     $this->index->setTracker($tracker);
     $this->index->save();
     // Check the dependencies were calculated correctly.
     $dependencies = $this->index->getDependencies();
     $this->assertContains('search_api_test_dependencies', $dependencies['module'], 'Module dependency correctly inserted');
     // When the index resets the tracker, it needs to know the ID of the default
     // tracker.
     \Drupal::configFactory()->getEditable('search_api.settings')->set('default_tracker', 'default')->save();
     // Disabling modules in Kernel tests normally doesn't trigger any kind of
     // reaction, just removes it from the list of modules (e.g., to avoid
     // calling of a hook). Therefore, we have to trigger that behavior
     // ourselves.
     \Drupal::getContainer()->get('config.manager')->uninstall('module', 'search_api_test_dependencies');
     // Reload the index and check it's still there.
     $this->reloadIndex();
     $this->assertInstanceOf('Drupal\\search_api\\IndexInterface', $this->index, 'Index not removed');
     // Make sure the dependency has been removed.
     $dependencies = $this->index->getDependencies();
     $dependencies += array('module' => array());
     $this->assertNotContains('search_api_test_dependencies', $dependencies['module'], 'Module dependency removed from index');
     // Make sure all the plugins have been removed.
     $this->assertNotContains('search_api_test_dependencies', $this->index->getDatasources(), 'Datasource was removed');
     $this->assertArrayNotHasKey('search_api_test_dependencies', $this->index->getProcessors(), 'Processor was removed');
     $this->assertEquals('default', $this->index->getTrackerId(), 'Tracker was reset');
 }
コード例 #2
0
 /**
  * Performs setup tasks before each individual test method is run.
  *
  * Installs commonly used schemas and sets up a search server and an index,
  * with the specified processor enabled.
  *
  * @param string|null $processor
  *   (optional) The plugin ID of the processor that should be set up for
  *   testing.
  */
 public function setUp($processor = NULL)
 {
     parent::setUp();
     $this->installSchema('node', array('node_access'));
     $this->installSchema('search_api', array('search_api_item', 'search_api_task'));
     $this->installEntitySchema('user');
     $this->installEntitySchema('node');
     $this->installEntitySchema('comment');
     $this->installConfig(array('field'));
     Action::create(['id' => 'foo', 'label' => 'Foobaz', 'plugin' => 'comment_publish_action'])->save();
     \Drupal::configFactory()->getEditable('search_api.settings')->set('tracking_page_size', 100)->save();
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
     \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
     $this->server = Server::create(array('id' => 'server', 'name' => 'Server & Name', 'status' => TRUE, 'backend' => 'search_api_db', 'backend_config' => array('min_chars' => 3, 'database' => 'default:default')));
     $this->server->save();
     $this->index = Index::create(array('id' => 'index', 'name' => 'Index name', 'status' => TRUE, 'datasource_settings' => array('entity:comment' => array('plugin_id' => 'entity:comment', 'settings' => array()), 'entity:node' => array('plugin_id' => 'entity:node', 'settings' => array())), 'server' => 'server', 'tracker_settings' => array('default' => array('plugin_id' => 'default', 'settings' => array()))));
     $this->index->setServer($this->server);
     $field_subject = new Field($this->index, 'subject');
     $field_subject->setType('text');
     $field_subject->setPropertyPath('subject');
     $field_subject->setDatasourceId('entity:comment');
     $field_subject->setLabel('Subject');
     $field_title = new Field($this->index, 'title');
     $field_title->setType('text');
     $field_title->setPropertyPath('title');
     $field_title->setDatasourceId('entity:node');
     $field_title->setLabel('Title');
     $this->index->addField($field_subject);
     $this->index->addField($field_title);
     if ($processor) {
         /** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */
         $plugin_manager = \Drupal::service('plugin.manager.search_api.processor');
         $this->processor = $plugin_manager->createInstance($processor, array('index' => $this->index));
         $this->index->addProcessor($this->processor);
     }
     $this->index->save();
 }