From e26dd6908602f5b6f5b455a229148041057cba59 Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Tue, 31 Aug 2021 15:07:24 -0600 Subject: [PATCH 01/14] CLI: Fix typo in output for words 'stoping' and 'occuring' --- includes/classes/Command.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/Command.php b/includes/classes/Command.php index ef44c097d0..981b348927 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -1266,7 +1266,7 @@ private function index_occurring() { } if ( $dashboard_syncing || $wpcli_syncing ) { - WP_CLI::error( esc_html__( 'An index is already occuring. Try again later.', 'elasticpress' ) ); + WP_CLI::error( esc_html__( 'An index is already occurring. Try again later.', 'elasticpress' ) ); } } @@ -1288,7 +1288,7 @@ private function reset_transient( $items_indexed, $total_items, $slug ) { } /** - * Delete transient that indicates indexing is occuring + * Delete transient that indicates indexing is occurring * * @since 3.1 */ @@ -1483,7 +1483,7 @@ public function stop_indexing( $args, $assoc_args ) { if ( empty( \ElasticPress\Utils\get_indexing_status() ) ) { WP_CLI::warning( esc_html__( 'There is no indexing operation running.', 'elasticpress' ) ); } else { - WP_CLI::line( esc_html__( 'Stoping indexing...', 'elasticpress' ) ); + WP_CLI::line( esc_html__( 'Stopping indexing...', 'elasticpress' ) ); if ( isset( $indexing_status['method'] ) && 'cli' === $indexing_status['method'] ) { set_transient( 'ep_wpcli_sync_interrupted', true, 5 ); From 0d0d1952f9927bc0a75914358cb15eece9c4274d Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Fri, 10 Sep 2021 12:59:37 -0300 Subject: [PATCH 02/14] Terms: Use $query_vars['parent'] even when equals 0 --- includes/classes/Indexable/Term/Term.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Indexable/Term/Term.php b/includes/classes/Indexable/Term/Term.php index a84fc0a48c..4f7618733c 100644 --- a/includes/classes/Indexable/Term/Term.php +++ b/includes/classes/Indexable/Term/Term.php @@ -424,7 +424,7 @@ public function format_args( $query_vars ) { /** * Support `parent` query var. */ - if ( ! empty( $query_vars['parent'] ) ) { + if ( isset( $query_vars['parent'] ) ) { $filter['bool']['must'][]['bool']['must'] = [ 'term' => [ 'parent' => (int) $query_vars['parent'], From eff11de62aef819e231a2f6f782e34e7da419662 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Fri, 10 Sep 2021 13:40:35 -0300 Subject: [PATCH 03/14] Terms: add unit test for 'parent' --- tests/php/indexables/TestTerm.php | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/php/indexables/TestTerm.php b/tests/php/indexables/TestTerm.php index 4618918ee8..9d66881fec 100644 --- a/tests/php/indexables/TestTerm.php +++ b/tests/php/indexables/TestTerm.php @@ -656,6 +656,43 @@ public function testTermQueryOrderParent() { $this->assertTrue( $term_query->terms[0]->term_id > $term_query->terms[ count( $term_query->terms ) - 1 ]->term_id ); } + /** + * Test a term query parent + * + * @since 3.6.3 + * @group term + */ + public function testTermQueryParent() { + $parent_term_id = Functions\create_and_sync_term( 'parent-term-no-post', 'Parent Category', 'Parent/Child Terms', 'category' ); + $child_term_id = Functions\create_and_sync_term( 'child-term-post', 'Child Category', 'Parent/Child Terms', 'category', [], $parent_term_id ); + + $term_query = new \WP_Term_Query( + [ + 'hide_empty' => false, + 'taxonomy' => 'category', + 'parent' => $parent_term_id, + 'ep_integrate' => true, + ] + ); + + $this->assertTrue( $term_query->elasticsearch_success ); + $this->assertCount( 1, $term_query->terms ); + $this->assertSame( $term_query->terms[0]->term_id, $child_term_id ); + + $term_query = new \WP_Term_Query( + [ + 'hide_empty' => false, + 'taxonomy' => 'category', + 'parent' => 0, + 'ep_integrate' => true, + ] + ); + + $this->assertTrue( $term_query->elasticsearch_success ); + $this->assertCount( 2, $term_query->terms ); // "Uncategorized" is also returned in this case. + $this->assertContains( $parent_term_id, wp_list_pluck( $term_query->terms, 'term_id' ) ); + } + /** * Test a term query hide_empty * From d4e66ab7b7c775de81ab0e1a6611a5135f46a326 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Fri, 10 Sep 2021 13:53:13 -0300 Subject: [PATCH 04/14] Don't use $query_vars['parent'] if it is an empty string --- includes/classes/Indexable/Term/Term.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Indexable/Term/Term.php b/includes/classes/Indexable/Term/Term.php index 4f7618733c..23d10d133c 100644 --- a/includes/classes/Indexable/Term/Term.php +++ b/includes/classes/Indexable/Term/Term.php @@ -424,7 +424,7 @@ public function format_args( $query_vars ) { /** * Support `parent` query var. */ - if ( isset( $query_vars['parent'] ) ) { + if ( isset( $query_vars['parent'] ) && '' !== $query_vars['parent'] ) { $filter['bool']['must'][]['bool']['must'] = [ 'term' => [ 'parent' => (int) $query_vars['parent'], From d37e3841f3f1280ab8b12e145b97abb7f8032594 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 13 Sep 2021 11:20:43 -0300 Subject: [PATCH 05/14] Move existing mapping determination to a function and change checks --- includes/classes/Indexable/Post/Post.php | 128 ++++++++++++++--------- 1 file changed, 76 insertions(+), 52 deletions(-) diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index d1463c81a1..49c5fc5b6b 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -288,58 +288,7 @@ public function determine_mapping_version() { return false; } - $version = 'unknown'; - - if ( isset( $mapping[ $index ]['mappings']['post']['_meta']['mapping_version'] ) ) { - $version = $mapping[ $index ]['mappings']['post']['_meta']['mapping_version']; - } elseif ( isset( $mapping[ $index ]['mappings']['_meta']['mapping_version'] ) ) { - $version = $mapping[ $index ]['mappings']['_meta']['mapping_version']; - } - - // mapping does not have meta value set - use legacy detection - if ( 'unknown' === $version ) { - - // check for pre-5-0 mapping - if ( isset( $mapping[ $index ]['mappings']['post']['properties']['post_name']['fields']['raw']['ignore_above'] ) ) { - $val = $mapping[ $index ]['mappings']['post']['properties']['post_name']['fields']['raw']['ignore_above']; - if ( ! $val || 10922 !== $val ) { - $version = 'pre-5-0.php'; - } elseif ( $val && 10922 === $val ) { - $version = 'not-pre-5-0'; - } - } - - // check for 5-0 mapping - if ( 'not-pre-5-0' === $version ) { - if ( isset( $mapping[ $index ]['mappings']['post']['properties']['post_content_filtered']['fields'] ) ) { - $version = '5-0.php'; - } else { - $version = 'not-5-0'; - } - } - - // check for 5-2 mapping - if ( 'not-5-0' === $version ) { - if ( isset( $mapping[ $index ]['mappings']['post']['_all'] ) ) { - $version = '5-2.php'; - } else { - $version = 'not-5-2'; - } - } - - // check for 7-0 mapping - if ( 'not-5-2' === $version ) { - if ( isset( $mapping[ $index ]['settings']['index.max_shingle_diff'] ) ) { - $version = '7-0.php'; - } else { - $version = 'not-7-0'; - } - } - - if ( preg_match( '/^not-.*/', $version ) ) { - $version = 'unknown'; - } - } + $version = $this->determine_mapping_version_based_on_existing( $mapping, $index ); /** * Filter the mapping version for posts. @@ -2006,4 +1955,79 @@ protected function get_orderby_array( $orderbys ) { return $orderbys; } + + /** + * Given a mapping content, try to determine the version used. + * + * @since 3.6.3 + * + * @param array $mapping Mapping content. + * @param string $index Index name + * @return string Version of the mapping being used. + */ + protected function determine_mapping_version_based_on_existing( $mapping, $index ) { + if ( isset( $mapping[ $index ]['mappings']['post']['_meta']['mapping_version'] ) ) { + return $mapping[ $index ]['mappings']['post']['_meta']['mapping_version']; + } + if ( isset( $mapping[ $index ]['mappings']['_meta']['mapping_version'] ) ) { + return $mapping[ $index ]['mappings']['_meta']['mapping_version']; + } + + /** + * Check for 7-0 mapping. + * If mapping has a `post` type, it can't be ES 7, as mapping types were removed in that release. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html + */ + if ( ! isset( $mapping[ $index ]['mappings']['post'] ) ) { + return '7-0.php'; + } + + $post_mapping = $mapping[ $index ]['mappings']['post']; + + /** + * Starting at this point, our tests rely on the post_title.fields.sortable field. + * As this field is present in all our mappings, if this field is not present in + * the mapping, this is a custom mapping. + * + * To have this code working with custom mappings, use the `ep_post_mapping_version_determined` filter. + */ + if ( ! isset( $post_mapping['properties']['post_title']['fields']['sortable'] ) ) { + return 'unknown'; + } + + $post_title_sortable = $post_mapping['properties']['post_title']['fields']['sortable']; + + /** + * Check for 5-2 mapping. + * Normalizers on keyword fields were only made available in ES 5.2 + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.2/release-notes-5.2.0.html + */ + if ( isset( $post_title_sortable['normalizer'] ) ) { + return '5-2.php'; + } + + /** + * Check for 5-0 mapping. + * `keyword` fields were only made available in ES 5.0 + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.0/release-notes-5.0.0.html + */ + if ( 'keyword' === $post_title_sortable['type'] ) { + return '5-0.php'; + } + + /** + * Check for pre-5-0 mapping. + * `string` fields were deprecated in ES 5.0 in favor of text/keyword + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.0/release-notes-5.0.0.html + */ + if ( 'string' === $post_title_sortable['type'] ) { + return 'pre-5-0.php'; + } + + return 'unknown'; + } } From a7814f9ceb259efbf1fed6cde6c8a9e2fd921075 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 14 Sep 2021 10:59:51 -0300 Subject: [PATCH 06/14] Autosuggest: Major rewrite of adjust_fuzzy_fields --- .../Feature/Autosuggest/Autosuggest.php | 148 ++++++++++++------ 1 file changed, 104 insertions(+), 44 deletions(-) diff --git a/includes/classes/Feature/Autosuggest/Autosuggest.php b/includes/classes/Feature/Autosuggest/Autosuggest.php index 9199fd70e1..2e3ad71394 100644 --- a/includes/classes/Feature/Autosuggest/Autosuggest.php +++ b/includes/classes/Feature/Autosuggest/Autosuggest.php @@ -237,57 +237,117 @@ public function set_fuzziness( $fuzziness, $search_fields, $args ) { * @return array $query adjusted ES Query arguments */ public function adjust_fuzzy_fields( $query, $post_type, $args ) { - if ( Utils\is_integrated_request( $this->slug, [ 'public' ] ) && ! empty( $args['s'] ) ) { - /** - * Filter autosuggest ngram fields - * - * @hook ep_autosuggest_ngram_fields - * @param {array} $fields Fields available to ngram - * @return {array} New fields array - */ - $ngram_fields = apply_filters( - 'ep_autosuggest_ngram_fields', - [ - 'post_title' => 'post_title.suggest', - ] - ); + if ( ! Utils\is_integrated_request( $this->slug, [ 'public' ] ) || empty( $args['s'] ) ) { + return $query; + } - if ( isset( $query['bool'] ) && isset( $query['bool']['must'] ) ) { - foreach ( $query['bool']['must'] as $q_index => $must_query ) { - if ( isset( $must_query['bool'] ) && isset( $must_query['bool']['should'] ) ) { - foreach ( $must_query['bool']['should'] as $index => $current_bool_should ) { - if ( - isset( $current_bool_should['multi_match'] ) && - isset( $current_bool_should['multi_match']['fields'] ) && - ( - ( - isset( $current_bool_should['multi_match']['fuzziness'] ) && - 0 !== $current_bool_should['multi_match']['fuzziness'] - ) || - ( - isset( $current_bool_should['multi_match']['slop'] ) && - 0 !== $current_bool_should['multi_match']['slop'] - ) - ) - ) { - foreach ( $current_bool_should['multi_match']['fields'] as $key => $field ) { - foreach ( $ngram_fields as $plain_field => $ngram_field ) { - if ( preg_match( '/^(' . $plain_field . ')(\^(\d+))?$/', $field, $match ) ) { - if ( isset( $match[3] ) && $match[3] > 1 ) { - $weight = $match[3] - 1; - } else { - $weight = 1; - } - $query['bool']['must'][ $q_index ]['bool']['should'][ $index ]['multi_match']['fields'][] = $ngram_field . '^' . $weight; - } - } - } + if ( ! isset( $query['bool'] ) || ! isset( $query['bool']['must'] ) ) { + return $query; + } + + /** + * Filter autosuggest ngram fields + * + * @hook ep_autosuggest_ngram_fields + * @param {array} $fields Fields available to ngram + * @return {array} New fields array + */ + $ngram_fields = apply_filters( + 'ep_autosuggest_ngram_fields', + [ + 'post_title' => 'post_title.suggest', + 'terms.(.*?).name' => 'term_suggest', + ] + ); + + /** + * At this point, `$query` might look like this (using the 3.5 search algorithm): + * + * [ + * [bool] => [ + * [must] => [ + * [0] => [ + * [bool] => [ + * [should] => [ + * [0] => [ + * [multi_match] => [ + * [query] => ep_autosuggest_placeholder + * [type] => phrase + * [fields] => [ + * [0] => post_title^1 + * ... + * [n] => terms.category.name^27 + * ] + * [boost] => 3 + * ] + * ] + * [1] => [ + * [multi_match] => [ + * [query] => ep_autosuggest_placeholder + * [fields] => [ ... ] + * [type] => phrase + * [slop] => 5 + * ] + * ] + * ] + * ] + * ] + * ] + * ] + * ... + * ] + * + * Also, note the usage of `&$must_query`. This means that by changing `$must_query` + * you will be actually changing `$query`. + */ + foreach ( $query['bool']['must'] as &$must_query ) { + if ( ! isset( $must_query['bool'] ) || ! isset( $must_query['bool']['should'] ) ) { + continue; + } + foreach ( $must_query['bool']['should'] as &$current_bool_should ) { + if ( ! isset( $current_bool_should['multi_match'] ) || ! isset( $current_bool_should['multi_match']['fields'] ) ) { + continue; + } + + /** + * `fuzziness` is used in the original algorithm. + * `slop` is used in `3.5`. + * + * @see \ElasticPress\Indexable\Post\Post::format_args() + */ + if ( empty( $current_bool_should['multi_match']['fuzziness'] ) && empty( $current_bool_should['multi_match']['slop'] ) ) { + continue; + } + + $fields_to_add = []; + + /** + * If the regex used in `$ngram_fields` matches more than one field, + * like taxonomies, for example, we use the min value - 1. + */ + foreach ( $current_bool_should['multi_match']['fields'] as $field ) { + foreach ( $ngram_fields as $regex => $ngram_field ) { + if ( preg_match( '/^(' . $regex . ')(\^(\d+))?$/', $field, $match ) ) { + $weight = 1; + if ( isset( $match[4] ) && $match[4] > 1 ) { + $weight = $match[4] - 1; + } + + if ( isset( $fields_to_add[ $ngram_field ] ) ) { + $fields_to_add[ $ngram_field ] = min( $fields_to_add[ $ngram_field ], $weight ); + } else { + $fields_to_add[ $ngram_field ] = $weight; } } } } + + foreach ( $fields_to_add as $field => $weight ) { + $current_bool_should['multi_match']['fields'][] = "{$field}^{$weight}"; + } } } + return $query; } From c16d07e1b250bfb4cdca5052b3bd9468cd9beaf3 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 14 Sep 2021 12:05:16 -0300 Subject: [PATCH 07/14] Autosuggest: restrict the addition of term_suggest --- includes/classes/Feature/Autosuggest/Autosuggest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/classes/Feature/Autosuggest/Autosuggest.php b/includes/classes/Feature/Autosuggest/Autosuggest.php index 2e3ad71394..c56b750b30 100644 --- a/includes/classes/Feature/Autosuggest/Autosuggest.php +++ b/includes/classes/Feature/Autosuggest/Autosuggest.php @@ -255,8 +255,8 @@ public function adjust_fuzzy_fields( $query, $post_type, $args ) { $ngram_fields = apply_filters( 'ep_autosuggest_ngram_fields', [ - 'post_title' => 'post_title.suggest', - 'terms.(.*?).name' => 'term_suggest', + 'post_title' => 'post_title.suggest', + 'terms.(.+).name' => 'term_suggest', ] ); From 54b55e977270c3b68b8763cb5f289a61911c7481 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 14 Sep 2021 18:03:37 -0300 Subject: [PATCH 08/14] Escape dots in regex --- includes/classes/Feature/Autosuggest/Autosuggest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/classes/Feature/Autosuggest/Autosuggest.php b/includes/classes/Feature/Autosuggest/Autosuggest.php index c56b750b30..544e3e2ad3 100644 --- a/includes/classes/Feature/Autosuggest/Autosuggest.php +++ b/includes/classes/Feature/Autosuggest/Autosuggest.php @@ -255,8 +255,8 @@ public function adjust_fuzzy_fields( $query, $post_type, $args ) { $ngram_fields = apply_filters( 'ep_autosuggest_ngram_fields', [ - 'post_title' => 'post_title.suggest', - 'terms.(.+).name' => 'term_suggest', + 'post_title' => 'post_title.suggest', + 'terms\.(.+)\.name' => 'term_suggest', ] ); From 6b943d261dd49ccf697c3b644af6ffc57d014c87 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 20 Sep 2021 12:46:48 -0300 Subject: [PATCH 09/14] WP Acceptance: Widget screen and "are you sure.." error --- tests/wpa/features/RelatedPostsTest.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/wpa/features/RelatedPostsTest.php b/tests/wpa/features/RelatedPostsTest.php index c64dcc2b55..e97d42a1a3 100644 --- a/tests/wpa/features/RelatedPostsTest.php +++ b/tests/wpa/features/RelatedPostsTest.php @@ -120,12 +120,28 @@ public function testRelatedPostsWidget() { $I->typeInField( 'input[name^="widget-ep-related-posts"]', 'Related Posts' ); - sleep( 2 ); + $update_button = $I->getElement( ".edit-widgets-header__actions .components-button.is-primary" ); - $I->click( ".edit-widgets-header__actions .components-button.is-primary" ); + $I->click( $update_button ); $I->waitUntilPageSourceContains( 'Widgets saved.' ); + sleep ( 1 ); + + /** + * It seems sometimes WP keeps a dirty state even after a successful save. + * When that happens, we get stuck with a "Are you sure you want to leave...?" message. + * + * Saving it again seems to fix the issue. + * + * @todo Investigate why WordPress gets stuck in that dirty state. + */ + if ( $I->elementIsEnabled( $update_button ) ) { + $I->click( $update_button ); + + sleep( 2 ); + } + $posts_data = [ [ 'title' => 'test related posts 1', From 66a44d0dee29a2ed0b9f0d2df7ef3c852fd427c0 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 20 Sep 2021 13:09:35 -0300 Subject: [PATCH 10/14] WP Acceptance: Fix typo Fix in WPA test the typo fixed in #2336 --- tests/wpa/DashboardSyncTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/wpa/DashboardSyncTest.php b/tests/wpa/DashboardSyncTest.php index abd07a03cc..e30fbc32f8 100644 --- a/tests/wpa/DashboardSyncTest.php +++ b/tests/wpa/DashboardSyncTest.php @@ -184,7 +184,7 @@ public function testWpCliSyncDuringDashboardSync() { $cli_result = $this->runCommand( 'wp elasticpress index' )['stdout']; - $this->assertStringContainsString( 'An index is already occuring', $cli_result ); + $this->assertStringContainsString( 'An index is already occurring', $cli_result ); $I->executeJavaScript( 'document.querySelector( ".resume-sync" ).click();' ); From 44f14ff43e36c3e36df6b11233533f3dce7117cc Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 20 Sep 2021 14:33:49 -0300 Subject: [PATCH 11/14] WPA: new moveTo() method that will retry in case of Page Crashed --- tests/wpa/BasicTest.php | 41 ++++++---------- tests/wpa/DashboardSyncTest.php | 28 +++++------ tests/wpa/GeneralTest.php | 8 +-- tests/wpa/HighlightingTest.php | 4 +- tests/wpa/WpCliTest.php | 14 +++--- tests/wpa/features/AutosuggestTest.php | 8 +-- tests/wpa/features/DocumentTest.php | 12 ++--- tests/wpa/features/ProtectedContentTest.php | 6 +-- tests/wpa/features/RelatedPostsTest.php | 54 ++++++--------------- tests/wpa/features/SearchTest.php | 6 +-- tests/wpa/features/WooCommerceTest.php | 16 +++--- tests/wpa/inc/TestBase.php | 41 +++++++++++++--- tests/wpa/indexables/UserTest.php | 6 +-- 13 files changed, 116 insertions(+), 128 deletions(-) diff --git a/tests/wpa/BasicTest.php b/tests/wpa/BasicTest.php index 305cbbe394..8a98d167d7 100644 --- a/tests/wpa/BasicTest.php +++ b/tests/wpa/BasicTest.php @@ -27,29 +27,16 @@ public function testDashboardSyncComplete() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".start-sync" ).click();' ); $I->waitUntilElementContainsText( 'Sync complete', '.sync-status' ); - try { - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-health' ); - foreach ( $this->indexes as $index_name ) { - $I->seeText( $index_name ); - } - } catch (\Throwable $th) { - // If failed for some other reason, it is a real failure. - if ( false === strpos( $th->getMessage(), 'Page crashed' ) ) { - throw $th; - } - - $cli_result = $this->runCommand( 'wp elasticpress stats' )['stdout']; - - foreach ( $this->indexes as $index_name ) { - $this->assertStringContainsString( $index_name, $cli_result ); - } + foreach ( $this->indexes as $index_name ) { + $I->seeText( $index_name ); } } @@ -65,7 +52,7 @@ public function testSearch() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/?s=test' ); + $this->moveTo( $I, '/?s=test' ); $I->click( '#wp-admin-bar-debug-bar' ); @@ -99,11 +86,11 @@ public function testWeightingOnOff() { sleep( 2 ); - $I->moveTo( '/?s=Test+ElasticPress+1' ); + $this->moveTo( $I, '/?s=Test+ElasticPress+1' ); $I->seeText( 'Test ElasticPress 1', '.hentry' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-weighting' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-weighting' ); $I->click( '#post-post_title-enabled' ); @@ -111,12 +98,12 @@ public function testWeightingOnOff() { $I->waitUntilElementContainsText( 'Changes Saved', '.notice-success' ); - $I->moveTo( '/?s=Test+ElasticPress+1' ); + $this->moveTo( $I, '/?s=Test+ElasticPress+1' ); $I->dontSeeText( 'Test ElasticPress 1', '.hentry' ); // Reset Changed Settings. - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-weighting' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-weighting' ); $I->click( '#post-post_title-enabled' ); @@ -151,7 +138,7 @@ public function testTitleContentWeighting() { $this->publishPost( $data, $I ); - $I->moveTo( '/?s=findme' ); + $this->moveTo( $I, '/?s=findme' ); $posts = $I->getElements( '.post' ); @@ -159,7 +146,7 @@ public function testTitleContentWeighting() { $I->seeText( 'test weighting content', $first_post ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-weighting' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-weighting' ); $I->setElementProperty( 'input[name="weighting[post][post_title][weight]"]', 'value', 20 ); @@ -167,7 +154,7 @@ public function testTitleContentWeighting() { $I->waitUntilElementContainsText( 'Changes Saved', '.notice-success' ); - $I->moveTo( '/?s=findme' ); + $this->moveTo( $I, '/?s=findme' ); $posts = $I->getElements( '.post' ); @@ -176,7 +163,7 @@ public function testTitleContentWeighting() { $I->seeText( 'test weighting title findme', $first_post ); // Reset Changed Settings. - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-weighting' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-weighting' ); $I->setElementProperty( 'input[name="weighting[post][post_title][weight]"]', 'value', 1 ); @@ -193,7 +180,7 @@ public function testAutosuggestDropdownShows() { $I = $this->openBrowserPage(); - $I->moveTo( '/' ); + $this->moveTo( $I, '/' ); $I->waitUntilElementVisible( '.search-toggle' ); diff --git a/tests/wpa/DashboardSyncTest.php b/tests/wpa/DashboardSyncTest.php index e30fbc32f8..e475ed26e7 100644 --- a/tests/wpa/DashboardSyncTest.php +++ b/tests/wpa/DashboardSyncTest.php @@ -24,17 +24,17 @@ public function testClickSyncButtonSinglesite() { $this->runCommand( 'wp elasticpress delete-index --yes' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-health' ); $I->seeText( 'We could not find any data for your Elasticsearch indices.' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".start-sync" ).click();' ); $I->waitUntilElementContainsText( 'Sync complete', '.sync-status' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-health' ); $I->dontSeeText( 'We could not find any data for your Elasticsearch indices.' ); @@ -59,21 +59,21 @@ public function testClickSyncButtonMultisite() { $this->runCommand( 'wp elasticpress delete-index --network-wide --yes' ); - $I->moveTo( 'wp-admin/network/sites.php' ); + $this->moveTo( $I, 'wp-admin/network/sites.php' ); $I->checkOptions( '.index-toggle' ); - $I->moveTo( 'wp-admin/network/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/network/admin.php?page=elasticpress-health' ); $I->seeText( 'We could not find any data for your Elasticsearch indices.' ); - $I->moveTo( 'wp-admin/network/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/network/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".start-sync" ).click();' ); $I->waitUntilElementContainsText( 'Sync complete', '.sync-status' ); - $I->moveTo( 'wp-admin/network/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/network/admin.php?page=elasticpress-health' ); $I->dontSeeText( 'We could not find any data for your Elasticsearch indices.' ); @@ -95,11 +95,11 @@ public function testResumeSync() { $this->runCommand( 'wp elasticpress delete-index --yes' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-health' ); $I->seeText( 'We could not find any data for your Elasticsearch indices.' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".start-sync" ).click();' ); @@ -107,9 +107,9 @@ public function testResumeSync() { sleep( 1 ); - $I->moveTo( 'wp-admin/index.php' ); + $this->moveTo( $I, 'wp-admin/index.php' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $I->seeText( 'Sync paused', '.sync-status' ); @@ -117,7 +117,7 @@ public function testResumeSync() { $I->waitUntilElementContainsText( 'Sync complete', '.sync-status' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress-health' ); $I->dontSeeText( 'We could not find any data for your Elasticsearch indices.' ); @@ -134,7 +134,7 @@ public function testPreventFeaturesActivationDuringSync() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $this->runCommand( 'wp elasticpress index --setup --yes' ); @@ -166,7 +166,7 @@ public function testWpCliSyncDuringDashboardSync() { // Slowing the index process a bit. $old_value = $this->setPerIndexCycle( 10, $I ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".start-sync" ).click();' ); diff --git a/tests/wpa/GeneralTest.php b/tests/wpa/GeneralTest.php index 42fded8610..b833331dc2 100644 --- a/tests/wpa/GeneralTest.php +++ b/tests/wpa/GeneralTest.php @@ -36,7 +36,7 @@ public function testFirstTimeActivation() { $this->activatePlugin(); - $I->moveTo( '/wp-admin/plugins.php' ); + $this->moveTo( $I, '/wp-admin/plugins.php' ); $I->seeText( 'ElasticPress is almost ready to go.' ); @@ -57,7 +57,7 @@ public function testFirstSetup() { $this->activatePlugin(); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $I->seeText( 'Index Your Content', '.setup-button' ); @@ -78,7 +78,7 @@ public function testSyncUpdatedPostData() { $this->publishPost( $data, $I ); - $I->moveTo( '/?s=Test+ElasticPress+1' ); + $this->moveTo( $I, '/?s=Test+ElasticPress+1' ); $I->seeText( 'Test ElasticPress 1', '.hentry' ); } @@ -103,7 +103,7 @@ public function testUnsupportedElasticsearchVersion() { $this->activatePlugin(); - $I->moveTo( '/wp-admin/plugins.php' ); + $this->moveTo( $I, '/wp-admin/plugins.php' ); $I->seeText( 'ElasticPress may or may not work properly.' ); diff --git a/tests/wpa/HighlightingTest.php b/tests/wpa/HighlightingTest.php index a04b4c19a7..9010b8a43d 100644 --- a/tests/wpa/HighlightingTest.php +++ b/tests/wpa/HighlightingTest.php @@ -27,7 +27,7 @@ public function testHighlightingColor() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".ep-feature-search .settings-button" ).click();' ); @@ -44,7 +44,7 @@ public function testHighlightingColor() { $this->publishPost( $data, $I ); - $I->moveTo( '/?s=findme' ); + $this->moveTo( $I, '/?s=findme' ); $I->seeElement( '.ep-highlight' ); } diff --git a/tests/wpa/WpCliTest.php b/tests/wpa/WpCliTest.php index 2f1ce36436..c2cebbdefe 100644 --- a/tests/wpa/WpCliTest.php +++ b/tests/wpa/WpCliTest.php @@ -42,11 +42,11 @@ public function testIndexCommandWithNetworkWide() { $this->activatePlugin( null, 'elasticpress', true ); - $I->moveTo( 'wp-admin/network/sites.php' ); + $this->moveTo( $I, 'wp-admin/network/sites.php' ); $I->checkOptions( '.index-toggle' ); - $I->moveTo( 'wp-admin/network/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/network/admin.php?page=elasticpress-health' ); $cli_result = $this->runCommand( 'wp elasticpress index --network-wide' )['stdout']; @@ -54,7 +54,7 @@ public function testIndexCommandWithNetworkWide() { $this->assertStringContainsString( 'Number of posts indexed on site', $cli_result ); - $I->moveTo( 'wp-admin/network/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/network/admin.php?page=elasticpress-health' ); $I->dontSeeText( 'We could not find any data for your Elasticsearch indices.' ); @@ -187,17 +187,17 @@ public function testDeleteIndexCommandWithNetworkWide() { $this->activatePlugin( $I, 'elasticpress', true ); - $I->moveTo( 'wp-admin/network/sites.php' ); + $this->moveTo( $I, 'wp-admin/network/sites.php' ); $I->checkOptions( '.index-toggle' ); - $I->moveTo( 'wp-admin/network/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/network/admin.php?page=elasticpress-health' ); $cli_result = $this->runCommand( 'wp elasticpress delete-index --network-wide --yes' )['stdout']; $this->assertStringContainsString( 'Index deleted', $cli_result ); - $I->moveTo( 'wp-admin/network/admin.php?page=elasticpress-health' ); + $this->moveTo( $I, 'wp-admin/network/admin.php?page=elasticpress-health' ); $I->seeText( 'We could not find any data for your Elasticsearch indices.' ); @@ -229,7 +229,7 @@ public function testPutMappingCommandWithNetworkWide() { $this->activatePlugin( $I, 'elasticpress', true ); - $I->moveTo( 'wp-admin/network/sites.php' ); + $this->moveTo( $I, 'wp-admin/network/sites.php' ); $I->checkOptions( '.index-toggle' ); diff --git a/tests/wpa/features/AutosuggestTest.php b/tests/wpa/features/AutosuggestTest.php index 12e2644dc1..05b33da5de 100644 --- a/tests/wpa/features/AutosuggestTest.php +++ b/tests/wpa/features/AutosuggestTest.php @@ -17,7 +17,7 @@ public function testSeeAutosuggestDropdown() { $I = $this->openBrowserPage(); - $I->moveTo( '/' ); + $this->moveTo( $I, '/' ); $I->waitUntilElementVisible( '.search-toggle' ); @@ -42,7 +42,7 @@ public function testSeeTypedPostTitleInDropdown() { $I = $this->openBrowserPage(); - $I->moveTo( '/' ); + $this->moveTo( $I, '/' ); $I->waitUntilElementVisible( '.search-toggle' ); @@ -79,7 +79,7 @@ public function testSearchForPostByCategory() { $I = $this->openBrowserPage(); - $I->moveTo( '/' ); + $this->moveTo( $I, '/' ); $I->waitUntilElementVisible( '.search-toggle' ); @@ -104,7 +104,7 @@ public function testClickSuggestionGoToPost() { $I = $this->openBrowserPage(); - $I->moveTo( '/' ); + $this->moveTo( $I, '/' ); $I->waitUntilElementVisible( '.search-toggle' ); diff --git a/tests/wpa/features/DocumentTest.php b/tests/wpa/features/DocumentTest.php index 009450cf37..e5e7d05a60 100644 --- a/tests/wpa/features/DocumentTest.php +++ b/tests/wpa/features/DocumentTest.php @@ -19,7 +19,7 @@ public function testSearchPdf() { $this->activateDocumentFeature( $I ); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".start-sync" ).click();' ); @@ -27,7 +27,7 @@ public function testSearchPdf() { $this->uploadFile( $I, dirname( __DIR__ ) . '/test-docs/pdf-file.pdf' ); - $I->moveTo( '/?s=dummy+pdf' ); + $this->moveTo( $I, '/?s=dummy+pdf' ); $I->seeText( 'pdf-file' ); } @@ -46,7 +46,7 @@ public function testSearchPttx() { $this->uploadFile( $I, dirname( __DIR__ ) . '/test-docs/pptx-file.pptx' ); - $I->moveTo( '/?s=dummy+slide' ); + $this->moveTo( $I, '/?s=dummy+slide' ); $I->seeText( 'pptx-file' ); } @@ -65,13 +65,13 @@ public function testSearchPdfAfterCliIndexSetup() { $this->uploadFile( $I, dirname( __DIR__ ) . '/test-docs/pdf-file.pdf' ); - $I->moveTo( '/?s=dummy+pdf' ); + $this->moveTo( $I, '/?s=dummy+pdf' ); $I->seeText( 'pdf-file' ); } private function uploadFile( $actor, $file ) { - $actor->moveTo( '/wp-admin/media-new.php?browser-uploader' ); + $this->moveTo( $actor, '/wp-admin/media-new.php?browser-uploader' ); $actor->attachFile( '#async-upload', $file ); @@ -81,7 +81,7 @@ private function uploadFile( $actor, $file ) { } private function activateDocumentFeature( $actor ) { - $actor->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $actor, '/wp-admin/admin.php?page=elasticpress' ); $class = $actor->getElementAttribute( '.ep-feature-documents', 'class' ); diff --git a/tests/wpa/features/ProtectedContentTest.php b/tests/wpa/features/ProtectedContentTest.php index 44117a040d..6261c73482 100644 --- a/tests/wpa/features/ProtectedContentTest.php +++ b/tests/wpa/features/ProtectedContentTest.php @@ -23,7 +23,7 @@ public function testTurnProtectedContentFeatureOn() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $I->click( '.ep-feature-protected_content .settings-button' ); @@ -58,7 +58,7 @@ public function testProtectedContentPostsList() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( 'wp-admin/edit.php' ); + $this->moveTo( $I, 'wp-admin/edit.php' ); $I->click( '#wp-admin-bar-debug-bar' ); @@ -93,7 +93,7 @@ public function testProtectedContentPostsDraftsList() { // Give some time to the async request that indexes the post. sleep( 5 ); - $I->moveTo( 'wp-admin/edit.php?post_status=draft&post_type=post' ); + $this->moveTo( $I, 'wp-admin/edit.php?post_status=draft&post_type=post' ); $I->click( '#wp-admin-bar-debug-bar' ); diff --git a/tests/wpa/features/RelatedPostsTest.php b/tests/wpa/features/RelatedPostsTest.php index e97d42a1a3..1e54374671 100644 --- a/tests/wpa/features/RelatedPostsTest.php +++ b/tests/wpa/features/RelatedPostsTest.php @@ -25,7 +25,7 @@ public function testSeeRelatedPostsWidgetIfActivated() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $I->click( '.ep-feature-related_posts .settings-button' ); @@ -35,31 +35,19 @@ public function testSeeRelatedPostsWidgetIfActivated() { sleep( 2 ); - // If we get "Page Crashed!" due to lack of memory, try WP-CLI. - try { - $this->openWidgetsPage( $I ); - - $I->click( '.edit-widgets-header-toolbar__inserter-toggle' ); - - $I->waitUntilElementVisible( '.block-editor-inserter__search-input' ); + $this->openWidgetsPage( $I ); - $I->typeInField( '.block-editor-inserter__search-input', 'ElasticPress Related Posts' ); + $I->click( '.edit-widgets-header-toolbar__inserter-toggle' ); - $I->dontSeeText( 'ElasticPress - Related Posts', '.block-editor-block-types-list' ); // Legacy Widget + $I->waitUntilElementVisible( '.block-editor-inserter__search-input' ); - $I->dontSeeText( 'Related Posts (ElasticPress)', '.block-editor-block-types-list' ); - } catch (\Throwable $th) { - // If failed for some other reason, it is a real failure. - if ( false === strpos( $th->getMessage(), 'Page crashed' ) ) { - throw $th; - } + $I->typeInField( '.block-editor-inserter__search-input', 'ElasticPress Related Posts' ); - $cli_result = $this->runCommand( "wp widget list {$this->sidebar_id}" )['stdout']; + $I->dontSeeText( 'ElasticPress - Related Posts', '.block-editor-block-types-list' ); // Legacy Widget - $this->assertStringNotContainsString( 'ep-related-posts', $cli_result ); - } + $I->dontSeeText( 'Related Posts (ElasticPress)', '.block-editor-block-types-list' ); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $I->click( '.ep-feature-related_posts .settings-button' ); @@ -69,31 +57,17 @@ public function testSeeRelatedPostsWidgetIfActivated() { sleep( 2 ); - // If we get "Page Crashed!" due to lack of memory, try WP-CLI. - try { - $this->openWidgetsPage( $I ); - - $I->click( '.edit-widgets-header-toolbar__inserter-toggle' ); - - $I->waitUntilElementVisible( '.block-editor-inserter__search-input' ); - - $I->typeInField( '.block-editor-inserter__search-input', 'ElasticPress Related Posts' ); + $this->openWidgetsPage( $I ); - $I->seeText( 'ElasticPress - Related Posts', '.block-editor-block-types-list' ); // Legacy Widget + $I->click( '.edit-widgets-header-toolbar__inserter-toggle' ); - $I->seeText( 'Related Posts (ElasticPress)', '.block-editor-block-types-list' ); - } catch (\Throwable $th) { - // If failed for some other reason, it is a real failure. - if ( false === strpos( $th->getMessage(), 'Page crashed' ) ) { - throw $th; - } + $I->waitUntilElementVisible( '.block-editor-inserter__search-input' ); - $this->runCommand( "wp widget add ep-related-posts {$this->sidebar_id}" ); + $I->typeInField( '.block-editor-inserter__search-input', 'ElasticPress Related Posts' ); - $cli_result = $this->runCommand( "wp widget list {$this->sidebar_id}" )['stdout']; + $I->seeText( 'ElasticPress - Related Posts', '.block-editor-block-types-list' ); // Legacy Widget - $this->assertStringContainsString( 'ep-related-posts', $cli_result ); - } + $I->seeText( 'Related Posts (ElasticPress)', '.block-editor-block-types-list' ); } /** diff --git a/tests/wpa/features/SearchTest.php b/tests/wpa/features/SearchTest.php index 6c8b864d86..09e7f2a76f 100644 --- a/tests/wpa/features/SearchTest.php +++ b/tests/wpa/features/SearchTest.php @@ -19,7 +19,7 @@ public function testSearchResultsFetchFromElasticsearch() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/?s=test' ); + $this->moveTo( $I, '/?s=test' ); $I->click( '#wp-admin-bar-debug-bar' ); @@ -54,7 +54,7 @@ public function testExactMatchesShowHigher() { 'content' => 'elasticpress', ], $I ); - $I->moveTo( '/?s=10up+loves+elasticpress' ); + $this->moveTo( $I, '/?s=10up+loves+elasticpress' ); $I->seeText( 'Higher', '#site-content article:nth-of-type(1)' ); @@ -85,7 +85,7 @@ public function testNewerDuplicatedPostsShowHigher() { 'content' => '10up loves elasticpress', ], $I ); - $I->moveTo( '/?s=10up+loves+elasticpress' ); + $this->moveTo( $I, '/?s=10up+loves+elasticpress' ); $I->seeText( '10up loves elasticpress', '#site-content article:nth-of-type(1)' ); $I->seeText( '10up loves elasticpress', '#site-content article:nth-of-type(2)' ); diff --git a/tests/wpa/features/WooCommerceTest.php b/tests/wpa/features/WooCommerceTest.php index d1111e7ab7..4a9c0f45d0 100644 --- a/tests/wpa/features/WooCommerceTest.php +++ b/tests/wpa/features/WooCommerceTest.php @@ -19,7 +19,7 @@ public function testAutoActivateFeatureIfActivateWooCommerce() { $this->activatePlugin( $I, 'woocommerce' ); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $this->assertStringContainsString( 'feature-active', $I->getElementAttribute( '.ep-feature-woocommerce', 'class' ) ); } @@ -34,7 +34,7 @@ public function testSyncPostsAfterActivatesWooCommerceFeature() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".ep-feature-woocommerce .settings-button" ).click();' ); @@ -44,7 +44,7 @@ public function testSyncPostsAfterActivatesWooCommerceFeature() { sleep( 2 ); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $I->click( '.ep-feature-woocommerce .settings-button' ); @@ -67,7 +67,7 @@ public function testFetchOrdersFromElasticsearch() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, '/wp-admin/admin.php?page=elasticpress' ); $I->click( '.ep-feature-protected_content .settings-button' ); @@ -77,7 +77,7 @@ public function testFetchOrdersFromElasticsearch() { $I->waitUntilElementContainsText( 'Sync complete', '.sync-status' ); - $I->moveTo( '/wp-admin/edit.php?post_type=shop_order' ); + $this->moveTo( $I, '/wp-admin/edit.php?post_type=shop_order' ); $I->click( '#wp-admin-bar-debug-bar' ); @@ -96,7 +96,7 @@ public function testFetchProductsFromElasticsearch() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/wp-admin/edit.php?post_type=product' ); + $this->moveTo( $I, '/wp-admin/edit.php?post_type=product' ); $I->click( '#wp-admin-bar-debug-bar' ); @@ -115,7 +115,7 @@ public function testProductCategoryServedByElasticsearch() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/product-category/uncategorized' ); + $this->moveTo( $I, '/product-category/uncategorized' ); $I->click( '#wp-admin-bar-debug-bar' ); @@ -134,7 +134,7 @@ public function testProductFilterServedByElasticsearch() { $I->loginAs( 'wpsnapshots' ); - $I->moveTo( '/shop/?filter_size=small' ); + $this->moveTo( $I, '/shop/?filter_size=small' ); $I->click( '#wp-admin-bar-debug-bar' ); diff --git a/tests/wpa/inc/TestBase.php b/tests/wpa/inc/TestBase.php index f9d6aca908..1d711b3ccd 100755 --- a/tests/wpa/inc/TestBase.php +++ b/tests/wpa/inc/TestBase.php @@ -194,7 +194,7 @@ public function publishPost( array $data, \WPAcceptance\PHPUnit\Actor $actor ) { $data = array_merge( $defaults, $data ); - $actor->moveTo( 'wp-admin/post-new.php' ); + $this->moveTo( $actor, 'wp-admin/post-new.php' ); try { $actor->click( '.edit-post-welcome-guide .components-modal__header button' ); @@ -256,9 +256,9 @@ protected function activatePlugin( $actor = null, $slug = 'elasticpress', $netwo } if ( $network ) { - $actor->moveTo( '/wp-admin/network/plugins.php' ); + $this->moveTo( $actor, '/wp-admin/network/plugins.php' ); } else { - $actor->moveTo( '/wp-admin/plugins.php' ); + $this->moveTo( $actor, '/wp-admin/plugins.php' ); } try { @@ -288,9 +288,9 @@ protected function deactivatePlugin( $actor = null, $slug = 'elasticpress', $net } if ( $network ) { - $actor->moveTo( '/wp-admin/network/plugins.php' ); + $this->moveTo( $actor, '/wp-admin/network/plugins.php' ); } else { - $actor->moveTo( '/wp-admin/plugins.php' ); + $this->moveTo( $actor, '/wp-admin/plugins.php' ); } try { @@ -335,7 +335,7 @@ public function checkTotal( int $total, \WPAcceptance\PHPUnit\Actor $actor ) { * @return string */ public function setPerIndexCycle( int $number, \WPAcceptance\PHPUnit\Actor $actor ) { - $actor->moveTo( 'wp-admin/admin.php?page=elasticpress-settings' ); + $this->moveTo( $actor, 'wp-admin/admin.php?page=elasticpress-settings' ); $per_page = $actor->getElementAttribute( '#ep_bulk_setting', 'value' ); @@ -364,7 +364,7 @@ public function maybeEnableFeature( $feature ) { * @param \WPAcceptance\PHPUnit\Actor $actor */ public function openWidgetsPage( $actor ) { - $actor->moveTo( '/wp-admin/widgets.php' ); + $this->moveTo( $actor, '/wp-admin/widgets.php' ); try { $actor->click( '.edit-widgets-welcome-guide .components-modal__header button' ); @@ -372,4 +372,31 @@ public function openWidgetsPage( $actor ) { // Do nothing } } + + /** + * Open a page in the browser. + * + * This method will keep trying to move to the new page until a success + * or any error other than "Page crashed" + * + * @param Actor $actor The actor + * @param array ...$args Arguments to be passed to Actor::moveTo() + */ + public function moveTo( $actor, ...$args ) { + $continue_trying = false; + $attempts = 0; + do { + try { + $attempts++; + $actor->moveTo( ...$args ); + $continue_trying = false; + } catch ( \Throwable $th ) { + // If failed due to Page crashed, let's try again. Otherwise, stop. + if ( false !== strpos( $th->getMessage(), 'Page crashed' ) ) { + $continue_trying = true; + sleep( 2 ); + } + } + } while ( $continue_trying && $attempts < 10 ); + } } diff --git a/tests/wpa/indexables/UserTest.php b/tests/wpa/indexables/UserTest.php index 658054f725..1da3872a86 100755 --- a/tests/wpa/indexables/UserTest.php +++ b/tests/wpa/indexables/UserTest.php @@ -26,7 +26,7 @@ public function setUp() { * @param \WPAcceptance\PHPUnit\Actor $actor Current actor. */ public function searchUser( $username = '', \WPAcceptance\PHPUnit\Actor $actor ) { - $actor->moveTo( 'wp-admin/users.php' ); + $this->moveTo( $actor, 'wp-admin/users.php' ); $actor->waitUntilElementVisible( '#user-search-input' ); @@ -54,7 +54,7 @@ public function testUserSync() { $this->createUser( $data, $I ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".start-sync" ).click();' ); @@ -105,7 +105,7 @@ public function testUserMetaSync() { $I->click( '#submit' ); - $I->moveTo( 'wp-admin/admin.php?page=elasticpress' ); + $this->moveTo( $I, 'wp-admin/admin.php?page=elasticpress' ); $I->executeJavaScript( 'document.querySelector( ".start-sync" ).click();' ); From 744b7359407d2a0fd47623a210363ba204367688 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 20 Sep 2021 15:25:13 -0300 Subject: [PATCH 12/14] Log Page Crashed error --- tests/wpa/inc/TestBase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/wpa/inc/TestBase.php b/tests/wpa/inc/TestBase.php index 1d711b3ccd..4433961dc2 100755 --- a/tests/wpa/inc/TestBase.php +++ b/tests/wpa/inc/TestBase.php @@ -383,16 +383,16 @@ public function openWidgetsPage( $actor ) { * @param array ...$args Arguments to be passed to Actor::moveTo() */ public function moveTo( $actor, ...$args ) { - $continue_trying = false; - $attempts = 0; + $attempts = 0; do { try { $attempts++; - $actor->moveTo( ...$args ); $continue_trying = false; + $actor->moveTo( ...$args ); } catch ( \Throwable $th ) { // If failed due to Page crashed, let's try again. Otherwise, stop. if ( false !== strpos( $th->getMessage(), 'Page crashed' ) ) { + \WPAcceptance\Log::instance()->write( 'Page crashed error. Retrying.', 0 ); $continue_trying = true; sleep( 2 ); } From 3d4680726199fd80a4c7b4e230094202ca3a1bfa Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 20 Sep 2021 16:00:14 -0300 Subject: [PATCH 13/14] WPA + Page Crashed: log # of attempts and wait 5 sec. --- tests/wpa/inc/TestBase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/wpa/inc/TestBase.php b/tests/wpa/inc/TestBase.php index 4433961dc2..7c7f3edefe 100755 --- a/tests/wpa/inc/TestBase.php +++ b/tests/wpa/inc/TestBase.php @@ -392,9 +392,9 @@ public function moveTo( $actor, ...$args ) { } catch ( \Throwable $th ) { // If failed due to Page crashed, let's try again. Otherwise, stop. if ( false !== strpos( $th->getMessage(), 'Page crashed' ) ) { - \WPAcceptance\Log::instance()->write( 'Page crashed error. Retrying.', 0 ); + \WPAcceptance\Log::instance()->write( 'Page crashed error. Retrying (' . $attempts . ')', 0 ); $continue_trying = true; - sleep( 2 ); + sleep( 5 ); } } } while ( $continue_trying && $attempts < 10 ); From bb53e311b965ae3b3d0db7ae3994a062d8a4eb35 Mon Sep 17 00:00:00 2001 From: Adil OZTASER Date: Tue, 21 Sep 2021 14:37:54 +0300 Subject: [PATCH 14/14] Fix EP enabled check when `is_integrated_request` returns false. --- includes/classes/Feature/Search/Search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Feature/Search/Search.php b/includes/classes/Feature/Search/Search.php index 835d8013e9..1d1e2d9ab0 100644 --- a/includes/classes/Feature/Search/Search.php +++ b/includes/classes/Feature/Search/Search.php @@ -569,7 +569,7 @@ public function output_feature_box_long() { */ public function integrate_search_queries( $enabled, $query ) { if ( ! Utils\is_integrated_request( $this->slug ) ) { - return; + return false; } if ( ! is_a( $query, 'WP_Query' ) ) {