From 45ed97ad01d7ddee82fdba6cfb22d019b3619298 Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Wed, 13 Oct 2021 13:57:29 -0600 Subject: [PATCH 1/9] Account for password protected posts via protected_content feature --- .../ProtectedContent/ProtectedContent.php | 72 ++++++- includes/classes/Indexable/Post/Post.php | 1 + includes/mappings/post/7-0.php | 3 + tests/php/features/TestProtectedContent.php | 190 ++++++++++++++++++ 4 files changed, 264 insertions(+), 2 deletions(-) diff --git a/includes/classes/Feature/ProtectedContent/ProtectedContent.php b/includes/classes/Feature/ProtectedContent/ProtectedContent.php index 84101fce22..63be2ab6b0 100644 --- a/includes/classes/Feature/ProtectedContent/ProtectedContent.php +++ b/includes/classes/Feature/ProtectedContent/ProtectedContent.php @@ -45,8 +45,16 @@ public function __construct() { public function setup() { add_filter( 'ep_indexable_post_status', [ $this, 'get_statuses' ] ); add_filter( 'ep_indexable_post_types', [ $this, 'post_types' ], 10, 1 ); - add_filter( 'ep_admin_wp_query_integration', '__return_true' ); - add_action( 'pre_get_posts', [ $this, 'integrate' ] ); + add_filter( 'ep_post_formatted_args', [ $this, 'exclude_protected_posts' ], 10, 2 ); + add_filter( 'ep_search_post_return_args', [ $this, 'return_post_password' ] ); + add_filter( 'ep_index_posts_args', [ $this, 'query_password_protected_posts' ] ); + add_filter( 'ep_post_sync_args', [ $this, 'include_post_password' ], 10, 2 ); + + if ( is_admin() ) { + add_filter( 'ep_admin_wp_query_integration', '__return_true' ); + add_action( 'pre_get_posts', [ $this, 'integrate' ] ); + add_filter( 'ep_post_query_db_args', [ $this, 'query_password_protected_posts' ] ); + } if ( Features::factory()->get_registered_feature( 'comments' )->is_active() ) { add_filter( 'ep_indexable_comment_status', [ $this, 'get_comment_statuses' ] ); @@ -180,6 +188,66 @@ public function integrate( $query ) { remove_filter( 'ep_formatted_args', [ $search_feature, 'weight_recent' ], 10 ); } + /** + * Query all posts with and without password for indexing. + * + * @param array $args Database arguments + * @return array + */ + public function query_password_protected_posts( $args ) { + $args['has_password'] = null; + + return $args; + } + + /** + * Include post password when indexing. + * + * @param array $post_args Post arguments + * @param int $post_id Post ID + */ + public function include_post_password( $post_args, $post_id ) { + $post = get_post( $post_id ); + $post_args['post_password'] = ! empty( $post->post_password ) ? $post->post_password : null; // Assign null value so we can use the EXISTS filter. + return $post_args; + } + + /** + * Exclude proctected post from the frontend queries. + * + * @param array $formatted_args Formatted Elasticsearch query + * @param array $args Query variables + * @return array + */ + public function exclude_protected_posts( $formatted_args, $args ) { + /** + * Filter to exclude protected posts from search. + * + * @hook ep_exclude_password_protected_from_search + * @param {bool} $exclude Exclude post from search. + * @return {bool} + */ + if ( ! is_admin() && apply_filters( 'ep_exclude_password_protected_from_search', true ) ) { + $formatted_args['post_filter']['bool']['must_not'][] = array( + 'exists' => array( + 'field' => 'post_password', + ), + ); + } + + return $formatted_args; + } + + /** + * Add post_password to post object properties set after query + * + * @param array $properties Post properties + * @return array + */ + public function return_post_password( $properties ) { + return $properties + [ 'post_password' ]; + } + /** * Integrate EP into comment queries * diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index 867cbce1c8..3e6c262221 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -65,6 +65,7 @@ public function query_db( $args ) { 'order' => 'desc', 'no_found_rows' => false, 'ep_indexing_advanced_pagination' => true, + 'has_password' => false, ]; if ( isset( $args['per_page'] ) ) { diff --git a/includes/mappings/post/7-0.php b/includes/mappings/post/7-0.php index d740b1c471..36579175ef 100644 --- a/includes/mappings/post/7-0.php +++ b/includes/mappings/post/7-0.php @@ -325,6 +325,9 @@ 'post_excerpt' => array( 'type' => 'text', ), + 'post_password' => array( + 'type' => 'text', + ), 'post_content' => array( 'type' => 'text', ), diff --git a/tests/php/features/TestProtectedContent.php b/tests/php/features/TestProtectedContent.php index cbb4aaa40a..bd9d3cf421 100644 --- a/tests/php/features/TestProtectedContent.php +++ b/tests/php/features/TestProtectedContent.php @@ -229,4 +229,194 @@ public function testAdminCategories() { $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } + + /** + * Check if passwords on posts are synced when feature not active + * + * @since 3.7 + * @group protected-content + */ + public function testNoSyncPasswordedPost() { + add_filter( 'ep_post_sync_args', array( $this, 'filter_post_sync_args' ), 10, 1 ); + + $post_id = Functions\create_and_sync_post( array( 'post_password' => 'test' ) ); + + ElasticPress\Elasticsearch::factory()->refresh_indices(); + + // Check if ES post sync filter has been triggered + $this->assertTrue( ! empty( $this->applied_filters['ep_post_sync_args'] ) ); + + // Check if password was synced + $post = ElasticPress\Indexables::factory()->get( 'post' )->get( $post_id ); + $this->assertTrue( ! isset( $post['post_password'] ) ); + } + + /** + * Check if passwords on posts are synced when feature active + * + * @since 3.7 + * @group protected-content + */ + public function testSyncPasswordedPost() { + ElasticPress\Features::factory()->activate_feature( 'protected_content' ); + ElasticPress\Features::factory()->setup_features(); + + add_filter( 'ep_post_sync_args', array( $this, 'filter_post_sync_args' ), 10, 1 ); + + $post_id = Functions\create_and_sync_post( array( 'post_password' => 'test' ) ); + + ElasticPress\Elasticsearch::factory()->refresh_indices(); + + // Check if ES post sync filter has been triggered + $this->assertTrue( ! empty( $this->applied_filters['ep_post_sync_args'] ) ); + + // Check if password was synced + $post = ElasticPress\Indexables::factory()->get( 'post' )->get( $post_id ); + $this->assertEquals( 'test', $post['post_password'] ); + + // Remove password from post + wp_update_post( + array( + 'ID' => $post_id, + 'post_password' => '', + ) ); + + ElasticPress\Indexables::factory()->get( 'post' )->index( $post_id, true ); + ElasticPress\Elasticsearch::factory()->refresh_indices(); + + $post = ElasticPress\Indexables::factory()->get( 'post' )->get( $post_id ); + + // Check if password was removed on sync + $this->assertEmpty( $post['post_password'] ); + + // Add back password on post + wp_update_post( + array( + 'ID' => $post_id, + 'post_password' => 'test', + ) ); + + ElasticPress\Indexables::factory()->get( 'post' )->index( $post_id, true ); + ElasticPress\Elasticsearch::factory()->refresh_indices(); + + $post = ElasticPress\Indexables::factory()->get( 'post' )->get( $post_id ); + + // Check if password was added back on sync + $this->assertEquals( 'test', $post['post_password'] ); + } + + /** + * Check if password protected post shows up in admin + * + * @since 3.7 + * @group protected-content + */ + public function testAdminPasswordedPost() { + set_current_screen( 'edit.php' ); + + ElasticPress\Features::factory()->activate_feature( 'protected_content' ); + ElasticPress\Features::factory()->setup_features(); + + $post_id = Functions\create_and_sync_post( + array( + 'post_content' => 'findme 123', + 'post_password' => 'test' + ) + ); + + ElasticPress\Elasticsearch::factory()->refresh_indices(); + + add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); + + $query = new \WP_Query(); + + global $wp_the_query; + + $wp_the_query = $query; + + $args = array( + 's' => 'findme', + ); + + $query->query( $args ); + + $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertEquals( 1, $query->post_count ); + $this->assertEquals( 1, $query->found_posts ); + } + + /** + * Check password protected post in front-end + * + * @since 3.7 + * @group protected-content + */ + public function testFrontEndSearchPasswordedPost() { + set_current_screen( 'front' ); + + ElasticPress\Features::factory()->activate_feature( 'protected_content' ); + ElasticPress\Features::factory()->activate_feature( 'search' ); + ElasticPress\Features::factory()->setup_features(); + + // Need to call this since it's hooked to init + ElasticPress\Features::factory()->get_registered_feature( 'search' )->search_setup(); + + $post_id = Functions\create_and_sync_post( + array( + 'post_content' => 'findme 123', + 'post_password' => 'test', + ) + ); + ElasticPress\Elasticsearch::factory()->refresh_indices(); + + add_filter( 'ep_post_formatted_args', array( $this, 'catch_ep_post_formatted_args' ), 20 ); + + $query = new \WP_Query( + array( + 's' => 'findme', + ) + ); + + // Check to ensure query is being modified + $this->assertEquals( + 'post_password', + $this->fired_actions['ep_post_formatted_args']['post_filter']['bool']['must_not'][0]['exists']['field'] + ); + + // Check for no results + $this->assertEquals( 0, $query->post_count ); + $this->assertEquals( 0, $query->found_posts ); + + // Remove password from post + wp_update_post( + array( + 'ID' => $post_id, + 'post_password' => '', + ) ); + + ElasticPress\Indexables::factory()->get( 'post' )->index( $post_id, true ); + ElasticPress\Elasticsearch::factory()->refresh_indices(); + + $query = new \WP_Query( + array( + 's' => 'findme', + ) + ); + + // Check for a result now that password was removed + $this->assertEquals( 1, $query->post_count ); + $this->assertEquals( 1, $query->found_posts ); + } + + /** + * Catch ES query args. + * + * @since 3.7 + * @group protected-content + * @param array $args ES query args. + */ + public function catch_ep_post_formatted_args( $args ) { + $this->fired_actions['ep_post_formatted_args'] = $args; + return $args; + } } From 0bab040dfdd5b68753ff7613da86628aa58a3b3b Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 30 Nov 2021 00:54:33 -0600 Subject: [PATCH 2/9] Mimic WP default password post search behavior if protected content is on --- .../ProtectedContent/ProtectedContent.php | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/includes/classes/Feature/ProtectedContent/ProtectedContent.php b/includes/classes/Feature/ProtectedContent/ProtectedContent.php index 63be2ab6b0..d243f6e23a 100644 --- a/includes/classes/Feature/ProtectedContent/ProtectedContent.php +++ b/includes/classes/Feature/ProtectedContent/ProtectedContent.php @@ -220,19 +220,22 @@ public function include_post_password( $post_args, $post_id ) { * @return array */ public function exclude_protected_posts( $formatted_args, $args ) { - /** - * Filter to exclude protected posts from search. - * - * @hook ep_exclude_password_protected_from_search - * @param {bool} $exclude Exclude post from search. - * @return {bool} - */ - if ( ! is_admin() && apply_filters( 'ep_exclude_password_protected_from_search', true ) ) { - $formatted_args['post_filter']['bool']['must_not'][] = array( - 'exists' => array( - 'field' => 'post_password', - ), - ); + if ( true !== $args['has_password'] ) { + $maybe_logged_in_exclude = ! is_user_logged_in() || ( is_user_logged_in() && ! is_search() ); + /** + * Filter to exclude protected posts from search. + * + * @hook ep_exclude_password_protected_from_search + * @param {bool} $exclude Exclude post from search. + * @return {bool} + */ + if ( $maybe_logged_in_exclude && apply_filters( 'ep_exclude_password_protected_from_search', true ) ) { + $formatted_args['post_filter']['bool']['must_not'][] = array( + 'exists' => array( + 'field' => 'post_password', + ), + ); + } } return $formatted_args; From 7aa8312945aea450b1293810f4a6ee881bfca633 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 30 Nov 2021 00:56:31 -0600 Subject: [PATCH 3/9] Fix typo --- includes/classes/Feature/ProtectedContent/ProtectedContent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Feature/ProtectedContent/ProtectedContent.php b/includes/classes/Feature/ProtectedContent/ProtectedContent.php index d243f6e23a..e134275c60 100644 --- a/includes/classes/Feature/ProtectedContent/ProtectedContent.php +++ b/includes/classes/Feature/ProtectedContent/ProtectedContent.php @@ -23,7 +23,7 @@ class ProtectedContent extends Feature { /** - * Initialize feature setting it's config + * Initialize feature setting its config * * @since 3.0 */ From d07769363b48807c9dffe0cb8a36a6cbc6de64ec Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Tue, 30 Nov 2021 23:31:18 -0600 Subject: [PATCH 4/9] Bugfix: return post_password property if set --- .../classes/Feature/ProtectedContent/ProtectedContent.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/classes/Feature/ProtectedContent/ProtectedContent.php b/includes/classes/Feature/ProtectedContent/ProtectedContent.php index e134275c60..577fe2605c 100644 --- a/includes/classes/Feature/ProtectedContent/ProtectedContent.php +++ b/includes/classes/Feature/ProtectedContent/ProtectedContent.php @@ -46,9 +46,9 @@ public function setup() { add_filter( 'ep_indexable_post_status', [ $this, 'get_statuses' ] ); add_filter( 'ep_indexable_post_types', [ $this, 'post_types' ], 10, 1 ); add_filter( 'ep_post_formatted_args', [ $this, 'exclude_protected_posts' ], 10, 2 ); - add_filter( 'ep_search_post_return_args', [ $this, 'return_post_password' ] ); add_filter( 'ep_index_posts_args', [ $this, 'query_password_protected_posts' ] ); add_filter( 'ep_post_sync_args', [ $this, 'include_post_password' ], 10, 2 ); + add_filter( 'ep_search_post_return_args', [ $this, 'return_post_password' ] ); if ( is_admin() ) { add_filter( 'ep_admin_wp_query_integration', '__return_true' ); @@ -221,7 +221,6 @@ public function include_post_password( $post_args, $post_id ) { */ public function exclude_protected_posts( $formatted_args, $args ) { if ( true !== $args['has_password'] ) { - $maybe_logged_in_exclude = ! is_user_logged_in() || ( is_user_logged_in() && ! is_search() ); /** * Filter to exclude protected posts from search. * @@ -229,7 +228,7 @@ public function exclude_protected_posts( $formatted_args, $args ) { * @param {bool} $exclude Exclude post from search. * @return {bool} */ - if ( $maybe_logged_in_exclude && apply_filters( 'ep_exclude_password_protected_from_search', true ) ) { + if ( ! is_user_logged_in() && apply_filters( 'ep_exclude_password_protected_from_search', true ) ) { $formatted_args['post_filter']['bool']['must_not'][] = array( 'exists' => array( 'field' => 'post_password', @@ -248,7 +247,8 @@ public function exclude_protected_posts( $formatted_args, $args ) { * @return array */ public function return_post_password( $properties ) { - return $properties + [ 'post_password' ]; + $properties[] = 'post_password'; + return $properties; } /** From a5bca5e7f7af0debfb0e6cbc3d829825303a376f Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Wed, 1 Dec 2021 19:12:41 -0600 Subject: [PATCH 5/9] Bugfix: account for has_password is empty --- includes/classes/Feature/ProtectedContent/ProtectedContent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Feature/ProtectedContent/ProtectedContent.php b/includes/classes/Feature/ProtectedContent/ProtectedContent.php index 577fe2605c..c24aad50c6 100644 --- a/includes/classes/Feature/ProtectedContent/ProtectedContent.php +++ b/includes/classes/Feature/ProtectedContent/ProtectedContent.php @@ -220,7 +220,7 @@ public function include_post_password( $post_args, $post_id ) { * @return array */ public function exclude_protected_posts( $formatted_args, $args ) { - if ( true !== $args['has_password'] ) { + if ( empty( $args['has_password'] ) ) { /** * Filter to exclude protected posts from search. * From f23455da3d9bf2dac758d26e6be029083891e893 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Wed, 1 Dec 2021 19:31:10 -0600 Subject: [PATCH 6/9] Modify unit test --- tests/php/features/TestProtectedContent.php | 24 ++------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/tests/php/features/TestProtectedContent.php b/tests/php/features/TestProtectedContent.php index bd9d3cf421..925e852dd3 100644 --- a/tests/php/features/TestProtectedContent.php +++ b/tests/php/features/TestProtectedContent.php @@ -377,33 +377,13 @@ public function testFrontEndSearchPasswordedPost() { ) ); - // Check to ensure query is being modified - $this->assertEquals( + // As we are "logged in", it is expected we should see a password post. + $this->assertNotEquals( 'post_password', $this->fired_actions['ep_post_formatted_args']['post_filter']['bool']['must_not'][0]['exists']['field'] ); // Check for no results - $this->assertEquals( 0, $query->post_count ); - $this->assertEquals( 0, $query->found_posts ); - - // Remove password from post - wp_update_post( - array( - 'ID' => $post_id, - 'post_password' => '', - ) ); - - ElasticPress\Indexables::factory()->get( 'post' )->index( $post_id, true ); - ElasticPress\Elasticsearch::factory()->refresh_indices(); - - $query = new \WP_Query( - array( - 's' => 'findme', - ) - ); - - // Check for a result now that password was removed $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } From 9f5c9b2883dc144fb80ecdd739b53086fa933a32 Mon Sep 17 00:00:00 2001 From: Oscar Sanchez S Date: Wed, 1 Dec 2021 19:36:28 -0600 Subject: [PATCH 7/9] Modify Unit test --- tests/php/features/TestProtectedContent.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/php/features/TestProtectedContent.php b/tests/php/features/TestProtectedContent.php index 925e852dd3..c60f5208ec 100644 --- a/tests/php/features/TestProtectedContent.php +++ b/tests/php/features/TestProtectedContent.php @@ -377,13 +377,7 @@ public function testFrontEndSearchPasswordedPost() { ) ); - // As we are "logged in", it is expected we should see a password post. - $this->assertNotEquals( - 'post_password', - $this->fired_actions['ep_post_formatted_args']['post_filter']['bool']['must_not'][0]['exists']['field'] - ); - - // Check for no results + // Password post is expected to return as we are logged in. $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } From 5a0987e8e1560d68130a6e6f625842be64534f9f Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Fri, 3 Dec 2021 10:57:46 -0300 Subject: [PATCH 8/9] Docs + Lint --- .../ProtectedContent/ProtectedContent.php | 18 ++++++-- tests/php/features/TestProtectedContent.php | 41 +++++++------------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/includes/classes/Feature/ProtectedContent/ProtectedContent.php b/includes/classes/Feature/ProtectedContent/ProtectedContent.php index c24aad50c6..85949bb29f 100644 --- a/includes/classes/Feature/ProtectedContent/ProtectedContent.php +++ b/includes/classes/Feature/ProtectedContent/ProtectedContent.php @@ -191,6 +191,8 @@ public function integrate( $query ) { /** * Query all posts with and without password for indexing. * + * @since 4.0.0 + * * @param array $args Database arguments * @return array */ @@ -203,18 +205,26 @@ public function query_password_protected_posts( $args ) { /** * Include post password when indexing. * - * @param array $post_args Post arguments - * @param int $post_id Post ID + * @since 4.0.0 + * + * @param array $post_args Post arguments + * @param int $post_id Post ID + * @return array */ public function include_post_password( $post_args, $post_id ) { $post = get_post( $post_id ); - $post_args['post_password'] = ! empty( $post->post_password ) ? $post->post_password : null; // Assign null value so we can use the EXISTS filter. + + // Assign null value so we can use the EXISTS filter. + $post_args['post_password'] = ! empty( $post->post_password ) ? $post->post_password : null; + return $post_args; } /** * Exclude proctected post from the frontend queries. * + * @since 4.0.0 + * * @param array $formatted_args Formatted Elasticsearch query * @param array $args Query variables * @return array @@ -243,6 +253,8 @@ public function exclude_protected_posts( $formatted_args, $args ) { /** * Add post_password to post object properties set after query * + * @since 4.0.0 + * * @param array $properties Post properties * @return array */ diff --git a/tests/php/features/TestProtectedContent.php b/tests/php/features/TestProtectedContent.php index c60f5208ec..5a4ea2ed3d 100644 --- a/tests/php/features/TestProtectedContent.php +++ b/tests/php/features/TestProtectedContent.php @@ -233,7 +233,7 @@ public function testAdminCategories() { /** * Check if passwords on posts are synced when feature not active * - * @since 3.7 + * @since 4.0.0 * @group protected-content */ public function testNoSyncPasswordedPost() { @@ -244,17 +244,18 @@ public function testNoSyncPasswordedPost() { ElasticPress\Elasticsearch::factory()->refresh_indices(); // Check if ES post sync filter has been triggered - $this->assertTrue( ! empty( $this->applied_filters['ep_post_sync_args'] ) ); + $this->assertNotEmpty( $this->applied_filters['ep_post_sync_args'] ); // Check if password was synced $post = ElasticPress\Indexables::factory()->get( 'post' )->get( $post_id ); - $this->assertTrue( ! isset( $post['post_password'] ) ); + + $this->assertArrayNotHasKey( 'post_password', $post ); } /** * Check if passwords on posts are synced when feature active * - * @since 3.7 + * @since 4.0.0 * @group protected-content */ public function testSyncPasswordedPost() { @@ -268,7 +269,7 @@ public function testSyncPasswordedPost() { ElasticPress\Elasticsearch::factory()->refresh_indices(); // Check if ES post sync filter has been triggered - $this->assertTrue( ! empty( $this->applied_filters['ep_post_sync_args'] ) ); + $this->assertNotEmpty( $this->applied_filters['ep_post_sync_args'] ); // Check if password was synced $post = ElasticPress\Indexables::factory()->get( 'post' )->get( $post_id ); @@ -308,7 +309,7 @@ public function testSyncPasswordedPost() { /** * Check if password protected post shows up in admin * - * @since 3.7 + * @since 4.0.0 * @group protected-content */ public function testAdminPasswordedPost() { @@ -317,7 +318,7 @@ public function testAdminPasswordedPost() { ElasticPress\Features::factory()->activate_feature( 'protected_content' ); ElasticPress\Features::factory()->setup_features(); - $post_id = Functions\create_and_sync_post( + Functions\create_and_sync_post( array( 'post_content' => 'findme 123', 'post_password' => 'test' @@ -326,8 +327,6 @@ public function testAdminPasswordedPost() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query(); global $wp_the_query; @@ -340,7 +339,7 @@ public function testAdminPasswordedPost() { $query->query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -348,7 +347,7 @@ public function testAdminPasswordedPost() { /** * Check password protected post in front-end * - * @since 3.7 + * @since 4.0.0 * @group protected-content */ public function testFrontEndSearchPasswordedPost() { @@ -360,8 +359,8 @@ public function testFrontEndSearchPasswordedPost() { // Need to call this since it's hooked to init ElasticPress\Features::factory()->get_registered_feature( 'search' )->search_setup(); - - $post_id = Functions\create_and_sync_post( + + Functions\create_and_sync_post( array( 'post_content' => 'findme 123', 'post_password' => 'test', @@ -369,28 +368,16 @@ public function testFrontEndSearchPasswordedPost() { ); ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_filter( 'ep_post_formatted_args', array( $this, 'catch_ep_post_formatted_args' ), 20 ); - $query = new \WP_Query( array( 's' => 'findme', ) ); + $this->assertTrue( $query->elasticsearch_success ); + // Password post is expected to return as we are logged in. $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } - - /** - * Catch ES query args. - * - * @since 3.7 - * @group protected-content - * @param array $args ES query args. - */ - public function catch_ep_post_formatted_args( $args ) { - $this->fired_actions['ep_post_formatted_args'] = $args; - return $args; - } } From 8e30ded2a4bd6d42fd9aa5247e2d7713919093bf Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Fri, 3 Dec 2021 10:58:02 -0300 Subject: [PATCH 9/9] Add mapping change to 5.2 + lint on 7.0 --- includes/mappings/post/5-2.php | 3 +++ includes/mappings/post/7-0.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/mappings/post/5-2.php b/includes/mappings/post/5-2.php index 794d2ff96d..a5a3d27562 100644 --- a/includes/mappings/post/5-2.php +++ b/includes/mappings/post/5-2.php @@ -316,6 +316,9 @@ 'post_excerpt' => array( 'type' => 'text', ), + 'post_password' => array( + 'type' => 'text', + ), 'post_content' => array( 'type' => 'text', ), diff --git a/includes/mappings/post/7-0.php b/includes/mappings/post/7-0.php index 2b7cee30cb..dee30fdd78 100644 --- a/includes/mappings/post/7-0.php +++ b/includes/mappings/post/7-0.php @@ -325,7 +325,7 @@ 'post_excerpt' => array( 'type' => 'text', ), - 'post_password' => array( + 'post_password' => array( 'type' => 'text', ), 'post_content' => array(