count()->execute(); $entity_test_storage = \Drupal::entityTypeManager() ->getStorage('entity_test'); $this->entities[1] = $entity_test_storage->create(array( 'name' => 'foo bar baz', 'body' => 'test test', 'type' => 'item', 'keywords' => array('orange'), 'category' => 'item_category', )); $this->entities[1]->save(); $this->entities[2] = $entity_test_storage->create(array( 'name' => 'foo test', 'body' => 'bar test', 'type' => 'item', 'keywords' => array('orange', 'apple', 'grape'), 'category' => 'item_category', )); $this->entities[2]->save(); $this->entities[3] = $entity_test_storage->create(array( 'name' => 'bar', 'body' => 'test foobar', 'type' => 'item', )); $this->entities[3]->save(); $this->entities[4] = $entity_test_storage->create(array( 'name' => 'foo baz', 'body' => 'test test test', 'type' => 'article', 'keywords' => array('apple', 'strawberry', 'grape'), 'category' => 'article_category', )); $this->entities[4]->save(); $this->entities[5] = $entity_test_storage->create(array( 'name' => 'bar baz', 'body' => 'foo', 'type' => 'article', 'keywords' => array('orange', 'strawberry', 'grape', 'banana'), 'category' => 'article_category', )); $this->entities[5]->save(); $count = \Drupal::entityQuery('entity_test')->count()->execute() - $count; $this->assertEqual($count, 5, "$count items inserted."); } /** * Indexes all (unindexed) items on the specified index. * * @param string $index_id * The ID of the index on which items should be indexed. * * @return int * The number of successfully indexed items. */ protected function indexItems($index_id) { /** @var \Drupal\search_api\IndexInterface $index */ $index = Index::load($index_id); return $index->indexItems(); } }