/**
  * {@inheritdoc}
  */
 public function setUp($processor = NULL)
 {
     parent::setUp('rendered_item');
     // Load configuration and needed schemas. (The necessary schemas for using
     // nodes are already installed by the parent method.)
     $this->installConfig(array('system', 'filter', 'node', 'comment'));
     $this->installSchema('system', array('router'));
     \Drupal::service('router.builder')->rebuild();
     // Create a node type for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     node_add_body_field($type);
     // Create anonymous user role.
     $role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
     $role->save();
     // Insert the anonymous user into the database.
     $anonymous_user = User::create(array('uid' => 0, 'name' => ''));
     $anonymous_user->save();
     // Default node values for all nodes we create below.
     $node_data = array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => '', 'body' => array('value' => '', 'summary' => '', 'format' => 'plain_text'), 'uid' => $anonymous_user->id());
     // Create some test nodes with valid user on it for rendering a picture.
     $node_data['title'] = 'Title for node 1';
     $node_data['body']['value'] = 'value for node 1';
     $node_data['body']['summary'] = 'summary for node 1';
     $this->nodes[1] = Node::create($node_data);
     $this->nodes[1]->save();
     $node_data['title'] = 'Title for node 2';
     $node_data['body']['value'] = 'value for node 2';
     $node_data['body']['summary'] = 'summary for node 2';
     $this->nodes[2] = Node::create($node_data);
     $this->nodes[2]->save();
     // Set proper configuration for the tested processor.
     $config = $this->processor->getConfiguration();
     $config['view_mode'] = array('entity:node' => ['page' => 'full', 'article' => 'teaser'], 'entity:user' => 'compact', 'entity:comment' => 'teaser');
     $config['roles'] = array($role->id());
     $this->processor->setConfiguration($config);
     $this->index->save();
     $this->index->getDatasources();
     // Enable the classy theme as the tests rely on markup from that.
     \Drupal::service('theme_handler')->install(array('classy'));
     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('classy'));
 }
 /**
  * {@inheritdoc}
  */
 public function setUp($processor = NULL)
 {
     parent::setUp('content_access');
     // The parent method already installs most needed node and comment schemas,
     // but here we also need the comment statistics.
     $this->installSchema('comment', array('comment_entity_statistics'));
     // Create a node type for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     // Create anonymous user role.
     $role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
     $role->save();
     // Insert the anonymous user into the database, as the user table is inner
     // joined by \Drupal\comment\CommentStorage.
     User::create(array('uid' => 0, 'name' => ''))->save();
     // Create a node with attached comment.
     $this->nodes[0] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'test title'));
     $this->nodes[0]->save();
     $comment_type = CommentType::create(array('id' => 'comment', 'target_entity_type_id' => 'node'));
     $comment_type->save();
     $this->installConfig(array('comment'));
     $this->addDefaultCommentField('node', 'page');
     $comment = Comment::create(array('entity_type' => 'node', 'entity_id' => $this->nodes[0]->id(), 'field_name' => 'comment', 'body' => 'test body', 'comment_type' => $comment_type->id()));
     $comment->save();
     $this->comments[] = $comment;
     $this->nodes[1] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'some title'));
     $this->nodes[1]->save();
     $this->nodes[2] = Node::create(array('status' => NODE_NOT_PUBLISHED, 'type' => 'page', 'title' => 'other title'));
     $this->nodes[2]->save();
     // Also index users, to verify that they are unaffected by the processor.
     $manager = \Drupal::getContainer()->get('plugin.manager.search_api.datasource');
     $datasources['entity:comment'] = $manager->createInstance('entity:comment', array('index' => $this->index));
     $datasources['entity:node'] = $manager->createInstance('entity:node', array('index' => $this->index));
     $datasources['entity:user'] = $manager->createInstance('entity:user', array('index' => $this->index));
     $this->index->setDatasources($datasources);
     $this->index->save();
     \Drupal::getContainer()->get('search_api.index_task_manager')->addItemsAll($this->index);
     $index_storage = \Drupal::entityTypeManager()->getStorage('search_api_index');
     $index_storage->resetCache([$this->index->id()]);
     $this->index = $index_storage->load($this->index->id());
 }