mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user