Repository navigation
Tests: Add unit test coverage for WP_Widget_Archives - #14185
rejaulalomkhan wants to merge 2 commits into
Conversation
Adds a test class for WP_Widget_Archives, which had no tests. The tests cover the registration settings, the default and custom title output, the widget_title filter arguments, the HTML5 navigation wrapper vs. XHTML format, dropdown mode output and the widget_archives_dropdown_args filter, settings sanitization in update(), and the settings form output in form(). This is a test-only change; no production code is modified. See #65819.
|
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: @claude. 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. |
| ) | ||
| ); | ||
| $this->assertSame( 'checkbox', $processor->get_attribute( 'type' ) ); | ||
| $this->assertTrue( $processor->get_attribute( 'checked' ) ); |
There was a problem hiding this comment.
This is what's failing CI: checked() prints checked='checked', so get_attribute() returns the string 'checked' rather than true.
| $this->assertTrue( $processor->get_attribute( 'checked' ) ); | |
| $this->assertSame( 'checked', $processor->get_attribute( 'checked' ) ); |
AI Review: Opus 5.5
| ) | ||
| ); | ||
| $this->assertSame( 'checkbox', $processor->get_attribute( 'type' ) ); | ||
| $this->assertTrue( $processor->get_attribute( 'checked' ) ); |
There was a problem hiding this comment.
Same here, it only didn't show up in CI because the assertion above fails first.
| $this->assertTrue( $processor->get_attribute( 'checked' ) ); | |
| $this->assertSame( 'checked', $processor->get_attribute( 'checked' ) ); |
| $this->assertStringContainsString( '<select id="archives-dropdown-2" name="archive-dropdown">', $output ); | ||
| $this->assertStringContainsString( '<label class="screen-reader-text" for="archives-dropdown-2">Select Archive</label>', $output ); | ||
| $this->assertStringContainsString( '<option value="">Select Month</option>', $output ); | ||
| $this->assertStringContainsString( 'archives-dropdown-2', $output ); |
There was a problem hiding this comment.
This one is already covered by the <select id="archives-dropdown-2" assertion a few lines up, so I think it can go.
| $old_instance = array( | ||
| 'title' => 'Old Title', | ||
| 'count' => 0, | ||
| 'dropdown' => 0, | ||
| ); |
There was a problem hiding this comment.
Unchecked checkboxes aren't submitted, so the real-world case is count and dropdown missing from $new_instance. Could you add a data set for that?
With the old instance at 0/0 it wouldn't prove much though, so starting it at 1/1 would show the values are reset rather than carried over.
`checked()` outputs `checked='checked'`, so the attribute value read by the HTML API is the string `'checked'`, not `true`. `WP_HTML_Tag_Processor::next_tag()` does not support an `id` query key, so those queries silently matched the next `INPUT` regardless of its ID. Assert the `id` attribute of each input explicitly instead. Also remove a redundant dropdown ID assertion, and add an `update()` data set where the unchecked checkboxes are absent from the submitted instance, starting from an old instance with both options enabled, so that the reset to `0` is actually verified. See #65819. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9qLmSDTekkoHLL78tqtBH
Description
Adds a test class for
WP_Widget_Archives, which had no tests. The tests cover the registration settings, default and custom title output, thewidget_titlefilter arguments, the HTML5 navigation wrapper vs. XHTML format, dropdown mode output and thewidget_archives_dropdown_argsfilter, settings sanitization inupdate(), and the settings form output inform().This is a test-only change; no production code is modified.
Testing Instructions
npm run test:php -- --filter 'Tests_Widgets_wpWidgetArchives'npm run test:php -- --filter 'Tests_Widgets_wpWidgetArchives' -c tests/phpunit/multisite.xmlnpm run test:php -- --filter 'Tests_Widgets_wpWidgetArchives' --order-by=randomnpm run test:php -- --group widgetsnode ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/widgets/wpWidgetArchives.phpTrac ticket: https://core.trac.wordpress.org/ticket/65819
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request outside of WordPress Core Trac.