WordPress.org

Make WordPress Core

Changeset 35857


Ignore:
Timestamp:
12/11/2015 02:26:43 AM (4 years ago)
Author:
boonebgorges
Message:

Share fixtures in get_comment_link() tests.

See #30017.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/getCommentLink.php

    r35331 r35857  
    55 */
    66class Tests_Comment_GetCommentLink extends WP_UnitTestCase {
    7     protected $p;
    8     protected $comments = array();
     7    protected static $p;
     8    protected static $comments = array();
    99
    10     public function setUp() {
    11         parent::setUp();
     10    public static function wpSetUpBeforeClass( $factory ) {
     11        $now = time();
     12        self::$p = self::factory()->post->create();
    1213
    13         $now = time();
    14         $this->p = self::factory()->post->create();
    15         $this->comments[] = self::factory()->comment->create( array(
    16             'comment_post_ID' => $this->p,
     14        self::$comments[] = self::factory()->comment->create( array(
     15            'comment_post_ID' => self::$p,
    1716            'comment_content' => '1',
    1817            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    1918        ) );
    20         $this->comments[] = self::factory()->comment->create( array(
    21             'comment_post_ID' => $this->p,
     19        self::$comments[] = self::factory()->comment->create( array(
     20            'comment_post_ID' => self::$p,
    2221            'comment_content' => '2',
    2322            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    2423        ) );
    25         $this->comments[] = self::factory()->comment->create( array(
    26             'comment_post_ID' => $this->p,
     24        self::$comments[] = self::factory()->comment->create( array(
     25            'comment_post_ID' => self::$p,
    2726            'comment_content' => '3',
    2827            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    2928        ) );
    30         $this->comments[] = self::factory()->comment->create( array(
    31             'comment_post_ID' => $this->p,
     29        self::$comments[] = self::factory()->comment->create( array(
     30            'comment_post_ID' => self::$p,
    3231            'comment_content' => '4',
    3332            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
    3433        ) );
    35         $this->comments[] = self::factory()->comment->create( array(
    36             'comment_post_ID' => $this->p,
     34        self::$comments[] = self::factory()->comment->create( array(
     35            'comment_post_ID' => self::$p,
    3736            'comment_content' => '4',
    3837            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
    3938        ) );
    40         $this->comments[] = self::factory()->comment->create( array(
    41             'comment_post_ID' => $this->p,
     39        self::$comments[] = self::factory()->comment->create( array(
     40            'comment_post_ID' => self::$p,
    4241            'comment_content' => '4',
    4342            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 600 ),
    4443        ) );
     44
     45    }
     46
     47    public static function wpTearDownAfterClass() {
     48        foreach ( self::$comments as $c ) {
     49            wp_delete_comment( $c, true );
     50        }
     51
     52        wp_delete_post( self::$p );
    4553    }
    4654
     
    5361        update_option( 'comments_per_page', 2 );
    5462
    55         $found = get_comment_link( $this->comments[1] );
     63        $found = get_comment_link( self::$comments[1] );
    5664
    5765        $this->assertContains( 'cpage=3', $found );
     
    6674        update_option( 'comments_per_page', 2 );
    6775
    68         $found = get_comment_link( $this->comments[3] );
     76        $found = get_comment_link( self::$comments[3] );
    6977
    7078        $this->assertContains( 'cpage=2', $found );
     
    7987        update_option( 'comments_per_page', 2 );
    8088
    81         $found = get_comment_link( $this->comments[5] );
     89        $found = get_comment_link( self::$comments[5] );
    8290
    8391        $this->assertContains( 'cpage=1', $found );
     
    9199        update_option( 'comments_per_page', 2 );
    92100
    93         $found = get_comment_link( $this->comments[5] );
     101        $found = get_comment_link( self::$comments[5] );
    94102
    95103        $this->assertNotContains( 'cpage', $found );
     
    104112        update_option( 'comments_per_page', 2 );
    105113
    106         $found = get_comment_link( $this->comments[3] );
     114        $found = get_comment_link( self::$comments[3] );
    107115
    108116        $this->assertContains( 'cpage=2', $found );
     
    117125        update_option( 'comments_per_page', 2 );
    118126
    119         $found = get_comment_link( $this->comments[1] );
     127        $found = get_comment_link( self::$comments[1] );
    120128
    121129        $this->assertContains( 'cpage=3', $found );
Note: See TracChangeset for help on using the changeset viewer.