Skip to content

65341 ajax actions widgets order#11963

Open
pbearne wants to merge 5 commits into
WordPress:trunkfrom
pbearne:65341-ajax-actions-widgets_order
Open

65341 ajax actions widgets order#11963
pbearne wants to merge 5 commits into
WordPress:trunkfrom
pbearne:65341-ajax-actions-widgets_order

Conversation

@pbearne
Copy link
Copy Markdown

@pbearne pbearne commented May 25, 2026

This PR adds unit tests for the wp_ajax_widgets_order() function located in src/wp-admin/includes/ajax-actions.php.
And checks for $_POST[sidebars]? for use

The tests cover:

  • Successful saving of the widgets order for multiple sidebars.
  • Proper handling of invalid nonces (save-sidebar-widgets nonce).
  • Verification of user permissions (edit_theme_options capability).
  • Behavior when the sidebars parameter is missing.

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

AI Disclosure:

  • AI assistance: Yes
  • Tool(s): Junie (JetBrains)
  • Model(s): gemini-3-flash-preview
  • Used for: Code analysis, test implementation, and workflow management.

@github-actions
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. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @pbearne@git.wordpress.org.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Props pbearne.

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

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

*
* @package WordPress
* @subpackage UnitTests
* @since 3.1.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this the correct @since version?

Comment on lines +65 to +67
$this->assertContains( 'text-1', $updated_sidebars['sidebar-1'] );
$this->assertContains( 'text-2', $updated_sidebars['sidebar-1'] );
$this->assertContains( 'search-1', $updated_sidebars['sidebar-2'] );
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think these assertions run because they come after phpunit catches the exception thrown by _handleAjax(). If you disable these, you'll see the assertion count remains the same. Same for line 62 I think.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure if this is the best/proper approach, but if you do the test like this, it will run the other assertions:

		try {
			$this->_handleAjax( 'widgets-order' );
			$this->fail( 'Expected WPAjaxDieStopException was not thrown.' );
		} catch ( WPAjaxDieStopException $e ) {
			$this->assertSame( '1', $e->getMessage() );
		}

*
* @covers ::wp_ajax_widgets_order
*/
class Tests_wp_ajax_widgets_order extends WP_Ajax_UnitTestCase {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think the classname, or filename, needs to be changed? If running these tests in isolation, by referencing the filename, you get an error about being unable to find class widgetsOrder.

npm run test:php -- ./tests/phpunit/tests/admin/includes/ajax-actions/widgetsOrder.php --group ajax

> WordPress@7.1.0 test:php
> node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit ./tests/phpunit/tests/admin/includes/ajax-actions/widgetsOrder.php --group ajax

[dotenv@17.3.1] injecting env (19) from .env -- tip: ⚙️  override existing env vars with { override: true }
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
Class widgetsOrder could not be found in /var/www/tests/phpunit/tests/admin/includes/ajax-actions/widgetsOrder.php

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