mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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
This commit is contained in:
parent
5d0718497c
commit
f3f892ce46
61
tests/phpunit/tests/rewrite/addRewriteRule.php
Normal file
61
tests/phpunit/tests/rewrite/addRewriteRule.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group rewrite
|
||||
*/
|
||||
class Tests_Rewrite_AddRewriteRule extends WP_UnitTestCase {
|
||||
|
||||
public function setUp() {
|
||||
global $wp_rewrite;
|
||||
parent::setUp();
|
||||
|
||||
$wp_rewrite->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 ] );
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user