Ticket #11882: 11882_tests.patch

File 11882_tests.patch, 1.7 KB (added by jgadbois, 22 months ago)

Unit tests

  • wp-testcase/test_admin_includes_comment.php

     
     1<?php 
     2class TestAdminComments extends _WPEmptyBlog { 
     3        function setUp() { 
     4                parent::setUp(); 
     5                $this->author_id = $this->_make_user('editor'); 
     6                _set_cron_array(array()); 
     7                $this->post_ids = array(); 
     8   } 
     9 
     10   function tearDown() { 
     11                parent::tearDown(); 
     12 
     13                foreach ($this->post_ids as $id) 
     14                        wp_delete_post($id); 
     15                wp_delete_user( $this->author_id ); 
     16   } 
     17 
     18   function test_get_pending_comments_num() { 
     19      // create a couple of posts 
     20                $post = array( 
     21                        'post_author' => $this->author_id, 
     22                        'post_status' => 'publish', 
     23                        'post_content' => rand_str(), 
     24                        'post_title' => rand_str(), 
     25                ); 
     26 
     27                // insert a post and make sure the ID is ok 
     28                $post1 = $this->post_ids[] = wp_insert_post($post); 
     29                $post2 = $this->post_ids[] = wp_insert_post($post); 
     30                $post3 = $this->post_ids[] = wp_insert_post($post); 
     31 
     32      // add a pending comment to post1 
     33      $commentdata = array('comment_approved'=>0, 'comment_post_ID'=>$post1, 'comment_content'=>rand_str()); 
     34      wp_insert_comment($commentdata); 
     35 
     36      // add an approved comment to $post2 
     37      $commentdata = array('comment_approved'=>1, 'comment_post_ID'=>$post1, 'comment_content'=>rand_str()); 
     38      wp_insert_comment($commentdata); 
     39 
     40      $this->assertEquals(1, get_pending_comments_num($post1)); 
     41      $this->assertEquals(0, get_pending_comments_num($post2)); 
     42      $this->assertEquals(0, get_pending_comments_num($post3)); // no pending comments or comments 
     43   } 
     44} 
     45?>