1010use Drupal \dkan_metastore \MetastoreService ;
1111use Drupal \search_api \IndexInterface ;
1212use Drupal \search_api \Item \Item ;
13+ use Drupal \search_api \ParseMode \ParseModePluginManager ;
14+ use Drupal \search_api \Plugin \search_api \parse_mode \Terms ;
1315use Drupal \search_api \Query \ConditionGroup ;
16+ use Drupal \search_api \Query \Query ;
1417use Drupal \search_api \Query \QueryInterface ;
1518use Drupal \search_api \Query \ResultSet ;
1619use Drupal \search_api \Utility \QueryHelperInterface ;
@@ -70,7 +73,19 @@ public function testSearch() {
7073 ]));
7174 }
7275
73- public function testSearchParameterWithComma () {
76+ /**
77+ * Test two things.
78+ *
79+ * 1. That commas in non-fulltext parameters get properly handled and don't
80+ * mess up parsing.
81+ * 2. That fulltext parameters get sent to keys()
82+ *
83+ * Because none of the functions we can test here return the query object, we
84+ * can't test that the keys() are being parsed as expected, but we should be
85+ * able to trust that if the input is sent to keys(), it will be handled
86+ * as expected by Search API.
87+ */
88+ public function testSearchParameterWithCommaAndFulltext () {
7489 $ options = (new Options ())
7590 ->add ('dkan.metastore.service ' , MetastoreService::class)
7691 ->add ('entity_type.manager ' , EntityTypeManager::class)
@@ -88,6 +103,7 @@ public function testSearchParameterWithComma() {
88103 ->add (QueryHelperInterface::class, 'createQuery ' , QueryInterface::class)
89104 ->add (QueryInterface::class, 'execute ' , ResultSet::class)
90105 ->add (QueryInterface::class, 'createConditionGroup ' , ConditionGroup::class)
106+ ->add (QueryInterface::class, 'keys ' , null , 'keys ' )
91107 ->add (ConditionGroup::class, 'addCondition ' , null , 'condition_group ' );
92108
93109 \Drupal::setContainer ($ container ->getMock ());
@@ -102,6 +118,15 @@ public function testSearchParameterWithComma() {
102118 'Steve, and someone else ' ,
103119 $ container ->getStoredInput ('condition_group ' )[1 ]
104120 );
121+
122+ // Now assert fulltext ends up getting sent to keys()
123+ $ service ->search ([
124+ 'fulltext ' => 'Fulltext Param, "Steve, and someone else" ' ,
125+ ]);
126+ $ this ->assertEquals (
127+ 'Fulltext Param, "Steve, and someone else" ' ,
128+ $ container ->getStoredInput ('keys ' )[0 ]
129+ );
105130 }
106131
107132 /**
0 commit comments