Skip to content

Commit

Permalink
Merge pull request #454 from humanmade/backport-453-to-v14-branch
Browse files Browse the repository at this point in the history
[Backport v14-branch] Disable WP_Query results cache in tests
  • Loading branch information
kovshenin authored Feb 28, 2023
2 parents 44ab2bf + c19e918 commit 17c409b
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions tests/acceptance/ElasticSearchCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
class ElasticSearchCest {

/**
* Disable cavalcade for all tests.
* Disable Cavalcade and query caching for all tests.
*
* @param AcceptanceTester $I Actor object.
* @return void
*/
public function _before( AcceptanceTester $I ) {
$I->bootstrapWith( [ __CLASS__, '_disableCavalcade' ] );
$I->bootstrapWith( [ __CLASS__, '_defaultBootstrap' ] );
}

/**
Expand Down Expand Up @@ -332,13 +332,24 @@ public function testAutosuggestDropdown( AcceptanceTester $I, Scenario $scenario
$rollback();
}

/**
* Default bootstrap method for all tests.
*
* @return void
*/
public static function _defaultBootstrap() {
self::_disableCavalcade();
self::_disableQueryCache();
}

/**
* Bootstraps the Altis config with advanced search mode.
*
* @return void
*/
public static function _setAdvancedMode() {
self::_disableCavalcade();
self::_defaultBootstrap();

add_filter( 'altis.config', function ( array $config ) : array {
$config['modules']['search']['mode'] = 'advanced';
return $config;
Expand All @@ -358,16 +369,28 @@ public static function _disableCavalcade() {
} );
}

/**
* Disable internal WP_Query results caching.
*
* @return void
*/
public static function _disableQueryCache() {
add_action( 'pre_get_posts', function( $query ) {
$query->query_vars['cache_results'] = false;
} );
}

/**
* Bootstraps the Altis config with autosuggest on.
*
* @return void
*/
public static function _setAutosuggestOn() {
self::_defaultBootstrap();

add_filter( 'altis.config', function ( array $config ) : array {
$config['modules']['search']['autosuggest'] = true;
return $config;
} );
}

}

0 comments on commit 17c409b

Please sign in to comment.