diff --git a/MIGRATION.md b/MIGRATION.md index 7fcfc68..2620b99 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -20,6 +20,10 @@ A migration map of the step definitions available in v2 to v3. | `Then I :can visit :path with HTTP credentials :user :pass` | `Given the basic authentication with the username :username and the password :password` | | `When I visit :path then the final URL should be :alias` | Removed. Use `When I visit :path` and `Then the path should be :path` | |   | | +| **[`SearchApiTrait`](src/SearchApiTrait.php) ([example](tests/behat/features/search.feature))** | | +| `When I index :type :title for search` | `When I add the :content_type content with the title :title to the search index` | +| `When I index :limit Search API items` | `When I run search indexing for :count item(s)` | +|   | | | **[`WaitTrait`](src/WaitTrait.php) ([example](tests/behat/features/wait.feature))** | | | `Then /^(?:\|I )wait (\d+) second(s?)$/` | `When I wait for :number second(s)` | | `Given I wait :timeout seconds for AJAX to finish` | `When I wait for :number second(s) for AJAX to finish` | diff --git a/README.md b/README.md index f747e62..c8693c8 100644 --- a/README.md +++ b/README.md @@ -207,8 +207,8 @@ For migration from v2 to v3, see [MIGRATION.md](MIGRATION.md). | `Then /^the option "([^"]*)" from select "([^"]*)" is selected$/` | Assert that the specified option is selected in the specified select element. | |   | | | **[`SearchApiTrait`](src/SearchApiTrait.php) ([example](tests/behat/features/search.feature))** | | -| `When I index :type :title for search` | Index a node with all Search API indices. | -| `When I index :limit Search API items` | Index a specified number of items across all active Search API indices. | +| `When I add the :content_type content with the title :title to the search index` | Index a node with all Search API indices. | +| `When I run search indexing for :count item(s)` | Index a specified number of items across all active Search API indices. | |   | | | **[`TaxonomyTrait`](src/TaxonomyTrait.php) ([example](tests/behat/features/taxonomy.feature))** | | | `Given vocabulary :vid with name :name exists` | Assert that the specified vocabulary exists. | diff --git a/src/SearchApiTrait.php b/src/SearchApiTrait.php index 442f822..c05d72e 100644 --- a/src/SearchApiTrait.php +++ b/src/SearchApiTrait.php @@ -20,9 +20,9 @@ trait SearchApiTrait { use ContentTrait; /** - * Index a node with all Search API indices. + * Index a node of a specific content type with a specific title. * - * @When I index :type :title for search + * @When I add the :content_type content with the title :title to the search index */ public function searchApiIndexContent(string $type, string $title): void { $nids = $this->contentLoadMultiple($type, [ @@ -43,18 +43,20 @@ public function searchApiIndexContent(string $type, string $title): void { } /** - * Index a number of items across all active Search API indices. + * Run indexing for a specific number of items. * - * @When I index :limit Search API items - * @When I index 1 Search API item + * @When I run search indexing for :count item(s) */ - public function searchApiDoIndex(string|int $limit = 1): void { + public function searchApiDoIndex(string|int $limit): void { $limit = intval($limit); + $index_storage = \Drupal::entityTypeManager()->getStorage('search_api_index'); + /** @var \Drupal\search_api\IndexInterface[] $indexes */ $indexes = $index_storage->loadByProperties(['status' => TRUE]); - if (!$indexes) { - return; + + if (empty($indexes)) { + throw new \RuntimeException('No active search indexes found'); } foreach ($indexes as $index) { diff --git a/tests/behat/features/search.feature b/tests/behat/features/search.feature index c68a532..3370fbd 100644 --- a/tests/behat/features/search.feature +++ b/tests/behat/features/search.feature @@ -2,7 +2,7 @@ Feature: Ensure Search works. @api - Scenario: Assert "I index :type :title for search" works as expected + Scenario: Assert "When I add the :content_type content with the title :title to the search index" works as expected Given article content: | title | moderation_state | | [MYTEST] TESTPUBLISHEDARTICLE TESTUNIQUETEXT | published | @@ -17,8 +17,8 @@ Feature: Ensure Search works. And I should not see the text "[MYTEST] TESTDRAFTARTICLE TESTUNIQUETEXT" # Index nodes and preform another search. - When I index article "[MYTEST] TESTPUBLISHEDARTICLE TESTUNIQUETEXT" for search - And I index article "[MYTEST] TESTDRAFTARTICLE TESTUNIQUETEXT" for search + When I add the "article" content with the title "[MYTEST] TESTPUBLISHEDARTICLE TESTUNIQUETEXT" to the search index + And I add the "article" content with the title "[MYTEST] TESTDRAFTARTICLE TESTUNIQUETEXT" to the search index # Perform another search. When I go to "/search" @@ -30,14 +30,14 @@ Feature: Ensure Search works. Then I should not see the text "[MYTEST] TESTDRAFTARTICLE TESTUNIQUETEXT" @api @testmode - Scenario: Assert that testmode correctly works with search + Scenario: Assert "When I add the :content_type content with the title :title to the search index" works as expected with test mode Given article content: | title | moderation_state | | TESTPUBLISHEDARTICLE 1 | published | | [MYTEST] TESTPUBLISHEDARTICLE 2 | published | And I am logged in as a user with the "administrator" role - And I index article "TESTPUBLISHEDARTICLE 1" for search - And I index article "[MYTEST] TESTPUBLISHEDARTICLE 2" for search + When I add the "article" content with the title "TESTPUBLISHEDARTICLE 1" to the search index + And I add the "article" content with the title "[MYTEST] TESTPUBLISHEDARTICLE 2" to the search index When I go to "/search" And I fill in "edit-search-api-fulltext" with "TESTPUBLISHEDARTICLE"