Rewrite: allow add_rewrite_rule|WP_Rewrite::add_rule() to accept an associative array for the value of $redirect instead of requiring a query string.

Adds unit tests.

Props scribu, DrewAPicture.
Fixes #16840.


git-svn-id: https://develop.svn.wordpress.org/trunk@34708 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-09-30 01:10:03 +00:00
parent 27bc50cef8
commit 427f4fe063
3 changed files with 90 additions and 21 deletions
+57
View File
@@ -31,6 +31,63 @@ class Tests_Rewrite extends WP_UnitTestCase {
parent::tearDown();
}
/**
* @ticket 16840
*/
public function test_add_rule() {
global $wp_rewrite;
$pattern = 'path/to/rewrite/([^/]+)/?$';
$redirect = 'index.php?test_var1=$matches[1]&test_var2=1';
$wp_rewrite->add_rule( $pattern, $redirect );
$wp_rewrite->flush_rules();
$rewrite_rules = $wp_rewrite->rewrite_rules();
$this->assertSame( $redirect, $rewrite_rules[ $pattern ] );
}
/**
* @ticket 16840
*/
public function test_add_rule_redirect_array() {
global $wp_rewrite;
$pattern = 'path/to/rewrite/([^/]+)/?$';
$redirect = 'index.php?test_var1=$matches[1]&test_var2=1';
$wp_rewrite->add_rule( $pattern, array(
'test_var1' => '$matches[1]',
'test_var2' => '1'
) );
$wp_rewrite->flush_rules();
$rewrite_rules = $wp_rewrite->rewrite_rules();
$this->assertSame( $redirect, $rewrite_rules[ $pattern ] );
}
/**
* @ticket 16840
*/
public function test_add_rule_top() {
global $wp_rewrite;
$pattern = 'path/to/rewrite/([^/]+)/?$';
$redirect = 'index.php?test_var1=$matches[1]&test_var2=1';
$wp_rewrite->add_rule( $pattern, $redirect, 'top' );
$wp_rewrite->flush_rules();
$extra_rules_top = $wp_rewrite->extra_rules_top;
$this->assertContains( $redirect, $extra_rules_top[ $pattern ] );
}
function test_url_to_postid() {
$id = $this->factory->post->create();