Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary remove_filters from the unit tests #3220

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions tests/php/TestAdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ public function testEsAboveCompatNoticeInAdmin() {

$notices = ElasticPress\AdminNotices::factory()->get_notices();

remove_filter( 'ep_elasticsearch_version', $es_version );

$this->assertEquals( 1, count( $notices ) );
$this->assertTrue( ! empty( $notices['es_above_compat'] ) );
}
Expand Down Expand Up @@ -338,8 +336,6 @@ public function testEsBelowCompatNoticeInAdmin() {

$notices = ElasticPress\AdminNotices::factory()->get_notices();

remove_filter( 'ep_elasticsearch_version', $es_version );

$this->assertEquals( 1, count( $notices ) );
$this->assertTrue( ! empty( $notices['es_below_compat'] ) );
}
Expand Down
1 change: 0 additions & 1 deletion tests/php/TestCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function set_up() {
ElasticPress\Indexables::factory()->get( 'post' )->put_mapping();
ElasticPress\Elasticsearch::factory()->refresh_indices();

delete_option( 'ep_active_features' );
parent::set_up();
}

Expand Down
2 changes: 0 additions & 2 deletions tests/php/TestFeatureActivation.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function set_up() {
public function tear_down() {
parent::tear_down();

// make sure no one attached to this
remove_filter( 'ep_sync_terms_allow_hierarchy', array( $this, 'ep_allow_multiple_level_terms_sync' ), 100 );
$this->fired_actions = array();
}

Expand Down
2 changes: 0 additions & 2 deletions tests/php/TestInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ public function testCalculateInstallStatusNoHost() {
$install_status = ElasticPress\Installer::factory()->get_install_status();

$this->assertEquals( 2, $install_status );

remove_all_filters( 'ep_host' );
}

/**
Expand Down
16 changes: 0 additions & 16 deletions tests/php/TestScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public function testDetermineScreenSettingsInstallTrue() {
ElasticPress\Screen::factory()->determine_screen();

$this->assertEquals( 'settings', ElasticPress\Screen::factory()->get_current_screen() );

remove_filter( 'ep_install_status', $set_install_status );
}

/**
Expand All @@ -139,8 +137,6 @@ public function testDetermineScreenSettingsInstall1() {
ElasticPress\Screen::factory()->determine_screen();

$this->assertEquals( 'install', ElasticPress\Screen::factory()->get_current_screen() );

remove_filter( 'ep_install_status', $set_install_status );
}

/**
Expand All @@ -162,8 +158,6 @@ public function testDetermineScreenSettingsInstall2() {
ElasticPress\Screen::factory()->determine_screen();

$this->assertEquals( 'settings', ElasticPress\Screen::factory()->get_current_screen() );

remove_filter( 'ep_install_status', $set_install_status );
}

/**
Expand All @@ -185,8 +179,6 @@ public function testDetermineScreenDashboardInstallTrue() {
ElasticPress\Screen::factory()->determine_screen();

$this->assertEquals( 'dashboard', ElasticPress\Screen::factory()->get_current_screen() );

remove_filter( 'ep_install_status', $set_install_status );
}

/**
Expand All @@ -208,8 +200,6 @@ public function testDetermineScreenDashboardInstall1() {
ElasticPress\Screen::factory()->determine_screen();

$this->assertEquals( 'install', ElasticPress\Screen::factory()->get_current_screen() );

remove_filter( 'ep_install_status', $set_install_status );
}

/**
Expand All @@ -231,8 +221,6 @@ public function testDetermineScreenDashboardInstall2() {
ElasticPress\Screen::factory()->determine_screen();

$this->assertEquals( 'install', ElasticPress\Screen::factory()->get_current_screen() );

remove_filter( 'ep_install_status', $set_install_status );
}

/**
Expand All @@ -255,8 +243,6 @@ public function testDetermineScreenDashboardInstallComplete() {
ElasticPress\Screen::factory()->determine_screen();

$this->assertEquals( 'install', ElasticPress\Screen::factory()->get_current_screen() );

remove_filter( 'ep_install_status', $set_install_status );
}

/**
Expand All @@ -279,7 +265,5 @@ public function testDetermineScreenDashboardInstall3DoSync() {
ElasticPress\Screen::factory()->determine_screen();

$this->assertEquals( 'dashboard', ElasticPress\Screen::factory()->get_current_screen() );

remove_filter( 'ep_install_status', $set_install_status );
}
}
4 changes: 0 additions & 4 deletions tests/php/TestSearchAlgorithm.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function testFilters() {

$query = $this->stub->get_query( 'indexable', '', [], [] );
$this->assertEquals( [ 'changed' ], $query );

remove_filter( 'ep_indexable_formatted_args_query', $test_filter );
}

/**
Expand All @@ -72,7 +70,5 @@ public function testLegacyFilters() {

$query = $this->stub->get_query( 'post', '', [], [] );
$this->assertEquals( [ 'changed' ], $query );

remove_filter( 'ep_formatted_args_query', $test_filter );
}
}
20 changes: 0 additions & 20 deletions tests/php/features/TestAutosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function set_up() {
$this->setup_test_post_type();

set_current_screen( 'front' );

delete_option( 'ep_active_features' );
}

/**
Expand Down Expand Up @@ -111,8 +109,6 @@ public function testMappingES5() {
$this->assertArrayHasKey( 'type', $mapping['mappings']['post']['properties']['post_title']['fields']['suggest'] );
$this->assertArrayHasKey( 'analyzer', $mapping['mappings']['post']['properties']['post_title']['fields']['suggest'] );
$this->assertArrayHasKey( 'search_analyzer', $mapping['mappings']['post']['properties']['post_title']['fields']['suggest'] );

remove_filter( 'ep_elasticsearch_version', $change_es_version );
}

public function testMappingES7() {
Expand All @@ -132,8 +128,6 @@ public function testMappingES7() {
$this->assertArrayHasKey( 'type', $mapping['mappings']['properties']['post_title']['fields']['suggest'] );
$this->assertArrayHasKey( 'analyzer', $mapping['mappings']['properties']['post_title']['fields']['suggest'] );
$this->assertArrayHasKey( 'search_analyzer', $mapping['mappings']['properties']['post_title']['fields']['suggest'] );

remove_filter( 'ep_elasticsearch_version', $change_es_version );
}

public function testSetFuzziness() {
Expand Down Expand Up @@ -182,9 +176,6 @@ public function testEnqueueScripts() {

$this->get_feature()->enqueue_scripts();
$this->assertTrue( wp_script_is( 'elasticpress-autosuggest' ) );

remove_filter( 'pre_site_option_ep_feature_settings', $filter );
remove_filter( 'pre_option_ep_feature_settings', $filter );
}

public function testGenerateSearchQuery() {
Expand All @@ -208,8 +199,6 @@ public function testGenerateSearchQueryFilters() {
$query = $this->get_feature()->generate_search_query();
$this->assertStringContainsString( 'lorem-ipsum', $query['body'] );

remove_filter( 'ep_autosuggest_query_placeholder', $test_placeholder_filter );

/**
* Test the `ep_autosuggest_query_placeholder` filter.
*/
Expand All @@ -221,9 +210,6 @@ public function testGenerateSearchQueryFilters() {

$query = $this->get_feature()->generate_search_query();
$this->assertStringContainsString( 'my-custom-post-type', $query['body'] );

remove_filter( 'ep_term_suggest_post_type', $test_post_type_filter );

/**
* Test the `ep_term_suggest_post_status` filter.
*/
Expand All @@ -236,8 +222,6 @@ public function testGenerateSearchQueryFilters() {
$query = $this->get_feature()->generate_search_query();
$this->assertStringContainsString( 'trash', $query['body'] );

remove_filter( 'ep_term_suggest_post_status', $test_post_status_filter );

/**
* Test the `ep_term_suggest_post_status` filter.
*/
Expand All @@ -250,8 +234,6 @@ public function testGenerateSearchQueryFilters() {

$query = $this->get_feature()->generate_search_query();
$this->assertStringContainsString( '1234', $query['body'] );

remove_filter( 'ep_autosuggest_query_args', $test_args_filter );
}

public function testReturnEmptyPosts() {
Expand All @@ -269,8 +251,6 @@ public function testApplyAutosuggestWeighting() {

$this->assertArrayHasKey( 'hello', $this->get_feature()->apply_autosuggest_weighting( [] ) );
$this->assertContains( 'world', $this->get_feature()->apply_autosuggest_weighting( [] ) );

remove_filter( 'ep_weighting_configuration_for_autosuggest', $filter );
}

public function testRequirementsStatus() {
Expand Down
4 changes: 0 additions & 4 deletions tests/php/features/TestComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public function set_up() {
$this->setup_test_post_type();

set_current_screen( 'front' );

delete_option( 'ep_active_features' );
}

/**
Expand All @@ -54,8 +52,6 @@ public function tear_down() {

set_current_screen();

// make sure no one attached to this
remove_filter( 'ep_sync_terms_allow_hierarchy', array( $this, 'ep_allow_multiple_level_terms_sync' ), 100 );
$this->fired_actions = array();
}

Expand Down
4 changes: 0 additions & 4 deletions tests/php/features/TestDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function set_up() {
$this->setup_test_post_type();

set_current_screen( 'front' );

delete_option( 'ep_active_features' );
}

/**
Expand All @@ -53,8 +51,6 @@ public function tear_down() {

set_current_screen();

// make sure no one attached to this
remove_filter( 'ep_sync_terms_allow_hierarchy', array( $this, 'ep_allow_multiple_level_terms_sync' ), 100 );
$this->fired_actions = array();
}

Expand Down
2 changes: 0 additions & 2 deletions tests/php/features/TestFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function testFacetTypeRegistration() {
$facets->types['test_custom'] = $facet_type;

$facets->setup();

remove_filter( 'ep_facet_types', $register_facet_type );
}

/**
Expand Down
10 changes: 0 additions & 10 deletions tests/php/features/TestFacetTypeMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function testGetFilterName() {
};
add_filter( 'ep_facet_meta_filter_name', $change_filter_name );
$this->assertEquals( 'ep_meta_filter__', $facet_type->get_filter_name() );
remove_filter( 'ep_facet_meta_filter_name', $change_filter_name );
}

/**
Expand All @@ -81,7 +80,6 @@ public function testGetFilterType() {
};
add_filter( 'ep_facet_meta_filter_type', $change_filter_type );
$this->assertEquals( 'meta_', $facet_type->get_filter_type() );
remove_filter( 'ep_facet_meta_filter_type', $change_filter_type );
}

/**
Expand Down Expand Up @@ -139,10 +137,6 @@ public function testSetWpQueryAggs() {
$with_aggs = $facet_type->set_wp_query_aggs( [] );
$this->assertSame( 5, $with_aggs['ep_meta_filter_new_meta_key_1']['terms']['size'] );
$this->assertSame( 10000, $with_aggs['ep_meta_filter_new_meta_key_2']['terms']['size'] );

remove_filter( 'ep_facet_meta_size', $change_meta_bucket_size );

remove_filter( 'ep_facet_meta_fields', $set_facet_meta_field );
}

/**
Expand Down Expand Up @@ -206,8 +200,6 @@ public function testGetMetaValues() {

$this->assertEqualsCanonicalizing( [ 'foo', 'bar', 'foobar' ], $meta_values_1 );
$this->assertEqualsCanonicalizing( [ 'lore', 'ipsu' ], $meta_values_2 );

remove_filter( 'ep_facet_meta_custom_meta_values', $change_meta_values );
}

/**
Expand Down Expand Up @@ -319,7 +311,5 @@ public function testGetSanitizeCallback() {
// test sanitize_text_field runs when filter is applied.
$expected_result = sanitize_title( $test_meta );
$this->assertArrayHasKey( $expected_result, $selected['meta']['new_meta_key_1']['terms'] );

remove_filter( 'ep_facet_default_sanitize_callback', $sanitize_function );
}
}
2 changes: 0 additions & 2 deletions tests/php/features/TestFacetTypeMetaRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,5 @@ public function testGetMetaValueHtml() {
add_filter( 'ep_facet_meta_value_html', $change_html, 10, 3 );

$this->assertEquals( '<p>Completely custom made element</p>', $renderer->get_meta_value_html( $value, $url ) );

remove_filter( 'ep_facet_meta_value_html', $change_html );
}
}
8 changes: 0 additions & 8 deletions tests/php/features/TestFacetTypeTaxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function testGetFilterName() {
};
add_filter( 'ep_facet_filter_name', $change_filter_name );
$this->assertEquals( 'ep_filter__', $facet_type->get_filter_name() );
remove_filter( 'ep_facet_filter_name', $change_filter_name );
}

/**
Expand All @@ -63,7 +62,6 @@ public function testGetFilterType() {
};
add_filter( 'ep_facet_filter_type', $change_filter_type );
$this->assertEquals( 'taxonomies_', $facet_type->get_filter_type() );
remove_filter( 'ep_facet_filter_type', $change_filter_type );
}

/**
Expand Down Expand Up @@ -96,8 +94,6 @@ public function testGetFacetableTaxonomies() {

$facetable_taxonomies = array_keys( $facet_type->get_facetable_taxonomies() );
$this->assertNotContains( 'category', $facetable_taxonomies );

remove_filter( 'ep_facet_include_taxonomies', $change_facetable_taxonomies );
}

/**
Expand Down Expand Up @@ -150,8 +146,6 @@ public function testSetWpQueryAggs() {
$with_aggs = $facet_type->set_wp_query_aggs( [] );
$this->assertSame( 5, $with_aggs['category']['terms']['size'] );
$this->assertSame( 10000, $with_aggs['post_tag']['terms']['size'] );

remove_filter( 'ep_facet_taxonomies_size', $change_tax_bucket_size );
}

/**
Expand Down Expand Up @@ -233,7 +227,5 @@ public function testGetSanitizeCallback() {
// test sanitize_text_field runs when filter is applied.
$expected_result = sanitize_text_field( $test_taxonomy );
$this->assertArrayHasKey( $expected_result, $selected['taxonomies']['taxonomy']['terms'] );

remove_filter( 'ep_facet_sanitize_callback', $sanitize_function );
}
}
4 changes: 0 additions & 4 deletions tests/php/features/TestProtectedContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function set_up() {
ElasticPress\Indexables::factory()->get( 'post' )->sync_manager->sync_queue = [];

$this->setup_test_post_type();

delete_option( 'ep_active_features' );
}

/**
Expand All @@ -48,8 +46,6 @@ public function set_up() {
public function tear_down() {
parent::tear_down();

// make sure no one attached to this
remove_filter( 'ep_sync_terms_allow_hierarchy', array( $this, 'ep_allow_multiple_level_terms_sync' ), 100 );
$this->fired_actions = array();

set_current_screen( 'front' );
Expand Down
6 changes: 0 additions & 6 deletions tests/php/features/TestRelatedPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function set_up() {
ElasticPress\Indexables::factory()->get( 'post' )->sync_manager->sync_queue = [];

$this->setup_test_post_type();

delete_option( 'ep_active_features' );
}

/**
Expand All @@ -47,8 +45,6 @@ public function set_up() {
public function tear_down() {
parent::tear_down();

// make sure no one attached to this
remove_filter( 'ep_sync_terms_allow_hierarchy', array( $this, 'ep_allow_multiple_level_terms_sync' ), 100 );
$this->fired_actions = array();
}

Expand Down Expand Up @@ -95,8 +91,6 @@ public function testFindRelatedPostFilter() {
$related = ElasticPress\Features::factory()->get_registered_feature( 'related_posts' )->find_related( $post_id, 1 );
$this->assertEquals( 1, count( $related ) );
$this->assertTrue( isset( $related[0] ) && isset( $related[0]->elasticsearch ) );

remove_filter( 'ep_find_related_args', array( $this, 'find_related_posts_filter' ), 10, 1 );
}

/**
Expand Down
Loading