forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-term-factories.php
110 lines (101 loc) · 3.1 KB
/
test-timber-term-factories.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
<?php
/**
* @group terms-api
*/
class TestTimberTermFactories extends Timber_UnitTestCase
{
public function set_up()
{
$this->truncate('term_relationships');
$this->truncate('term_taxonomy');
$this->truncate('terms');
$this->truncate('termmeta');
parent::set_up();
}
public function testGetTerm()
{
$term_id = $this->factory->term->create([
'name' => 'Thingo',
'taxonomy' => 'post_tag',
]);
$term = Timber::get_term($term_id);
$this->assertEquals('Thingo', $term->name);
}
/**
* @expectedDeprecated Term::from()
*/
public function testGetMultiTerm()
{
register_taxonomy('cars', 'post');
$term_ids[] = $this->factory->term->create([
'name' => 'Toyota',
'taxonomy' => 'cars',
]);
$term_ids[] = $this->factory->term->create([
'name' => 'Honda',
'taxonomy' => 'cars',
]);
$term_ids[] = $this->factory->term->create([
'name' => 'Chevy',
'taxonomy' => 'cars',
]);
$post_id = $this->factory->post->create();
wp_set_object_terms($post_id, $term_ids, 'cars');
$term_get = Timber::get_terms([
'taxonomy' => 'cars',
]);
$this->assertEquals('Chevy', $term_get[0]->title());
$terms_from = Timber\Term::from(get_terms([
'taxonomy' => 'cars',
]), 'cars');
$this->assertEquals('Chevy', $terms_from[0]->title());
}
/**
* @expectedDeprecated Term::from()
*/
public function testTermFrom()
{
register_taxonomy('baseball', ['post']);
register_taxonomy('hockey', ['post']);
$term_id = $this->factory->term->create([
'name' => 'Rangers',
'taxonomy' => 'baseball',
]);
$term_id = $this->factory->term->create([
'name' => 'Cardinals',
'taxonomy' => 'baseball',
]);
$term_id = $this->factory->term->create([
'name' => 'Rangers',
'taxonomy' => 'hockey',
]);
$baseball_teams = Timber\Term::from(get_terms([
'taxonomy' => 'baseball',
'hide_empty' => false,
]), 'baseball');
$this->assertSame(2, count($baseball_teams));
$this->assertEquals('Cardinals', $baseball_teams[0]->name);
}
/**
* @expectedDeprecated Term::from()
*/
public function testGetSingleTermFrom()
{
register_taxonomy('cars', 'post');
$term_id = $this->factory->term->create([
'name' => 'Toyota',
'taxonomy' => 'cars',
]);
$post_id = $this->factory->post->create();
wp_set_object_terms($post_id, $term_id, 'cars');
$term_from = Timber\Term::from(get_terms([
'taxonomy' => 'cars',
'hide_empty' => false,
]), 'cars');
$this->assertEquals($term_id, $term_from[0]->ID);
$term_get = Timber::get_term([
'taxonomy' => 'cars',
]);
$this->assertEquals($term_id, $term_get->ID);
}
}