65341 ajax actions widgets order#11963
Conversation
Co-authored-by: Junie <junie@jetbrains.com>
|
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 Unlinked AccountsThe 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: 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. |
| * | ||
| * @package WordPress | ||
| * @subpackage UnitTests | ||
| * @since 3.1.0 |
| $this->assertContains( 'text-1', $updated_sidebars['sidebar-1'] ); | ||
| $this->assertContains( 'text-2', $updated_sidebars['sidebar-1'] ); | ||
| $this->assertContains( 'search-1', $updated_sidebars['sidebar-2'] ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
This PR adds unit tests for the
wp_ajax_widgets_order()function located insrc/wp-admin/includes/ajax-actions.php.And checks for $_POST[sidebars]? for use
The tests cover:
save-sidebar-widgetsnonce).edit_theme_optionscapability).sidebarsparameter is missing.Trac ticket: https://core.trac.wordpress.org/ticket/65341
AI Disclosure: