Tests: add unit test coverage for ElasticPressIo and ElasticPressIoTemplateManager - #4370
Open
noruzzamans wants to merge 1 commit into
Open
noruzzamans wants to merge 1 commit into
noruzzamans wants to merge 1 commit into
Conversation
noruzzamans
marked this pull request as ready for review
September 13, 2026 06:15
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces comprehensive automated unit test coverage for
ElasticPressIoand theElasticPressIoTemplateManagertrait in10up/ElasticPress.These components manage the lifecycle of ElasticPress.io search template registration, remote template synchronization, service availability checks, and caching. Prior to this PR, neither component had dedicated unit tests in
tests/php/.This PR is 100% test-only and introduces zero production code changes, ensuring zero risk of regressions while significantly strengthening the test harness.
Changes
1.
tests/php/TestElasticPressIo.php(New File)Dedicated unit test suite for
ElasticPress\ElasticPressIo:test_non_epio_environment_returns_empty():IS_EPIO_ENVIRONMENT=0to simulate a non-ElasticPress.io environment.get_endpoint_status(),get_endpoint_messages(), andget_endpoint_available_services()safely return empty arrays ([]).is_service_available('synonyms')returnsfalsewithout making any unexpected HTTP requests.test_get_endpoint_status_from_transient():IS_EPIO_ENVIRONMENT=1and seedsset_transient( ElasticPressIo::STATUS_TRANSIENT_NAME, ... )with structured endpoint responses (operational messages, available services with boolean and string flags).is_service_available()logic across multiple scenarios: active services returntrue, explicitly disabled services returnfalse, empty string flags returnfalse, and non-existent services returnfalse.2.
tests/php/TestElasticPressIoTemplateManager.php(New File)Dedicated unit test suite for the
ElasticPress\ElasticPressIoTemplateManagertrait using an anonymous class test double:test_get_hook_prefix():get_hook_prefix()correctly converts hyphenated feature slugs into underscore-delimited WordPress hook prefixes (e.g.test-feature-slug->ep_test_feature_slug,woocommerce-orders-autosuggest->ep_woocommerce_orders_autosuggest).test_epio_save_search_template():epio_save_search_template()triggers the{hook_prefix}_template_savedaction hook and passes the exact search template JSON body.test_epio_delete_search_template():epio_delete_search_template()triggers the{hook_prefix}_template_deletedaction hook upon template deletion.test_epio_get_search_template():ep_intercept_remote_request/ep_do_intercept_requestto simulate aWP_Errorand verifies thatepio_get_search_template()safely bubbles up theWP_Error.test_after_update_feature():['active' => true]) callsepio_save_search_template()and fires the save hook.['active' => false]) callsepio_delete_search_template()and fires the delete hook.Testing
1. PHPUnit Execution
Result: All 7 tests and 25 assertions pass (
OK (7 tests, 25 assertions)in < 0.15s).2. Coding Standards (10up PHPCS Standard)
Result:
0 errors, 0 warnings(100% compliant with 10up PHPCS standards).