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

Unit Test Failures with SearchPress adaptor #109

Closed
mslinnea opened this issue Dec 6, 2024 · 1 comment
Closed

Unit Test Failures with SearchPress adaptor #109

mslinnea opened this issue Dec 6, 2024 · 1 comment
Assignees
Labels
bug Something isn't working elasticsearch Requires understanding Elasticsearch php Requires understanding PHP

Comments

@mslinnea
Copy link
Member

mslinnea commented Dec 6, 2024

Description of the bug

When running tests with the SearchPress adaptor, there are test failures for loggedIn.php that relate to post statuses. See the below output.

Testing with SearchPress adapter, using SearchPress version 0.5 and host http://localhost:9200
Elasticsearch is up and running, using version 8.16.1.
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 9.6.21 by Sebastian Bergmann and contributors.

.......................................................FF.FF.FF  63 / 187 ( 33%)
............................................................... 126 / 187 ( 67%)
......S..........S...........................................   187 / 187 (100%)

Time: 00:36.800, Memory: 46.50 MB

There were 6 failures:

1) Tests_Query_LoggedIn::test_query_not_logged_in_any_status
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     3 => 'pending'
     4 => 'private'
     5 => 'publish'
-    6 => 'request-completed'
-    7 => 'request-confirmed'
-    8 => 'request-failed'
-    9 => 'request-pending'
 )

/var/www/sandbox/wp-content/plugins/es-wp-query/tests/query/loggedIn.php:52

2) Tests_Query_LoggedIn::test_query_not_logged_in_all_statuses
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'auto-draft'
-    1 => 'draft'
-    2 => 'future'
-    3 => 'inherit'
-    4 => 'pending'
-    5 => 'private'
-    6 => 'publish'
-    7 => 'request-completed'
-    8 => 'request-confirmed'
-    9 => 'request-failed'
-    10 => 'request-pending'
-    11 => 'trash'
+    0 => 'draft'
+    1 => 'future'
+    2 => 'inherit'
+    3 => 'pending'
+    4 => 'private'
+    5 => 'publish'
 )

/var/www/sandbox/wp-content/plugins/es-wp-query/tests/query/loggedIn.php:67

3) Tests_Query_LoggedIn::test_query_admin_logged_in_any_status
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     3 => 'pending'
     4 => 'private'
     5 => 'publish'
-    6 => 'request-completed'
-    7 => 'request-confirmed'
-    8 => 'request-failed'
-    9 => 'request-pending'
 )

/var/www/sandbox/wp-content/plugins/es-wp-query/tests/query/loggedIn.php:103

4) Tests_Query_LoggedIn::test_query_admin_logged_in_all_statuses
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'auto-draft'
-    1 => 'draft'
-    2 => 'future'
-    3 => 'inherit'
-    4 => 'pending'
-    5 => 'private'
-    6 => 'publish'
-    7 => 'request-completed'
-    8 => 'request-confirmed'
-    9 => 'request-failed'
-    10 => 'request-pending'
-    11 => 'trash'
+    0 => 'draft'
+    1 => 'future'
+    2 => 'inherit'
+    3 => 'pending'
+    4 => 'private'
+    5 => 'publish'
 )

/var/www/sandbox/wp-content/plugins/es-wp-query/tests/query/loggedIn.php:123

5) Tests_Query_LoggedIn::test_query_subscriber_logged_in_any_status
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     3 => 'pending'
     4 => 'private'
     5 => 'publish'
-    6 => 'request-completed'
-    7 => 'request-confirmed'
-    8 => 'request-failed'
-    9 => 'request-pending'
 )

/var/www/sandbox/wp-content/plugins/es-wp-query/tests/query/loggedIn.php:159

6) Tests_Query_LoggedIn::test_query_subscriber_logged_in_all_statuses
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'auto-draft'
-    1 => 'draft'
-    2 => 'future'
-    3 => 'inherit'
-    4 => 'pending'
-    5 => 'private'
-    6 => 'publish'
-    7 => 'request-completed'
-    8 => 'request-confirmed'
-    9 => 'request-failed'
-    10 => 'request-pending'
-    11 => 'trash'
+    0 => 'draft'
+    1 => 'future'
+    2 => 'inherit'
+    3 => 'pending'
+    4 => 'private'
+    5 => 'publish'
 )

/var/www/sandbox/wp-content/plugins/es-wp-query/tests/query/loggedIn.php:179

Steps To Reproduce

Install SearchPress plugin into your testing environment.
Create a es.php file in the tests directory.
Set up the es.php file like this:

<?php
require_once __DIR__ . '/../../searchpress/searchpress.php';
define( 'ES_WP_QUERY_TEST_ENV', true );
es_wp_query_load_adapter( 'searchpress' );

Run tests with composer run phpunit

Additional Information

No response

@mslinnea mslinnea added the bug Something isn't working label Dec 6, 2024
@kevinfodness kevinfodness added elasticsearch Requires understanding Elasticsearch php Requires understanding PHP labels Feb 19, 2025
@mboynes
Copy link
Contributor

mboynes commented Feb 19, 2025

SearchPress indexes all posts whose post_status is not internal, with a special exception carved out for inherit. We didn't change this logic when core added post statuses for exporting and removing personal data. For reference, here are all the core post statuses with 'internal' => true as of 6.7.2. Perhaps we should have? I think it's worth reconsidering which post statuses get indexed, so I created an issue over there to have that discussion. See alleyinteractive/searchpress#191.

As it pertains to ES_WP_Query, this is easy enough to work around, simply add this to that es.php file:

add_filter( 'sp_config_sync_statuses', fn() => get_post_stati() );

@mboynes mboynes closed this as completed Feb 19, 2025
@mboynes mboynes self-assigned this Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working elasticsearch Requires understanding Elasticsearch php Requires understanding PHP
Projects
None yet
Development

No branches or pull requests

3 participants