Changeset 35173 for trunk/tests/phpunit/tests/comment.php
- Timestamp:
- 10/15/2015 12:38:26 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/comment.php
r34623 r35173 5 5 */ 6 6 class Tests_Comment extends WP_UnitTestCase { 7 protected static $user_id; 8 protected static $post_id; 9 10 public static function setUpBeforeClass() { 11 parent::setUpBeforeClass(); 12 13 $factory = new WP_UnitTest_Factory(); 14 15 self::$user_id = $factory->user->create(); 16 self::$post_id = $factory->post->create( array( 17 'post_author' => self::$user_id 18 ) ); 19 20 self::commit_transaction(); 21 } 22 7 23 function test_wp_update_comment() { 8 24 $post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post' ) ); … … 24 40 */ 25 41 function test_wp_update_comment_updates_comment_type() { 26 $post_id = $this->factory->post->create(); 27 $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) ); 42 $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => self::$post_id ) ); 28 43 29 44 wp_update_comment( array( 'comment_ID' => $comment_id, 'comment_type' => 'pingback' ) ); … … 37 52 */ 38 53 function test_wp_update_comment_updates_user_id() { 39 $post_id = $this->factory->post->create(); 40 $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) ); 54 $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => self::$post_id ) ); 41 55 42 56 wp_update_comment( array( 'comment_ID' => $comment_id, 'user_id' => 1 ) ); … … 47 61 48 62 public function test_get_approved_comments() { 49 $p = $this->factory->post->create(); 50 $ca1 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1' ) ); 51 $ca2 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1' ) ); 52 $ca3 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '0' ) ); 53 $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); 54 $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); 55 $c4 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); 56 $c5 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); 57 58 $found = get_approved_comments( $p ); 63 $ca1 = $this->factory->comment->create( array( 64 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' 65 ) ); 66 $ca2 = $this->factory->comment->create( array( 67 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' 68 ) ); 69 $ca3 = $this->factory->comment->create( array( 70 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' 71 ) ); 72 $c2 = $this->factory->comment->create( array( 73 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' 74 ) ); 75 $c3 = $this->factory->comment->create( array( 76 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' 77 ) ); 78 $c4 = $this->factory->comment->create( array( 79 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' 80 ) ); 81 $c5 = $this->factory->comment->create( array( 82 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' 83 ) ); 84 85 $found = get_approved_comments( self::$post_id ); 59 86 60 87 // all comments types will be returned … … 66 93 */ 67 94 public function test_get_approved_comments_with_post_id_0_should_return_empty_array() { 68 $p = $this->factory->post->create(); 69 $ca1 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1' ) ); 95 $ca1 = $this->factory->comment->create( array( 96 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' 97 ) ); 70 98 71 99 $found = get_approved_comments( 0 ); … … 78 106 */ 79 107 public function test_wp_new_comment_respects_dates() { 80 $u = $this->factory->user->create(); 81 $post_id = $this->factory->post->create( array( 'post_author' => $u ) ); 82 83 $data = array( 84 'comment_post_ID' => $post_id, 108 $data = array( 109 'comment_post_ID' => self::$post_id, 85 110 'comment_author' => rand_str(), 86 111 'comment_author_url' => '', … … 104 129 */ 105 130 public function test_wp_new_comment_respects_author_ip() { 106 $u = $this->factory->user->create(); 107 $post_id = $this->factory->post->create( array( 'post_author' => $u ) ); 108 109 $data = array( 110 'comment_post_ID' => $post_id, 131 $data = array( 132 'comment_post_ID' => self::$post_id, 111 133 'comment_author' => rand_str(), 112 134 'comment_author_IP' => '192.168.1.1', … … 128 150 */ 129 151 public function test_wp_new_comment_respects_author_ip_empty_string() { 130 $u = $this->factory->user->create(); 131 $post_id = $this->factory->post->create( array( 'post_author' => $u ) ); 132 133 $data = array( 134 'comment_post_ID' => $post_id, 152 $data = array( 153 'comment_post_ID' => self::$post_id, 135 154 'comment_author' => rand_str(), 136 155 'comment_author_IP' => '', … … 152 171 */ 153 172 public function test_wp_new_comment_respects_comment_agent() { 154 $u = $this->factory->user->create(); 155 $post_id = $this->factory->post->create( array( 'post_author' => $u ) ); 156 157 $data = array( 158 'comment_post_ID' => $post_id, 173 $data = array( 174 'comment_post_ID' => self::$post_id, 159 175 'comment_author' => rand_str(), 160 176 'comment_author_IP' => '', … … 177 193 */ 178 194 public function test_wp_new_comment_should_trim_provided_comment_agent_to_254_chars() { 179 $u = $this->factory->user->create(); 180 $post_id = $this->factory->post->create( array( 'post_author' => $u ) ); 181 182 $data = array( 183 'comment_post_ID' => $post_id, 195 $data = array( 196 'comment_post_ID' => self::$post_id, 184 197 'comment_author' => rand_str(), 185 198 'comment_author_IP' => '', … … 202 215 */ 203 216 public function test_wp_new_comment_respects_comment_agent_empty_string() { 204 $u = $this->factory->user->create(); 205 $post_id = $this->factory->post->create( array( 'post_author' => $u ) ); 206 207 $data = array( 208 'comment_post_ID' => $post_id, 217 $data = array( 218 'comment_post_ID' => self::$post_id, 209 219 'comment_author' => rand_str(), 210 220 'comment_author_IP' => '', … … 225 235 226 236 public function test_comment_field_lengths() { 227 $u = $this->factory->user->create(); 228 $post_id = $this->factory->post->create( array( 'post_author' => $u ) ); 229 230 $data = array( 231 'comment_post_ID' => $post_id, 237 $data = array( 238 'comment_post_ID' => self::$post_id, 232 239 'comment_author' => rand_str(), 233 240 'comment_author_url' => '', … … 265 272 */ 266 273 public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_has_been_marked_as_spam() { 267 $p = $this->factory->post->create();268 274 $c = $this->factory->comment->create( array( 269 'comment_post_ID' => $p,275 'comment_post_ID' => self::$post_id, 270 276 'comment_approved' => 'spam', 271 277 ) ); … … 294 300 */ 295 301 public function test_wp_comment_get_children_should_fill_children() { 296 297 $p = $this->factory->post->create();298 299 302 $c1 = $this->factory->comment->create( array( 300 'comment_post_ID' => $p,303 'comment_post_ID' => self::$post_id, 301 304 'comment_approved' => '1', 302 305 ) ); 303 306 304 307 $c2 = $this->factory->comment->create( array( 305 'comment_post_ID' => $p,308 'comment_post_ID' => self::$post_id, 306 309 'comment_approved' => '1', 307 310 'comment_parent' => $c1, … … 309 312 310 313 $c3 = $this->factory->comment->create( array( 311 'comment_post_ID' => $p,314 'comment_post_ID' => self::$post_id, 312 315 'comment_approved' => '1', 313 316 'comment_parent' => $c2, … … 315 318 316 319 $c4 = $this->factory->comment->create( array( 317 'comment_post_ID' => $p,320 'comment_post_ID' => self::$post_id, 318 321 'comment_approved' => '1', 319 322 'comment_parent' => $c1, … … 321 324 322 325 $c5 = $this->factory->comment->create( array( 323 'comment_post_ID' => $p,326 'comment_post_ID' => self::$post_id, 324 327 'comment_approved' => '1', 325 328 ) ); 326 329 327 330 $c6 = $this->factory->comment->create( array( 328 'comment_post_ID' => $p,331 'comment_post_ID' => self::$post_id, 329 332 'comment_approved' => '1', 330 333 'comment_parent' => $c5, … … 345 348 */ 346 349 public function test_post_properties_should_be_lazyloaded() { 347 $p = $this->factory->post->create(); 348 349 $c = $this->factory->comment->create( array( 'comment_post_ID' => $p ) ); 350 351 $post = get_post( $p ); 350 $c = $this->factory->comment->create( array( 'comment_post_ID' => self::$post_id ) ); 351 352 $post = get_post( self::$post_id ); 352 353 $comment = get_comment( $c ); 353 354
Note: See TracChangeset
for help on using the changeset viewer.