Skip to content

Tests: Add unit tests for the setup of the Menus screen in nav-menu.php - #15822

Open
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:test-nav-menu-boxes
Open

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:test-nav-menu-boxes

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 7, 2026

Copy link
Copy Markdown

Summary

Adds tests for the functions that set up the Menus screen (nav-menus.php) in src/wp-admin/includes/nav-menu.php, which had no tests.

  • wp_nav_menu_setup(): the meta boxes it registers (the post types, the custom links and the taxonomies), the filter of the advanced columns, and the advanced properties that are hidden the first time and kept afterwards.
  • wp_nav_menu_post_type_meta_boxes() and wp_nav_menu_taxonomy_meta_boxes(): a meta box for each post type and taxonomy that is shown in menus (and none for the others), the priority of pages, the arguments of the meta boxes, the nav_menu_meta_box_object filter (also to remove a meta box), and nothing when no object is shown in menus.
  • _wp_nav_menu_meta_box_object(): the default query of pages, posts, categories and the other objects, an object without a name, and the hook that adds it.
  • wp_initial_nav_menu_meta_boxes(): the meta boxes that are hidden the first time, the saved setting that is kept, and nothing without meta boxes.
  • wp_nav_menu_disabled_check() and wp_nav_menu_manage_columns().

The test restores the meta boxes, the global of the theme locations, and the post types and taxonomies it changes.

Testing

vendor/bin/phpunit --filter 'Tests_Admin_includesNavMenuSetup::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Admin_includesNavMenuSetup::'
vendor/bin/phpcs tests/phpunit/tests/admin/includesNavMenuSetup.php

Mutation check: 43 changes to the functions were each caught by a test, except three that do not change the output: the early returns when there are no post types or taxonomies (the loop does nothing for an empty list) and the separate branch for posts in the default query (it is the same as the one for the other objects).

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@hmbashar
hmbashar marked this pull request as ready for review November 7, 2026 12:03
@github-actions

github-actions Bot commented Nov 7, 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 hmbashar, lancewillett.

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.

@lancewillett

Copy link
Copy Markdown
Member

@hmbashar this note covers all 148 of your open test PRs (#15521–#15822, opened Nov 6–7) and their Trac tickets.

New tests in Core need to earn their place. The bar, from #52895 comment 207: "Ideally new tests are in relation to a broken feature, bug/regression, versus just adding coverage for its own sake." A function with no tests isn't enough reason on its own. Every test adds run time and upkeep for everyone who works on that code.

Before anyone reviews these:

  1. Please hold off on opening more.
  2. For each PR, add to its Trac ticket the bug or regression it would have caught, with a link to the ticket or changeset where that happened. Close the PRs and tickets that don't have one.
  3. For the block PRs (about 89 of them): Core copies most block PHP in src/wp-includes/blocks/ from Gutenberg's block-library package, and Gutenberg keeps its own block PHPUnit tests in phpunit/blocks/. Tests for that code belong there, next to where it's written. Avatar, Calendar and Latest Posts already have tests there.

The mutation checks in your PR bodies are good practice. They show the tests detect a change, though, not that the change is likely to happen.

New tests go to the maintainers of each ticket's component for review and landing. I won't be reviewing these for Build/Test Tools.

AI review · claude-opus-5-5

@hmbashar

hmbashar commented Nov 7, 2026 •

Copy link
Copy Markdown
Author

Hi @lancewillett,

Thank you for taking the time to review this and for explaining the expectations so clearly. I appreciate the guidance, and I apologize for the extra load my PRs have put on the team.

I'm new to contributing to Core. My office was closed on Friday and Saturday, and I wanted to make good use of those two days by contributing. I spent the full time on it, but in my enthusiasm I opened far more PRs than made sense. Most of them added coverage for its own sake rather than addressing a specific bug or regression. I should have read the testing guidelines and the contributor expectations before starting, and I'm sorry that I didn't.

Here is what I'll do:

  • I've stopped opening new PRs and tickets.
  • I'll close the block PRs, since that code is maintained in Gutenberg. If any of those tests are worth keeping, I'll propose them in Gutenberg's phpunit/blocks/ instead.
  • I'll go through the remaining PRs and close any that I can't tie to a real bug or regression. For any I keep, I'll add the bug or regression it would have caught to the Trac ticket.

Thank you again for your patience. I'll follow these guidelines in my future contributions.

@hmbashar

hmbashar commented Nov 7, 2026

Copy link
Copy Markdown
Author

Hi @lancewillett, one follow-up question: for the matching Trac tickets (e.g. the Editor-component ones), the only closing option I have is "close as fixed", which wouldn't be accurate since nothing was committed, so I haven't touched them.

What's the preferred way to handle these? Would it be fine to leave a short comment on each ticket asking a maintainer to close it as wontfix?

Thank you.

@lancewillett

Copy link
Copy Markdown
Member

Thanks @hmbashar, and thanks for cleaning these up so quickly.

No need to comment on each ticket. Close the PRs you're not keeping and leave their tickets as they are; they'll be closed as wontfix once the PR is closed. For any PR you keep, note the bug or regression on its ticket.

AI review · claude-opus-5-5

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