WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/17/2015 06:02:16 PM (6 years ago)
Author:
wonderboymusic
Message:

Unit Tests: after [35225], make factory a method/getter on WP_UnitTestCase and add magic methods for BC for every plugin that is extending WP_UnitTestCase and accessing the $factory instance prop.

Props nerrad, wonderboymusic.
See #30017, #33968.

File:
1 edited

Legend:

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

    r35225 r35242  
    1313    public function test_should_respect_comment_order_asc_when_default_comments_page_is_newest() {
    1414        $now = time();
    15         $p = self::$factory->post->create();
    16         $comment_1 = self::$factory->comment->create( array(
    17             'comment_post_ID' => $p,
    18             'comment_content' => '1',
    19             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    20         ) );
    21         $comment_2 = self::$factory->comment->create( array(
     15        $p = self::factory()->post->create();
     16        $comment_1 = self::factory()->comment->create( array(
     17            'comment_post_ID' => $p,
     18            'comment_content' => '1',
     19            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     20        ) );
     21        $comment_2 = self::factory()->comment->create( array(
    2222            'comment_post_ID' => $p,
    2323            'comment_content' => '2',
     
    4343    public function test_should_respect_comment_order_desc_when_default_comments_page_is_newest() {
    4444        $now = time();
    45         $p = self::$factory->post->create();
    46         $comment_1 = self::$factory->comment->create( array(
    47             'comment_post_ID' => $p,
    48             'comment_content' => '1',
    49             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    50         ) );
    51         $comment_2 = self::$factory->comment->create( array(
     45        $p = self::factory()->post->create();
     46        $comment_1 = self::factory()->comment->create( array(
     47            'comment_post_ID' => $p,
     48            'comment_content' => '1',
     49            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     50        ) );
     51        $comment_2 = self::factory()->comment->create( array(
    5252            'comment_post_ID' => $p,
    5353            'comment_content' => '2',
     
    7373    public function test_should_respect_comment_order_asc_when_default_comments_page_is_oldest() {
    7474        $now = time();
    75         $p = self::$factory->post->create();
    76         $comment_1 = self::$factory->comment->create( array(
    77             'comment_post_ID' => $p,
    78             'comment_content' => '1',
    79             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    80         ) );
    81         $comment_2 = self::$factory->comment->create( array(
     75        $p = self::factory()->post->create();
     76        $comment_1 = self::factory()->comment->create( array(
     77            'comment_post_ID' => $p,
     78            'comment_content' => '1',
     79            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     80        ) );
     81        $comment_2 = self::factory()->comment->create( array(
    8282            'comment_post_ID' => $p,
    8383            'comment_content' => '2',
     
    103103    public function test_should_respect_comment_order_desc_when_default_comments_page_is_oldest() {
    104104        $now = time();
    105         $p = self::$factory->post->create();
    106         $comment_1 = self::$factory->comment->create( array(
    107             'comment_post_ID' => $p,
    108             'comment_content' => '1',
    109             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    110         ) );
    111         $comment_2 = self::$factory->comment->create( array(
     105        $p = self::factory()->post->create();
     106        $comment_1 = self::factory()->comment->create( array(
     107            'comment_post_ID' => $p,
     108            'comment_content' => '1',
     109            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     110        ) );
     111        $comment_2 = self::factory()->comment->create( array(
    112112            'comment_post_ID' => $p,
    113113            'comment_content' => '2',
     
    133133    public function test_should_respect_comment_order_asc_when_default_comments_page_is_newest_on_subsequent_pages() {
    134134        $now = time();
    135         $p = self::$factory->post->create();
    136         $comment_1 = self::$factory->comment->create( array(
    137             'comment_post_ID' => $p,
    138             'comment_content' => '1',
    139             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    140         ) );
    141         $comment_2 = self::$factory->comment->create( array(
    142             'comment_post_ID' => $p,
    143             'comment_content' => '2',
    144             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    145         ) );
    146         $comment_3 = self::$factory->comment->create( array(
    147             'comment_post_ID' => $p,
    148             'comment_content' => '3',
    149             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    150         ) );
    151         $comment_4 = self::$factory->comment->create( array(
     135        $p = self::factory()->post->create();
     136        $comment_1 = self::factory()->comment->create( array(
     137            'comment_post_ID' => $p,
     138            'comment_content' => '1',
     139            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     140        ) );
     141        $comment_2 = self::factory()->comment->create( array(
     142            'comment_post_ID' => $p,
     143            'comment_content' => '2',
     144            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     145        ) );
     146        $comment_3 = self::factory()->comment->create( array(
     147            'comment_post_ID' => $p,
     148            'comment_content' => '3',
     149            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     150        ) );
     151        $comment_4 = self::factory()->comment->create( array(
    152152            'comment_post_ID' => $p,
    153153            'comment_content' => '4',
    154154            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
    155155        ) );
    156         $comment_5 = self::$factory->comment->create( array(
     156        $comment_5 = self::factory()->comment->create( array(
    157157            'comment_post_ID' => $p,
    158158            'comment_content' => '3',
    159159            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
    160160        ) );
    161         $comment_6 = self::$factory->comment->create( array(
     161        $comment_6 = self::factory()->comment->create( array(
    162162            'comment_post_ID' => $p,
    163163            'comment_content' => '4',
     
    188188    public function test_should_respect_comment_order_desc_when_default_comments_page_is_newest_on_subsequent_pages() {
    189189        $now = time();
    190         $p = self::$factory->post->create();
    191         $comment_1 = self::$factory->comment->create( array(
    192             'comment_post_ID' => $p,
    193             'comment_content' => '1',
    194             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    195         ) );
    196         $comment_2 = self::$factory->comment->create( array(
    197             'comment_post_ID' => $p,
    198             'comment_content' => '2',
    199             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    200         ) );
    201         $comment_3 = self::$factory->comment->create( array(
    202             'comment_post_ID' => $p,
    203             'comment_content' => '3',
    204             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    205         ) );
    206         $comment_4 = self::$factory->comment->create( array(
     190        $p = self::factory()->post->create();
     191        $comment_1 = self::factory()->comment->create( array(
     192            'comment_post_ID' => $p,
     193            'comment_content' => '1',
     194            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     195        ) );
     196        $comment_2 = self::factory()->comment->create( array(
     197            'comment_post_ID' => $p,
     198            'comment_content' => '2',
     199            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     200        ) );
     201        $comment_3 = self::factory()->comment->create( array(
     202            'comment_post_ID' => $p,
     203            'comment_content' => '3',
     204            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     205        ) );
     206        $comment_4 = self::factory()->comment->create( array(
    207207            'comment_post_ID' => $p,
    208208            'comment_content' => '4',
    209209            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
    210210        ) );
    211         $comment_5 = self::$factory->comment->create( array(
     211        $comment_5 = self::factory()->comment->create( array(
    212212            'comment_post_ID' => $p,
    213213            'comment_content' => '3',
    214214            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
    215215        ) );
    216         $comment_6 = self::$factory->comment->create( array(
     216        $comment_6 = self::factory()->comment->create( array(
    217217            'comment_post_ID' => $p,
    218218            'comment_content' => '4',
     
    243243    public function test_should_respect_comment_order_asc_when_default_comments_page_is_oldest_on_subsequent_pages() {
    244244        $now = time();
    245         $p = self::$factory->post->create();
    246         $comment_1 = self::$factory->comment->create( array(
    247             'comment_post_ID' => $p,
    248             'comment_content' => '1',
    249             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    250         ) );
    251         $comment_2 = self::$factory->comment->create( array(
    252             'comment_post_ID' => $p,
    253             'comment_content' => '2',
    254             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    255         ) );
    256         $comment_3 = self::$factory->comment->create( array(
    257             'comment_post_ID' => $p,
    258             'comment_content' => '3',
    259             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    260         ) );
    261         $comment_4 = self::$factory->comment->create( array(
     245        $p = self::factory()->post->create();
     246        $comment_1 = self::factory()->comment->create( array(
     247            'comment_post_ID' => $p,
     248            'comment_content' => '1',
     249            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     250        ) );
     251        $comment_2 = self::factory()->comment->create( array(
     252            'comment_post_ID' => $p,
     253            'comment_content' => '2',
     254            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     255        ) );
     256        $comment_3 = self::factory()->comment->create( array(
     257            'comment_post_ID' => $p,
     258            'comment_content' => '3',
     259            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     260        ) );
     261        $comment_4 = self::factory()->comment->create( array(
    262262            'comment_post_ID' => $p,
    263263            'comment_content' => '4',
     
    288288    public function test_should_respect_comment_order_desc_when_default_comments_page_is_oldest_on_subsequent_pages() {
    289289        $now = time();
    290         $p = self::$factory->post->create();
    291         $comment_1 = self::$factory->comment->create( array(
    292             'comment_post_ID' => $p,
    293             'comment_content' => '1',
    294             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    295         ) );
    296         $comment_2 = self::$factory->comment->create( array(
    297             'comment_post_ID' => $p,
    298             'comment_content' => '2',
    299             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    300         ) );
    301         $comment_3 = self::$factory->comment->create( array(
    302             'comment_post_ID' => $p,
    303             'comment_content' => '3',
    304             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    305         ) );
    306         $comment_4 = self::$factory->comment->create( array(
     290        $p = self::factory()->post->create();
     291        $comment_1 = self::factory()->comment->create( array(
     292            'comment_post_ID' => $p,
     293            'comment_content' => '1',
     294            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     295        ) );
     296        $comment_2 = self::factory()->comment->create( array(
     297            'comment_post_ID' => $p,
     298            'comment_content' => '2',
     299            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     300        ) );
     301        $comment_3 = self::factory()->comment->create( array(
     302            'comment_post_ID' => $p,
     303            'comment_content' => '3',
     304            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     305        ) );
     306        $comment_4 = self::factory()->comment->create( array(
    307307            'comment_post_ID' => $p,
    308308            'comment_content' => '4',
     
    335335    public function test_last_page_of_comments_should_be_full_when_default_comment_page_is_newest() {
    336336        $now = time();
    337         $p = self::$factory->post->create();
    338         $comment_1 = self::$factory->comment->create( array(
    339             'comment_post_ID' => $p,
    340             'comment_content' => '1',
    341             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    342         ) );
    343         $comment_2 = self::$factory->comment->create( array(
    344             'comment_post_ID' => $p,
    345             'comment_content' => '2',
    346             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    347         ) );
    348         $comment_3 = self::$factory->comment->create( array(
     337        $p = self::factory()->post->create();
     338        $comment_1 = self::factory()->comment->create( array(
     339            'comment_post_ID' => $p,
     340            'comment_content' => '1',
     341            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     342        ) );
     343        $comment_2 = self::factory()->comment->create( array(
     344            'comment_post_ID' => $p,
     345            'comment_content' => '2',
     346            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     347        ) );
     348        $comment_3 = self::factory()->comment->create( array(
    349349            'comment_post_ID' => $p,
    350350            'comment_content' => '3',
     
    377377    public function test_first_page_of_comments_should_have_remainder_when_default_comments_page_is_newest() {
    378378        $now = time();
    379         $p = self::$factory->post->create();
    380         $comment_1 = self::$factory->comment->create( array(
    381             'comment_post_ID' => $p,
    382             'comment_content' => '1',
    383             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    384         ) );
    385         $comment_2 = self::$factory->comment->create( array(
    386             'comment_post_ID' => $p,
    387             'comment_content' => '2',
    388             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    389         ) );
    390         $comment_3 = self::$factory->comment->create( array(
     379        $p = self::factory()->post->create();
     380        $comment_1 = self::factory()->comment->create( array(
     381            'comment_post_ID' => $p,
     382            'comment_content' => '1',
     383            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     384        ) );
     385        $comment_2 = self::factory()->comment->create( array(
     386            'comment_post_ID' => $p,
     387            'comment_content' => '2',
     388            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     389        ) );
     390        $comment_3 = self::factory()->comment->create( array(
    391391            'comment_post_ID' => $p,
    392392            'comment_content' => '3',
     
    417417    public function test_comment_permalinks_should_be_correct_when_using_default_display_callback_with_default_comment_page_oldest() {
    418418        $now = time();
    419         $p = self::$factory->post->create();
    420         $comment_1 = self::$factory->comment->create( array(
    421             'comment_post_ID' => $p,
    422             'comment_content' => '1',
    423             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    424         ) );
    425         $comment_2 = self::$factory->comment->create( array(
    426             'comment_post_ID' => $p,
    427             'comment_content' => '2',
    428             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    429         ) );
    430         $comment_3 = self::$factory->comment->create( array(
    431             'comment_post_ID' => $p,
    432             'comment_content' => '3',
    433             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    434         ) );
    435         $comment_4 = self::$factory->comment->create( array(
     419        $p = self::factory()->post->create();
     420        $comment_1 = self::factory()->comment->create( array(
     421            'comment_post_ID' => $p,
     422            'comment_content' => '1',
     423            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     424        ) );
     425        $comment_2 = self::factory()->comment->create( array(
     426            'comment_post_ID' => $p,
     427            'comment_content' => '2',
     428            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     429        ) );
     430        $comment_3 = self::factory()->comment->create( array(
     431            'comment_post_ID' => $p,
     432            'comment_content' => '3',
     433            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     434        ) );
     435        $comment_4 = self::factory()->comment->create( array(
    436436            'comment_post_ID' => $p,
    437437            'comment_content' => '4',
     
    481481    public function test_comment_permalinks_should_be_correct_when_using_default_display_callback_with_default_comment_page_newest() {
    482482        $now = time();
    483         $p = self::$factory->post->create();
    484         $comment_1 = self::$factory->comment->create( array(
    485             'comment_post_ID' => $p,
    486             'comment_content' => '1',
    487             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    488         ) );
    489         $comment_2 = self::$factory->comment->create( array(
    490             'comment_post_ID' => $p,
    491             'comment_content' => '2',
    492             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    493         ) );
    494         $comment_3 = self::$factory->comment->create( array(
    495             'comment_post_ID' => $p,
    496             'comment_content' => '3',
    497             'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    498         ) );
    499         $comment_4 = self::$factory->comment->create( array(
     483        $p = self::factory()->post->create();
     484        $comment_1 = self::factory()->comment->create( array(
     485            'comment_post_ID' => $p,
     486            'comment_content' => '1',
     487            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     488        ) );
     489        $comment_2 = self::factory()->comment->create( array(
     490            'comment_post_ID' => $p,
     491            'comment_content' => '2',
     492            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     493        ) );
     494        $comment_3 = self::factory()->comment->create( array(
     495            'comment_post_ID' => $p,
     496            'comment_content' => '3',
     497            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     498        ) );
     499        $comment_4 = self::factory()->comment->create( array(
    500500            'comment_post_ID' => $p,
    501501            'comment_content' => '4',
    502502            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
    503503        ) );
    504         $comment_5 = self::$factory->comment->create( array(
     504        $comment_5 = self::factory()->comment->create( array(
    505505            'comment_post_ID' => $p,
    506506            'comment_content' => '4',
    507507            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
    508508        ) );
    509         $comment_6 = self::$factory->comment->create( array(
     509        $comment_6 = self::factory()->comment->create( array(
    510510            'comment_post_ID' => $p,
    511511            'comment_content' => '4',
Note: See TracChangeset for help on using the changeset viewer.