Tests: Fix unit tests after [36217].
See #35236. git-svn-id: https://develop.svn.wordpress.org/trunk@36218 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
79f2e50ca5
commit
1f47f9c5f5
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user