3 use Drupal\search_api\Item\Item;
4 use Drupal\search_api\Query\ConditionGroup;
5 use Drupal\search_api\Query\ResultSet;
8 use PHPUnit\Framework\TestCase;
9 use Symfony\Component\HttpFoundation\ParameterBag;
10 use Symfony\Component\HttpFoundation\Request;
11 use Symfony\Component\HttpFoundation\RequestStack;
12 use Drupal\Component\DependencyInjection\Container;
13 use Drupal\Core\Entity\EntityManager;
14 use Drupal\Core\Entity\EntityStorageInterface;
15 use Drupal\search_api\IndexInterface;
16 use Drupal\search_api\Query\QueryInterface;
17 use Drupal\search_api\Utility\QueryHelperInterface;
31 $paramsBag = (
new Chain($this))
32 ->add(ParameterBag::class,
'all',
35 'fulltext' =>
'hello',
36 'description' =>
'goodbye',
37 'sort' =>
'description',
38 'sort-order' =>
'asc',
42 $request = (
new Chain($this))
43 ->add(Request::class,
'blah', NULL)
46 $reflection =
new ReflectionClass($request);
47 $reflection_property = $reflection->getProperty(
'query');
48 $reflection_property->setAccessible(TRUE);
49 $reflection_property->setValue($request, $paramsBag);
51 $options = (
new Options())
52 ->add(
'entity_type.manager', EntityManager::class)
53 ->add(
'request_stack', RequestStack::class)
54 ->add(
'search_api.query_helper', QueryHelperInterface::class)
55 ->add(
'dkan_metastore.service', Service::class)
58 $item = (
new Chain($this))
59 ->add(Item::class,
'getId', 1)
62 $thing = (object) [
'title' =>
'hello',
'description' =>
'goodbye',
'publisher__name' =>
'Steve'];
63 $facet = (object) [
'data' => (
object) [
'name' =>
'Steve']];
64 $expect = (object) [
'type' =>
'publisher__name',
'name' =>
'Steve',
'total' => 1];
66 $container = (
new Chain($this))
67 ->add(Container::class,
"get", $options)
68 ->add(EntityManager::class,
'getStorage', EntityStorageInterface::class)
69 ->add(EntityStorageInterface::class,
'load', IndexInterface::class)
70 ->add(IndexInterface::class,
'getFields', [
'description' =>
'blah',
'publisher__name' =>
'blah'])
71 ->add(IndexInterface::class,
'getFulltextFields', [
'title'])
72 ->add(RequestStack::class,
'getCurrentRequest', $request)
73 ->add(QueryHelperInterface::class,
'createQuery', QueryInterface::class)
74 ->add(QueryInterface::class,
'execute', ResultSet::class)
75 ->add(QueryInterface::class,
'createConditionGroup', ConditionGroup::class)
76 ->add(ResultSet::class,
'getResultCount', 1)
77 ->add(ResultSet::class,
'getResultItems', [$item])
78 ->add(Service::class,
'get', json_encode($thing))
79 ->add(Service::class,
'getAll', [$facet])
82 \Drupal::setContainer($container);
87 $response = $controller->search();
89 json_encode((
object) [
'total' => 1,
'results' => [$thing],
'facets' => [$expect]]),
90 $response->getContent());
97 $container = (
new Chain($this))
98 ->add(Container::class,
"get", EntityManager::class)
99 ->add(EntityManager::class,
'getStorage', EntityStorageInterface::class)
102 \Drupal::setContainer($container);
107 $response = $controller->search();
108 $this->assertEquals(json_encode((
object) [
'message' =>
"An index named [dkan] does not exist."]), $response->getContent());