Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#35452 closed defect (bug) (fixed)

WP_UnitTestCase::set_permalink_structure() doesn't set all permastructures

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: 4.7 Priority: high
Severity: normal Version:
Component: Build/Test Tools Keywords: needs-patch needs-unit-tests
Focuses: Cc:


Calling $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ) from within a unit test does not result in the $wp_rewrite->extra_permastructs property being populated.

The result is that categories and tags don't have pretty permalinks enabled. Posts, date archives, author archives, custom post type archives etc do have pretty permalinks enabled as expected.

Example failing test:

public function test_pretty_links() {
	$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );

	$term     = self::factory()->term->create_and_get();
	$expected = 'http://' . WP_TESTS_DOMAIN . '/tag/' . $term->slug . '/';
	$actual   = get_term_link( $term );

	$this->assertEquals( $expected, $actual );

Attachments (1)

35452-tests.patch (985 bytes) - added by stevenkword 8 years ago.

Download all attachments as: .zip

Change History (11)

#1 @stevenkword
8 years ago

  • Priority changed from normal to high

I'm escalating the priority to 'high' since this is blocking both #30210 and #31935.

#2 @stevenkword
8 years ago

@johnbillion -- The tests you shared passes for me.

#3 @stevenkword
8 years ago

  • Keywords has-unit-tests added

#4 @mboynes
8 years ago

This test doesn't fail for me either on trunk. @johnbillion, can you double-check?

#5 @mboynes
8 years ago

If there is an issue still related to this, it might be related to #37207 and the proposed patch there might resolve it.

#6 @johnbillion
8 years ago

It looks like we have some cross-test leakage somewhere. Running this test on its own with phpunit --filter Tests_Rewrite_Pretty_Permalinks results in a failure:

1) Tests_Rewrite_Pretty_Permalinks::test_term_permalink
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@

But running it as part of the whole suite with phpunit or as part of the rewrite group with phpunit --group rewrite results in a pass.

#7 @stevenkword
8 years ago

What can I do to help nudge this along? I'm really trying to get #30210 in for 4.7, and this is blocking.

#8 @johnbillion
8 years ago

  • Milestone changed from Awaiting Review to 4.7

#9 @johnbillion
8 years ago

  • Keywords needs-unit-tests added; has-unit-tests removed

I've found the cause of this failure. create_initial_taxonomies() needs to be re-called after calling $this->set_permalink_structure( $structure ). See #37851 and [38407].

#10 @johnbillion
8 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 38654:

Built/Test Tools: Unify the way the permastructure is set when used in conjunction with re-registering the initial taxonomies. This ensure that rewrite rules for taxonomies are consistently available.

Fixes #35452

Note: See TracTickets for help on using tickets.