forked from habari/tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_tag.php
118 lines (102 loc) · 3.48 KB
/
test_tag.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
114
115
116
117
118
<?php
include 'bootstrap.php';
class TagTest extends UnitTestCase
{
private $text = 'Test Tag';
private $slug;
private $tag;
public function setup()
{
$this->slug = Utils::slugify( $this->text );
$this->tag = new Tag( array( 'term_display' => $this->text, 'term' => $this->slug ) );
}
public function teardown()
{
unset( $this->tag );
}
public function test_construct_tag()
{
// Create a tag from a parameter array
$params = array(
'term' => $this->slug,
'term_display' => $this->text,
);
$t = new Tag($params);
$this->assert_type('Tag', $t, 'Result should be of type Tag');
$this->assert_equal($this->slug, $t->term, 'The slug should equal the slug value passed in.' );
$this->assert_equal($this->text, $t->term_display, 'The text should equal the text value passed in.' );
}
public function test_create_tag()
{
$t = Tag::create( array( 'term_display' => $this->text, 'term' => $this->slug ) );
$this->assert_type( 'Tag', $t );
// Check the tag's id is set.
$this->assert_true((int)$t->id > 0, 'The Tag id should be greater than zero');
$this->assert_equal($this->slug, $t->term, 'The slug should equal the slug value passed in.' );
$this->assert_equal($this->text, $t->term_display, 'The text should equal the text value passed in.' );
$this->assert_true( (int)$t->mptt_left > 0, 'The Tag mptt_left should be greater than zero' );
$this->assert_true( (int)$t->mptt_right > 0, 'The Tag mptt_right should be greater than zero' );
Tags::vocabulary()->delete_term( $t );
}
public function test_insert_tag()
{
$count = Tags::vocabulary()->count_total();
$res = Tags::vocabulary()->add_term( $this->tag );
if ( $res ) {
$this->assert_type( 'Tag', $res );
$this->assert_equal( $count + 1, Tags::vocabulary()->count_total() );
// Dies on PHP versions with the PDO bug if you try to get the tag as a Tag
$t = Tags::vocabulary()->get_term( $this->text );
// Settle for testing for a Term
$this->assert_type( 'Term', $t );
$this->assert_equal( $this->text, $t->term_display, $this->text . ' is not the same as ' . $t->term_display );
Tags::vocabulary()->delete_term( $t );
}
else {
$this->assert_equal( $res, FALSE );
}
}
public function test_update_tag()
{
Tags::vocabulary()->add_term( $this->tag );
$t = Tags::vocabulary()->get_term( $this->tag->term_display );
$t->term_display = 'Updated Test Tag';
$t->update();
$new_tag = Tags::vocabulary()->get_term( $t->id );
$this->assert_equal( $new_tag->term_display, $t->term_display );
Tags::vocabulary()->delete_term( $t );
}
public function test_delete_tag()
{
$count = Tags::vocabulary()->count_total();
$t = Tags::vocabulary()->add_term( $this->tag );
$this->assert_equal( $count + 1, Tags::vocabulary()->count_total() );
Tags::vocabulary()->delete_term( $t );
$this->assert_equal( $count, Tags::vocabulary()->count_total() );
}
public function test_get_tag()
{
Tags::vocabulary()->add_term( $this->tag );
// Get tag by text
$t = Tags::vocabulary()->get_term( $this->text );
$this->assert_equal( $t->term_display, $this->tag->term_display );
// Get tag by id
$t = Tags::vocabulary()->get_term( $t->id );
$this->assert_equal( $t->term_display, $this->tag->term_display );
Tags::vocabulary()->delete_term( $t );
}
/*
* @todo Implement test_attach_tag_to_post
*/
public function test_attach_tag_to_post()
{
}
/*
* @todo Implement test_detach_tag_from_post
*/
public function test_detach_tag_from_post()
{
}
}
TagTest::run_one( 'TagTest' );
?>