forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTermLink.php
More file actions
144 lines (112 loc) · 3.61 KB
/
getTermLink.php
File metadata and controls
144 lines (112 loc) · 3.61 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* @group taxonomy
*/
class Tests_Term_GetTermLink extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
register_taxonomy( 'wptests_tax', 'post' );
}
public function test_integer_should_be_interpreted_as_term_id() {
$t1 = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax',
'name' => 'foo',
) );
$t2 = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax',
'slug' => $t1,
) );
$term = intval( $t1 );
$actual = get_term_link( $term, 'wptests_tax' );
$this->assertContains( 'wptests_tax=foo', $actual );
}
public function test_numeric_string_should_be_interpreted_as_term_slug() {
$t1 = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax',
'name' => 'foo',
) );
$t2 = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax',
'slug' => $t1,
) );
$term = (string) $t1;
$actual = get_term_link( $term, 'wptests_tax' );
$this->assertContains( 'wptests_tax=' . $term, $actual );
}
public function test_invalid_term_should_return_wp_error() {
$actual = get_term_link( 'foo', 'wptests_tax' );
$this->assertWPError( $actual );
}
public function test_category_should_use_cat_query_var_with_term_id() {
$c = self::factory()->category->create();
$actual = get_term_link( $c, 'category' );
$this->assertContains( 'cat=' . $c, $actual );
}
public function test_taxonomy_with_query_var_should_use_that_query_var_with_term_slug() {
register_taxonomy( 'wptests_tax2', 'post', array(
'query_var' => 'foo',
) );
$t = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax2',
'slug' => 'bar',
) );
$actual = get_term_link( $t, 'wptests_tax2' );
$this->assertContains( 'foo=bar', $actual );
}
public function test_taxonomy_without_query_var_should_use_taxonomy_query_var_and_term_query_var_with_term_slug() {
register_taxonomy( 'wptests_tax2', 'post', array(
'query_var' => false,
) );
$t = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax2',
'slug' => 'bar',
) );
$actual = get_term_link( $t, 'wptests_tax2' );
$this->assertContains( 'taxonomy=wptests_tax2', $actual );
$this->assertContains( 'term=bar', $actual );
}
public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
register_taxonomy( 'wptests_tax2', 'post', array(
'hierarchical' => true,
'rewrite' => array(
'slug' => 'foo',
'hierarchical' => true,
),
) );
flush_rewrite_rules();
$t1 = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax2',
'slug' => 'term1',
) );
$t2 = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax2',
'slug' => 'term2',
'parent' => $t1,
) );
$actual = get_term_link( $t2, 'wptests_tax2' );
$this->assertContains( '/foo/term1/term2/', $actual );
}
public function test_taxonomy_permastruct_with_nonhierarchical_rewrite_should_not_put_term_ancestors_in_link() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
register_taxonomy( 'wptests_tax2', 'post', array(
'hierarchical' => true,
'rewrite' => array(
'slug' => 'foo',
'hierarchical' => false,
),
) );
flush_rewrite_rules();
$t1 = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax2',
'slug' => 'term1',
) );
$t2 = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax2',
'slug' => 'term2',
'parent' => $t1,
) );
$actual = get_term_link( $t2, 'wptests_tax2' );
$this->assertContains( '/foo/term2/', $actual );
}
}