Feature: Add tests for wp_removable_query_args#7731
Feature: Add tests for wp_removable_query_args#7731Debarghya-Banerjee wants to merge 1 commit intoWordPress:trunkfrom
wp_removable_query_args#7731Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
Hi @SergeyBiryukov , can you please take a look into this PR. Thanks. |
apermo
left a comment
There was a problem hiding this comment.
Some WPCS fixes. And some comments just state the obvious and could imho be removed.
| * @ticket 59938 | ||
| */ | ||
| public function test_should_modify_array_when_filter_applied() { | ||
| // Add a custom query argument using a filter |
There was a problem hiding this comment.
| // Add a custom query argument using a filter | |
| // Add a custom query argument using a filter. |
WPCS fix.
Or omit this comment, it is just stating the obvious.
|
|
||
| $result = wp_removable_query_args(); | ||
|
|
||
| // Assert that the custom argument is in the array |
There was a problem hiding this comment.
| // Assert that the custom argument is in the array | |
| // Assert that the custom argument is in the array. |
WPCS fix.
Or omit this comment, it is just stating the obvious.
| // Assert that the custom argument is in the array | ||
| $this->assertContains( 'custom_arg', $result, 'The filter did not modify the array as expected.' ); | ||
|
|
||
| // Remove the filter after the test |
There was a problem hiding this comment.
| // Remove the filter after the test | |
| // Remove the filter after the test. |
WPCS fix.
Or omit this comment, it is just stating the obvious.
| return $args; | ||
| }; | ||
|
|
||
| // Apply the custom filter |
There was a problem hiding this comment.
| // Apply the custom filter | |
| // Apply the custom filter. |
WPCS fix.
Or omit this comment, it is just stating the obvious.
| // Apply the custom filter | ||
| add_filter( 'removable_query_args', $custom_filter_callback ); | ||
|
|
||
| // Get the array with the filter applied |
There was a problem hiding this comment.
| // Get the array with the filter applied | |
| // Get the array with the filter applied. |
WPCS fix.
Or omit this comment, it is just stating the obvious.
| $result_with_filter = wp_removable_query_args(); | ||
| $this->assertContains( 'custom_arg', $result_with_filter, 'The filter did not add the custom argument.' ); | ||
|
|
||
| // Now, remove the custom filter |
There was a problem hiding this comment.
| // Now, remove the custom filter | |
| // Now, remove the custom filter. |
WPCS fix.
Or omit this comment, it is just stating the obvious.
| // Now, remove the custom filter | ||
| remove_filter( 'removable_query_args', $custom_filter_callback ); | ||
|
|
||
| // Get the array after the filter is removed |
There was a problem hiding this comment.
| // Get the array after the filter is removed | |
| // Get the array after the filter is removed. |
WPCS fix.
| // Get the array after the filter is removed | ||
| $result_after_filter_removed = wp_removable_query_args(); | ||
|
|
||
| // The original array should not contain 'custom_arg' |
There was a problem hiding this comment.
| // The original array should not contain 'custom_arg' | |
| // The original array should not contain 'custom_arg'. |
WPCS fix.
Trac Ticket: Core-53651
Overview
This pull request introduces unit tests for the
wp_removable_query_argsfunction to ensure that it behaves as expected in different scenarios. Specifically, the tests verify the following key behaviors:Return Type: Ensures the function returns an array.
Non-Empty Array: Confirms that the array is not empty.
Filter Functionality: Verifies that custom filters applied to the function modify the returned array as expected.
Reverting to Original State: Ensures that the array reverts to its original state after the custom filter is removed.
Added Test Cases:
test_should_return_array_when_called: Confirms that the function returns an array.test_should_return_non_empty_array_when_called: Verifies that the returned array is not empty.test_should_modify_array_when_filter_applied: Ensures that a custom filter correctly modifies the array of query arguments.test_should_revert_to_original_array_when_filter_removed: Checks that the array reverts to its original state after the custom filter is removed.