From f3f892ce46478ffc60b8cfdd931c9106fff55348 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 6 Oct 2015 03:35:14 +0000 Subject: [PATCH] Rewrite: add tests for `add_rewrite_rule()`. Props DrewAPicture. See #16840. git-svn-id: https://develop.svn.wordpress.org/trunk@34847 602fd350-edb4-49c9-b593-d223f7449a82 --- .../phpunit/tests/rewrite/addRewriteRule.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/phpunit/tests/rewrite/addRewriteRule.php 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 ] ); + } +}