diff --git a/tests/phpunit/tests/rewrite/addRewriteRule.php b/tests/phpunit/tests/rewrite/addRewriteRule.php new file mode 100644 index 0000000000..2296e88722 --- /dev/null +++ b/tests/phpunit/tests/rewrite/addRewriteRule.php @@ -0,0 +1,61 @@ +init(); + $wp_rewrite->set_permalink_structure( '/%postname%/' ); + $wp_rewrite->flush_rules(); + } + + public function tearDown() { + global $wp_rewrite; + $wp_rewrite->init(); + + parent::tearDown(); + } + + /** + * @ticket 16840 + */ + public function test_add_rewrite_rule_redirect() { + global $wp_rewrite; + + $pattern = 'path/to/rewrite/([^/]+)/?$'; + $redirect = 'index.php?test_var1=$matches[1]&test_var2=1'; + add_rewrite_rule( $pattern, $redirect ); + + flush_rewrite_rules(); + + $rewrite_rules = $wp_rewrite->rewrite_rules(); + + $this->assertSame( $redirect, $rewrite_rules[ $pattern ] ); + } + + /** + * @ticket 16840 + */ + public function test_add_rewrite_rule_redirect_array() { + global $wp_rewrite; + + $pattern = 'path/to/rewrite/([^/]+)/?$'; + $redirect = 'index.php?test_var1=$matches[1]&test_var2=1'; + + add_rewrite_rule( $pattern, array( + 'test_var1' => '$matches[1]', + 'test_var2' => '1' + ) ); + + flush_rewrite_rules(); + + $rewrite_rules = $wp_rewrite->rewrite_rules(); + + $this->assertSame( $redirect, $rewrite_rules[ $pattern ] ); + } +}