For testing advanced service class functionality (of other modules like Database search), having a multi-valued field in the test entity is needed.

Another option would be to copy this module to the DB search project and modify it there – however, since this would lead to a lot of code duplication, I think this way is preferable for now.

Comments

drunken monkey’s picture

This should do the trick.

drunken monkey’s picture

Status: Active » Needs review
drunken monkey’s picture

Category: bug » feature
drunken monkey’s picture

This also removes the now unnecessary |COMPLEX| hack for complex queries. (See #2013609: Change the workflow of the module's tests).

drunken monkey’s picture

(For context: this issue was born in #1863672-14: Multiple content in the search result, when using multiple terms to filtering onwards. Continuing the discussion related to this test module here now.)

I don't know why the load is not called, and I don't understand if that search_api_test_load is an implementation of https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hoo... or not as the signature is different and the behaviour is not what the hook_load expects.

It's no hook implementation, no, it's just a custom loading function. However, the Search API usually loads with entity_load() (since it has to work on a generic level), therefore the changes in that function would only affect the testing module itself, which uses the function in several places.
I therefore think it's safe to remove the special keywords code in that place.
Sorry, just figured this out myself, otherwise I wouldn't have asked.

And I agree that we should probably better serialize/unserialize the keywords property, or maybe we should serialize the whole entity using a simple 2 column table with id+data where data is the serialization of the whole entity: this way we have better control on how we want an entity to be built.

I don't think that's necessary, solving it this way should suffice. I don't think we'll have to add/change properties in the future, or at least only rarely, and doing this would just make the code more complicated (I'd think).

BTW: All of this stuff is about the search_api_test.module: should we move part of this discussion to search_api issue queue or should we move/copy the test module to the search_api_db module? You are the owner of both project, so it should be an easy agreement ;-)

Yes, you're right, let's discuss it in here.
Moving the test module would not be possible, as the Search API tests also heavily rely on it. And though copying would be possible, I think it would lead to unnecessary code duplication. Besides, one of the main reasons (except simple, clean decoupling) for doing this would have been to enable #2013609: Change the workflow of the module's tests to be tested by the test bot and commited right away. However, since it is also blocked by another Search API issue already (which we could work around, but I'd rather fix it cleanly), that's not a valid point anymore.

drunken monkey’s picture

Revised patch which also allows NULL values for all fields (except ID).

bago’s picture

+1 for me. I see you decided not to use array_filter after the explode (for keywords). Is this intended or you changed your mind since raising that idea in the linked issue? Currently when we put an empty string it's like we have 1 element with an empty value (not sure if this is indexed by the search api or not).

drunken monkey’s picture

+++ b/tests/search_api_test.module
@@ -200,6 +191,20 @@ function search_api_test_parent($entity) {
+  if (is_array($data)) {
+    $res = is_array($data['keywords']) ? $data['keywords'] : explode(',', $data['keywords']);
+  }
+  else {
+    $res = is_array($data->keywords) ? $data->keywords : explode(',', $data->keywords);
+  }
+  return array_filter($res);

I moved the array_filter() to the last line.

bago’s picture

Status: Needs review » Reviewed & tested by the community

LOL, I must be blind!
I just run the tests succesfully.

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

No problem, thanks for testing!
Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.