forked from habari/tests
/
test_comment.php
233 lines (199 loc) · 5.34 KB
/
test_comment.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
include 'bootstrap.php';
class CommentTest extends UnitTestCase
{
protected $comment;
protected $post_id;
protected $paramarray;
protected $user;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function module_setup()
{
$user = User::get_by_name( 'posts_test' );
if ( !$user ) {
$user = User::create( array (
'username'=>'posts_test',
'email'=>'posts_test@example.com',
'password'=>md5('q' . rand( 0,65535 ) ),
) );
}
$this->user = $user;
$post = Post::create( array(
'title' => 'Test Post',
'content' => 'These tests expect there to be at least one post.',
'user_id' => $user->id,
'status' => Post::status( 'published' ),
'content_type' => Post::type( 'entry' ),
) );
$this->post_id = $post->id;
$this->paramarray = array(
'id' => 'foofoo',
'post_id' => $this->post_id,
'name' => 'test',
'email' => 'test@example.org',
'url' => 'http://example.org',
'ip' => ip2long('127.0.0.1'),
'content' => 'test content',
'status' => Comment::STATUS_UNAPPROVED,
'date' => HabariDateTime::date_create(),
'type' => Comment::COMMENT
);
$this->comment = Comment::create( $this->paramarray );
}
protected function module_teardown()
{
if ( $this->comment instanceof Comment ) {
$this->comment->delete();
}
unset( $this->comment );
$posts = Posts::get( array( 'user_id' => $this->user->id ) );
foreach ( $posts as $post ) {
$post->delete();
}
$this->user->delete();
unset( $this->user );
}
public function test_create_comment()
{
$comment = Comment::create( $this->paramarray );
$id = DB::last_insert_id();
$this->assert_type( 'Comment', $comment );
foreach( $this->paramarray as $key => $val ) {
switch ( $key ) {
case 'id':
$this->assert_equal( $id, $comment->$key );
break;
default:
$this->assert_equal( $val, $comment->$key );
break;
}
}
$comment->delete();
}
public function test_update_comment()
{
$old_content = $this->comment->content;
$this->comment->content = 'updated test content';
$this->comment->update();
$updated_comment = Comment::get( $this->comment->id );
$this->assert_equal( $updated_comment->content, $this->comment->content );
$this->comment->content = $old_content;
$this->comment-> update();
// $updated_comment->delete();
}
public function test_get_comment()
{
$comment = Comment::get( $this->comment->id );
$this->assert_type( 'Comment', $comment );
$this->assert_equal( $comment->id, $this->comment->id );
}
public function test_delete_comment()
{
$comment = Comment::create( $this->paramarray );
$id = $comment->id;
$comment->delete();
$this->assert_false( Comment::get( $id ) );
}
public function test__get()
{
$this->assert_type( 'Post', $this->comment->post, 'Expected Post. Received ' . get_class( $this->comment->post ) );
$this->assert_equal( $this->comment->post->id, $this->post_id );
$this->assert_equal( $this->comment->statusname, 'unapproved' );
$this->assert_equal( $this->comment->typename, 'comment' );
$this->assert_equal( $this->comment->editlink, URL::get( 'admin', "page=comment&id={$this->comment->id}" ) );
$this->assert_type( 'CommentInfo', $this->comment->info );
}
/**
* @todo Implement test__set().
*/
public function test__set()
{
}
public function test_commentinfo()
{
// make sure adding info to comment works
$this->comment->info->test = 'test';
$this->assert_equal( 'test', $this->comment->info->test );
$this->comment->update();
$test_comment = Comment::get( $this->comment->id );
$this->assert_equal( $this->comment->info->test, $test_comment->info->test );
unset( $test_comment );
// make sure construction works with info
$new_comment = new Comment();
$this->assert_type( 'CommentInfo', $new_comment->info );
$this->assert_false( $new_comment->info->is_key_set() );
$new_comment->info->test = 'test';
$new_comment->insert();
$this->assert_true( $new_comment->info->is_key_set() );
$test_comment = Comment::get( $new_comment->id );
$this->assert_equal( $new_comment->info->test, $test_comment->info->test );
$new_comment->delete();
unset( $test_comment );
}
/**
* @todo Implement test_list_comment_types().
*/
public function test_list_comment_types()
{
}
/**
* @todo Implement test_list_comment_statuses().
*/
public function test_list_comment_statuses()
{
}
public function test_status_action()
{
$comment_status_actions = array(
Comment::STATUS_UNAPPROVED => _t( 'Unapprove' ),
Comment::STATUS_APPROVED => _t( 'Approve' ),
Comment::STATUS_SPAM => _t( 'Spam' ),
);
foreach ( $comment_status_actions as $status => $action ) {
$this->assert_equal( $action, Comment::status_action( $status ) );
}
}
/**
* @todo Implement test_status().
*/
public function test_status()
{
}
/**
* @todo Implement test_status_name().
*/
public function test_status_name()
{
}
/**
* @todo Implement test_type().
*/
public function test_type()
{
}
/**
* @todo Implement test_type_name().
*/
public function test_type_name()
{
}
/**
* @todo Implement test_content_type().
*/
public function test_content_type()
{
}
/**
* @todo Implement test_get_access().
*/
public function test_get_access()
{
}
}
CommentTest::run_one( 'CommentTest' );
?>