#31135 closed defect (bug) (fixed)
register_taxonomy() should call a _doing_it_wrong() when called with an empty taxonomy name
| Reported by: | tyxla | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.2 |
| Component: | Taxonomy | Version: | 3.0 |
| Severity: | minor | Keywords: | has-patch commit |
| Cc: | Focuses: |
Description
If you misuse register_taxonomy() with an empty string as a first parameter, this will currently not throw any notice.
Anyway, it is definitely wrong and can lead to some very weird results both in the administration and in the frontend.
I suggest that a _doing_it_wrong() should be called to cover this case.
Attachments (5)
Change History (16)
#2
@
12 years ago
- Keywords needs-unit-tests added
- Milestone Awaiting Review → 4.2
- Severity normal → minor
- Type enhancement → defect (bug)
Hi @tyxla, thanks for the patch, that's a good catch. I think we can probably modify the existing _doing_it_wrong() call to account for both cases, maybe "Taxonomies must be between 1 and 32 characters in length." We also need a unit test covering the empty string case.
@
12 years ago
Updating the first patch. Now using a single _doing_it_wrong() call for both taxonomy min and max, also adding unit tests for both cases.
#5
@
12 years ago
Just a couple of things on 31135.2.patch:
- Rather than tacking tests on to the main
test_register_taxonomy()method, you should split them out to more specifically-named tests. For instance, the "> 32 characters" case is already covered bytest_register_long_taxonomy()a few lines below your changes - Realistically, we're checking for the returned
WP_Errorobject instead of a_doing_it_wrong()to confirm the test, see below for an example of this:<?php /** * @ticket 21593 * * @expectedIncorrectUsage register_taxonomy */ function test_register_long_taxonomy() { $this->assertInstanceOf( 'WP_Error', register_taxonomy( 'abcdefghijklmnopqrstuvwxyz0123456789', 'post', array() ) ); }
- So perhaps creating a
test_register_short_taxonomy()block might be the way to go. I'd follow the same syntax as for long
#6
@
12 years ago
Thanks for making things more clear on how _doing_it_wrong() cases are tested. And I really missed the test_register_long_taxonomy() test.
Updating the patch with your suggestions right away.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Adding a
_doing_it_wrong()whenregister_taxonomy()is called with an empty taxonomy name.