forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpTerm.php
More file actions
92 lines (72 loc) · 1.9 KB
/
wpTerm.php
File metadata and controls
92 lines (72 loc) · 1.9 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
<?php
/**
* @group taxonomy
*/
class Tests_Term_WpTerm extends WP_UnitTestCase {
protected static $term_id;
public function setUp() {
parent::setUp();
register_taxonomy( 'wptests_tax', 'post' );
}
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
global $wpdb;
register_taxonomy( 'wptests_tax', 'post' );
// Ensure that there is a term with ID 1.
if ( ! get_term( 1 ) ) {
$wpdb->insert(
$wpdb->terms,
array(
'term_id' => 1,
)
);
$wpdb->insert(
$wpdb->term_taxonomy,
array(
'term_id' => 1,
'taxonomy' => 'wptests_tax',
)
);
clean_term_cache( 1, 'wptests_tax' );
}
self::$term_id = $factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
}
/**
* @ticket 37738
*/
public function test_get_instance_should_work_for_numeric_string() {
$found = WP_Term::get_instance( (string) self::$term_id );
$this->assertSame( self::$term_id, $found->term_id );
}
/**
* @ticket 37738
*/
public function test_get_instance_should_fail_for_negative_number() {
$found = WP_Term::get_instance( -self::$term_id );
$this->assertFalse( $found );
}
/**
* @ticket 37738
*/
public function test_get_instance_should_fail_for_non_numeric_string() {
$found = WP_Term::get_instance( 'abc' );
$this->assertFalse( $found );
}
/**
* @ticket 37738
*/
public function test_get_instance_should_succeed_for_float_that_is_equal_to_post_id() {
$found = WP_Term::get_instance( 1.0 );
$this->assertSame( 1, $found->term_id );
}
/**
* @ticket 40671
*/
public function test_get_instance_should_respect_taxonomy_when_term_id_is_found_in_cache() {
global $wpdb;
register_taxonomy( 'wptests_tax2', 'post' );
// Ensure that cache is primed.
WP_Term::get_instance( self::$term_id, 'wptests_tax' );
$found = WP_Term::get_instance( self::$term_id, 'wptests_tax2' );
$this->assertFalse( $found );
}
}