Skip to content

Tests: Expand test coverage for wp_list_filter(). - #13718

Open
mindctrl wants to merge 2 commits into
WordPress:trunkfrom
mindctrl:53987-test_wp_list_filter
Open

mindctrl wants to merge 2 commits into
WordPress:trunkfrom
mindctrl:53987-test_wp_list_filter

Conversation

@mindctrl

Copy link
Copy Markdown
Member

Every case in the data provider passed a list of objects, and every case spelled the operator in uppercase. Two parts of WP_List_Util::filter() therefore never ran:

  • A list can hold arrays as well as objects, and the two are matched differently: arrays with array_key_exists(), objects with isset(). Only the object path was tested.
  • The operator is uppercased before it is checked against AND, OR, and NOT, so and works the same as AND. Since the tests only ever passed uppercase, dropping the strtoupper() would not have failed anything, even though wp_filter_object_list() itself defaults to lowercase and.

Also adds cases for the default operator, an empty list, a null list, list values that are neither arrays nor objects, empty arguments with an invalid operator, string keys in the output, OR matching nothing, NOT matching everything, and a loose true to 'yes' comparison alongside the existing numeric one.

See #53987.

Trac ticket: https://core.trac.wordpress.org/ticket/53987

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Opus 5
Used for: Initial to identify gaps in testing and to generate tests for them

Every case in the data provider passed a list of objects, and every case
spelled the operator in uppercase. Two parts of `WP_List_Util::filter()`
therefore never ran:

* A list can hold arrays as well as objects, and the two are matched
  differently: arrays with `array_key_exists()`, objects with `isset()`.
  Only the object path was tested.
* The operator is uppercased before it is checked against `AND`, `OR`,
  and `NOT`, so `and` works the same as `AND`. Since the tests only ever
  passed uppercase, dropping the `strtoupper()` would not have failed anything,
  even though `wp_filter_object_list()` itself defaults to lowercase
  `and`.

Also adds cases for the default operator, an empty list, a `null` list,
list values that are neither arrays nor objects, empty arguments with an
invalid operator, string keys in the output, `OR` matching nothing, `NOT`
matching everything, and a loose `true` to `'yes'` comparison alongside
the existing numeric one.

See #53987.
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props mindctrl, huzaifaalmesbah.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @mindctrl! I really appreciate the list of arrays cases and the lowercase operators, I checked them against WP_List_Util::filter() and they match, including the isset() and array_key_exists() difference for null. Looks good to me, I left one optional note inline.

AI Review: Opus 5.5

Comment thread tests/phpunit/tests/functions/wpListFilter.php Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants