diff --git a/tests/phpunit/tests/rewrite/rewriteTags.php b/tests/phpunit/tests/rewrite/rewriteTags.php index a86fcc0ad8..d8cde6929b 100644 --- a/tests/phpunit/tests/rewrite/rewriteTags.php +++ b/tests/phpunit/tests/rewrite/rewriteTags.php @@ -7,9 +7,14 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase { protected $rewritecode; protected $rewritereplace; protected $queryreplace; + protected $wp_rewrite; public function setUp() { global $wp_rewrite; + $this->wp_rewrite = $wp_rewrite; + $wp_rewrite = new WP_Rewrite(); + $wp_rewrite->init(); + $this->rewritecode = $wp_rewrite->rewritecode; $this->rewritereplace = $wp_rewrite->rewritereplace; $this->queryreplace = $wp_rewrite->queryreplace; @@ -17,9 +22,7 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase { public function tearDown() { global $wp_rewrite; - $wp_rewrite->rewritecode = $this->rewritecode; - $wp_rewrite->rewritereplace = $this->rewritereplace; - $wp_rewrite->queryreplace = $this->queryreplace; + $wp_rewrite = $this->wp_rewrite; } public function _invalid_rewrite_tags() { @@ -43,29 +46,33 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase { global $wp_rewrite; add_rewrite_tag( $tag, $regex ); - $this->assertNotContains( $tag, $wp_rewrite->rewritecode ); - $this->assertNotContains( $regex, $wp_rewrite->rewritereplace ); - $this->assertNotContains( $tag . '=', $wp_rewrite->queryreplace ); + $this->assertEqualSets( $this->rewritecode, $wp_rewrite->rewritecode ); + $this->assertEqualSets( $this->rewritereplace, $wp_rewrite->rewritereplace ); + $this->assertEqualSets( $this->queryreplace, $wp_rewrite->queryreplace ); } public function test_add_rewrite_tag_empty_query() { global $wp_rewrite; + $rewritecode = $wp_rewrite->rewritecode; + $rewritecode[] = '%foo%'; add_rewrite_tag( '%foo%', 'bar' ); - $this->assertSame( array_merge( $this->rewritecode, array( '%foo%' ) ), $wp_rewrite->rewritecode ); - $this->assertSame( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace ); - $this->assertSame( array_merge( $this->queryreplace, array( 'foo=' ) ), $wp_rewrite->queryreplace ); + $this->assertEqualSets( $rewritecode, $wp_rewrite->rewritecode ); + $this->assertEqualSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace ); + $this->assertEqualSets( array_merge( $this->queryreplace, array( 'foo=' ) ), $wp_rewrite->queryreplace ); } public function test_add_rewrite_tag_custom_query() { global $wp_rewrite; + $rewritecode = $wp_rewrite->rewritecode; + $rewritecode[] = '%foo%'; add_rewrite_tag( '%foo%', 'bar', 'baz=' ); - $this->assertSame( array_merge( $this->rewritecode, array( '%foo%' ) ), $wp_rewrite->rewritecode ); - $this->assertSame( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace ); - $this->assertSame( array_merge( $this->queryreplace, array( 'baz=' ) ), $wp_rewrite->queryreplace ); + $this->assertEqualSets( $rewritecode, $wp_rewrite->rewritecode ); + $this->assertEqualSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace ); + $this->assertEqualSets( array_merge( $this->queryreplace, array( 'baz=' ) ), $wp_rewrite->queryreplace ); } public function test_add_rewrite_tag_updates_existing() { @@ -82,15 +89,17 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase { public function test_remove_rewrite_tag() { global $wp_rewrite; + $rewritecode = $wp_rewrite->rewritecode; + $rewritecode[] = '%foo%'; add_rewrite_tag( '%foo%', 'bar', 'baz=' ); - $this->assertSame( array_merge( $this->rewritecode, array( '%foo%' ) ), $wp_rewrite->rewritecode ); - $this->assertSame( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace ); - $this->assertSame( array_merge( $this->queryreplace, array( 'baz=' ) ), $wp_rewrite->queryreplace ); + $this->assertEqualSets( $rewritecode, $wp_rewrite->rewritecode ); + $this->assertEqualSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace ); + $this->assertEqualSets( array_merge( $this->queryreplace, array( 'baz=' ) ), $wp_rewrite->queryreplace ); remove_rewrite_tag( '%foo%' ); - $this->assertSame( $this->rewritecode, $wp_rewrite->rewritecode ); - $this->assertSame( $this->rewritereplace, $wp_rewrite->rewritereplace ); - $this->assertSame( $this->queryreplace, $wp_rewrite->queryreplace ); + $this->assertEqualSets( $this->rewritecode, $wp_rewrite->rewritecode ); + $this->assertEqualSets( $this->rewritereplace, $wp_rewrite->rewritereplace ); + $this->assertEqualSets( $this->queryreplace, $wp_rewrite->queryreplace ); } public function test_remove_rewrite_tag_internal_tag() { @@ -110,15 +119,19 @@ class Tests_Rewrite_Tags extends WP_UnitTestCase { public function test_remove_rewrite_tag_only_removes_one_array_value() { global $wp_rewrite; + $rewritecode = $wp_rewrite->rewritecode; + $rewritecode[] = '%foo%'; + $rewritereplace = $wp_rewrite->rewritereplace; + $rewritereplace[] = '([0-9]{1,2})'; add_rewrite_tag( '%foo%', '([0-9]{1,2})', 'post_type=foo&name=' ); - $this->assertSame( array_merge( $this->rewritecode, array( '%foo%' ) ), $wp_rewrite->rewritecode ); - $this->assertSame( array_merge( $this->rewritereplace, array( '([0-9]{1,2})' ) ), $wp_rewrite->rewritereplace ); - $this->assertSame( array_merge( $this->queryreplace, array( 'post_type=foo&name=' ) ), $wp_rewrite->queryreplace ); + $this->assertEqualSets( $rewritecode, $wp_rewrite->rewritecode ); + $this->assertEqualSets( $rewritereplace, $wp_rewrite->rewritereplace ); + $this->assertEqualSets( array_merge( $this->queryreplace, array( 'post_type=foo&name=' ) ), $wp_rewrite->queryreplace ); remove_rewrite_tag( '%foo%' ); - $this->assertSame( $this->rewritecode, $wp_rewrite->rewritecode ); - $this->assertSame( $this->rewritereplace, $wp_rewrite->rewritereplace ); - $this->assertSame( $this->queryreplace, $wp_rewrite->queryreplace ); + $this->assertEqualSets( $this->rewritecode, $wp_rewrite->rewritecode ); + $this->assertEqualSets( $this->rewritereplace, $wp_rewrite->rewritereplace ); + $this->assertEqualSets( $this->queryreplace, $wp_rewrite->queryreplace ); $this->assertNotContains( '%foo%', $wp_rewrite->rewritecode ); $this->assertContains( '([0-9]{1,2})', $wp_rewrite->rewritereplace );