Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Nov 26, 2024
1 parent a58a8b9 commit f0581f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
8 changes: 4 additions & 4 deletions includes/classes/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -1730,14 +1730,14 @@ public function add_elasticpress_version_to_user_agent( $user_agent ) {
* Query logging. Don't log anything to the queries property when
* WP_DEBUG is not enabled. Calls action 'ep_add_query_log' if you
* want to access the query outside of the ElasticPress plugin. This
* runs regardless of debufg settings.
* runs regardless of debug settings.
*
* @param array $query Query to log.
*/
protected function add_query_log( $query ) {
$wp_debug = defined( 'WP_DEBUG' ) && WP_DEBUG;
$wp_ep_debug = defined( 'WP_EP_DEBUG' ) && WP_EP_DEBUG;
$wp_debug = defined( 'WP_DEBUG' ) && WP_DEBUG;
$wp_ep_debug = defined( 'WP_EP_DEBUG' ) && WP_EP_DEBUG;

/**
* Filter query logging. Don't log anything to the queries property when true.
*
Expand Down
31 changes: 31 additions & 0 deletions tests/php/TestElasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,35 @@ public function testGetIndicesComparison() {
];
$this->assertEqualsCanonicalizing( $expected, \ElasticPress\Elasticsearch::factory()->get_indices_comparison() );
}

/**
* Test the ep_disable_query_logging filter
*
* @since 5.2.0
* @group elasticsearch
*/
public function testEpDisableQueryLoggingFilter() {
$elasticsearch = new \ElasticPress\Elasticsearch();

$reflection = new \ReflectionClass( $elasticsearch );
$property = $reflection->getProperty( 'queries' );
$property->setAccessible( true );
$method = $reflection->getMethod( 'add_query_log' );
$method->setAccessible( true );

$example_query = [ 'example_query' ];

add_filter( 'ep_disable_query_logging', '__return_true' );

$method->invokeArgs( $elasticsearch, [ $example_query ] );
$this->assertEmpty( $property->getValue( $elasticsearch ) );

remove_filter( 'ep_disable_query_logging', '__return_true' );

$method->invokeArgs( $elasticsearch, [ $example_query ] );

$queries = $property->getValue( $elasticsearch );
$this->assertCount( 1, $queries );
$this->assertSame( $example_query, $queries[0] );
}
}

0 comments on commit f0581f8

Please sign in to comment.