Skip to content
Snippets Groups Projects
Commit 1696c211 authored by eduardo morales alberti's avatar eduardo morales alberti Committed by Thomas Seidl
Browse files

Issue #3263875 by Eduardo Morales Alberti, drunken monkey, GrumpySchlag: Fixed Behat integration.

parent 6ce3d21e
No related branches found
No related tags found
No related merge requests found
Search API 1.x, dev (xxxx-xx-xx):
---------------------------------
- #3263875 by Eduardo Morales Alberti, drunken monkey, GrumpySchlag: Fixed Behat
integration.
- #3355677 by drunken monkey: Fixed incompatibility with PHP 7.3 in
ConfigurablePropertyBase.
- #3358819 by drunken monkey: Fixed tests against Drupal 10.1.
......
......@@ -6,6 +6,7 @@
*/
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Gherkin\Node\FeatureNode;
use Drupal\DrupalExtension\Context\DrupalSubContextBase;
/**
......@@ -15,6 +16,15 @@ use Drupal\DrupalExtension\Context\DrupalSubContextBase;
*/
class SearchApiSubContext extends DrupalSubContextBase {
/**
* Cached tags lists of features, keyed by feature hash.
*
* @var string[][]
*
* @see \SearchApiSubContext::getTagsFromFeature()
*/
protected static $tags;
/**
* Triggers all queued indexing operations for this page request.
*
......@@ -39,7 +49,7 @@ class SearchApiSubContext extends DrupalSubContextBase {
* @AfterStep
*/
public function indexEntities(AfterStepScope $event) {
$tags = $event->getFeature()->getTags();
$tags = static::getTagsFromFeature($event->getFeature());
if (!in_array('search_api', $tags)) {
return;
}
......@@ -48,4 +58,26 @@ class SearchApiSubContext extends DrupalSubContextBase {
->destruct();
}
/**
* Extracts tags from a feature.
*
* @param \Behat\Gherkin\Node\FeatureNode $feature
* Feature node from which to extract the tags.
*
* @return string[]
* The tags list of the feature.
*/
public static function getTagsFromFeature(FeatureNode $feature): array {
$feature_hash = md5($feature->getFile());
if (!isset(static::$tags[$feature_hash])) {
$tags = [];
foreach ($feature->getScenarios() as $scenario) {
$scenario_tags = $scenario->getTags();
$tags = array_unique(array_merge($tags, $scenario_tags), SORT_REGULAR);
}
static::$tags[$feature_hash] = $tags;
}
return static::$tags[$feature_hash];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment