forked from Yoast/wordpress-seo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-class-rewrite.php
113 lines (88 loc) · 3.27 KB
/
test-class-rewrite.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
class WPSEO_Rewrite_Test extends WPSEO_UnitTestCase {
/**
* @var string
*/
private $flush_option_name = 'wpseo_flush_rewrite';
/**
* @var WPSEO_Rewrite
*/
private static $class_instance;
public static function setUpBeforeClass() {
self::$class_instance = new WPSEO_Rewrite;
}
/**
* @covers WPSEO_Rewrite::schedule_flush
*/
public function test_schedule_flush() {
self::$class_instance->schedule_flush();
$this->assertTrue( get_option( $this->flush_option_name ) == true );
}
/**
* @covers WPSEO_Rewrite::flush
*/
public function test_flush() {
delete_option( $this->flush_option_name );
$this->assertFalse( self::$class_instance->flush() );
self::$class_instance->schedule_flush();
$this->assertTrue( self::$class_instance->flush() );
}
/**
* @covers WPSEO_Rewrite::no_category_base
*/
public function test_no_category_base() {
$input = 'http://yoast.com/cat/link/';
$category_base = get_option( 'category_base' );
if ( '' == $category_base ) {
$category_base = 'category';
}
// Remove initial slash, if there is one (we remove the trailing slash in the regex replacement and don't want to end up short a slash)
if ( '/' == substr( $category_base, 0, 1 ) ) {
$category_base = substr( $category_base, 1 );
}
$category_base .= '/';
$expected = preg_replace( '`' . preg_quote( $category_base, '`' ) . '`u', '', $input, 1 );
$this->assertEquals( $expected, self::$class_instance->no_category_base( $input ) );
}
/**
* @covers WPSEO_Rewrite::query_vars
*/
public function test_query_vars() {
$this->assertEquals( array(), self::$class_instance->query_vars( array() ) );
$options = WPSEO_Options::get_all();
$options['stripcategorybase'] = true;
update_option( WPSEO_Option_Permalinks::get_instance()->option_name, $options );
$this->assertEquals( array( 'wpseo_category_redirect' ), self::$class_instance->query_vars( array() ) );
}
/**
* @covers WPSEO_Rewrite::request
*/
public function test_request() {
// @TODO find method to test redirects
}
/**
* @covers WPSEO_Rewrite::category_rewrite_rules
*/
public function test_category_rewrite_rules() {
$c = self::$class_instance;
$categories = get_categories( array( 'hide_empty' => false ) );
if ( false == is_multisite() ) {
$expected = array(
'(uncategorized)/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
'(uncategorized)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
'(uncategorized)/?$' => 'index.php?category_name=$matches[1]',
'$' => 'index.php?wpseo_category_redirect=$matches[1]',
);
} else {
$expected = array(
'blog/(uncategorized)/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
'blog/(uncategorized)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
'blog/(uncategorized)/?$' => 'index.php?category_name=$matches[1]',
);
global $wp_rewrite;
$old_base = trim( str_replace( '%category%', '(.+)', $wp_rewrite->get_category_permastruct() ), '/' );
$expected[ $old_base . '$' ] = 'index.php?wpseo_category_redirect=$matches[1]';
}
$this->assertEquals( $expected, $c->category_rewrite_rules() );
}
}