Make WordPress Core

Changeset 51403


Ignore:
Timestamp:
07/11/2021 12:41:48 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in various tests.

This replaces instances of assertTrue( empty( ... ) ) with assertEmpty() to use native PHPUnit functionality.

Follow-up to [51335], [51337], [51367], [51397].

See #53363.

Location:
trunk/tests/phpunit/tests
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/actions.php

    r51397 r51403  
    280280        // Just in case we don't trust assertSame().
    281281        $obj->foo = true;
    282         $this->assertFalse( empty( $args[0][0]->foo ) );
     282        $this->assertNotEmpty( $args[0][0]->foo );
    283283    }
    284284
  • trunk/tests/phpunit/tests/filters.php

    r48937 r51403  
    232232        // Just in case we don't trust assertSame().
    233233        $obj->foo = true;
    234         $this->assertFalse( empty( $args[0][0]->foo ) );
     234        $this->assertNotEmpty( $args[0][0]->foo );
    235235    }
    236236
     
    255255        // Just in case we don't trust assertSame().
    256256        $obj->foo = true;
    257         $this->assertFalse( empty( $args[0][1]->foo ) );
     257        $this->assertNotEmpty( $args[0][1]->foo );
    258258
    259259        $args = $b->get_args();
     
    261261        // Just in case we don't trust assertSame().
    262262        $obj->foo = true;
    263         $this->assertFalse( empty( $args[0][1]->foo ) );
     263        $this->assertNotEmpty( $args[0][1]->foo );
    264264
    265265    }
  • trunk/tests/phpunit/tests/http/base.php

    r51397 r51403  
    226226        $this->skipTestOnTimeout( $res );
    227227        $this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
    228         $this->assertTrue( ! empty( $res['headers']['location'] ) );
     228        $this->assertNotEmpty( $res['headers']['location'] );
    229229    }
    230230
  • trunk/tests/phpunit/tests/import/base.php

    r47122 r51403  
    2525        $file     = realpath( $filename );
    2626
    27         $this->assertTrue( ! empty( $file ), 'Path to import file is empty.' );
     27        $this->assertNotEmpty( $file, 'Path to import file is empty.' );
    2828        $this->assertTrue( is_file( $file ), 'Import file is not a file.' );
    2929
  • trunk/tests/phpunit/tests/post/attachments.php

    r49024 r51403  
    1919
    2020        $upload = wp_upload_bits( $filename, null, $contents );
    21         $this->assertTrue( empty( $upload['error'] ) );
     21        $this->assertEmpty( $upload['error'] );
    2222    }
    2323
     
    2929
    3030        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    31         $this->assertTrue( empty( $upload['error'] ) );
     31        $this->assertEmpty( $upload['error'] );
    3232
    3333        $id = $this->_make_attachment( $upload );
     
    6666
    6767        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    68         $this->assertTrue( empty( $upload['error'] ) );
     68        $this->assertEmpty( $upload['error'] );
    6969
    7070        $id = $this->_make_attachment( $upload );
     
    120120
    121121        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    122         $this->assertTrue( empty( $upload['error'] ) );
     122        $this->assertEmpty( $upload['error'] );
    123123
    124124        $id      = $this->_make_attachment( $upload );
     
    177177
    178178        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    179         $this->assertTrue( empty( $upload['error'] ) );
     179        $this->assertEmpty( $upload['error'] );
    180180
    181181        $id      = $this->_make_attachment( $upload );
     
    220220
    221221        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    222         $this->assertTrue( empty( $upload['error'] ) );
     222        $this->assertEmpty( $upload['error'] );
    223223
    224224        $upload['url'] = '';
     
    226226
    227227        $guid = get_the_guid( $id );
    228         $this->assertFalse( empty( $guid ) );
     228        $this->assertNotEmpty( $guid );
    229229    }
    230230
     
    237237
    238238        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    239         $this->assertTrue( empty( $upload['error'] ) );
     239        $this->assertEmpty( $upload['error'] );
    240240
    241241        $id = $this->_make_attachment( $upload );
     
    263263
    264264        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    265         $this->assertTrue( empty( $upload['error'] ) );
     265        $this->assertEmpty( $upload['error'] );
    266266
    267267        $attachment_id = $this->_make_attachment( $upload );
     
    295295
    296296        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    297         $this->assertTrue( empty( $upload['error'] ) );
     297        $this->assertEmpty( $upload['error'] );
    298298
    299299        // Set attachment ID.
     
    320320
    321321        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    322         $this->assertTrue( empty( $upload['error'] ) );
     322        $this->assertEmpty( $upload['error'] );
    323323
    324324        // Set attachment ID.
     
    345345
    346346        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    347         $this->assertTrue( empty( $upload['error'] ) );
     347        $this->assertEmpty( $upload['error'] );
    348348
    349349        // Set attachment ID.
     
    373373
    374374        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    375         $this->assertTrue( empty( $upload['error'] ) );
     375        $this->assertEmpty( $upload['error'] );
    376376
    377377        // Set attachment ID.
     
    401401
    402402        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    403         $this->assertTrue( empty( $upload['error'] ) );
     403        $this->assertEmpty( $upload['error'] );
    404404
    405405        // Set attachment ID.
     
    428428
    429429        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
    430         $this->assertTrue( empty( $upload['error'] ) );
     430        $this->assertEmpty( $upload['error'] );
    431431
    432432        // Set attachment ID.
  • trunk/tests/phpunit/tests/query/setupPostdata.php

    r50449 r51403  
    318318        setup_postdata( $post2 );
    319319
    320         $this->assertTrue( empty( $GLOBALS['more'] ) );
     320        $this->assertEmpty( $GLOBALS['more'] );
    321321    }
    322322
     
    336336        setup_postdata( $post );
    337337
    338         $this->assertTrue( empty( $GLOBALS['more'] ) );
     338        $this->assertEmpty( $GLOBALS['more'] );
    339339    }
    340340
     
    373373
    374374                // $more should refer to the current loop.
    375                 $this->assertTrue( empty( $GLOBALS['more'] ) );
     375                $this->assertEmpty( $GLOBALS['more'] );
    376376            }
    377377        }
  • trunk/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php

    r50449 r51403  
    479479        $data = $response->get_data();
    480480
    481         $this->assertTrue( empty( $data['rendered'] ) );
     481        $this->assertEmpty( $data['rendered'] );
    482482
    483483        // Now test with post ID.
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r51335 r51403  
    7474
    7575        $this->assertIsArray( $routes, '`get_routes` should return an array.' );
    76         $this->assertTrue( ! empty( $routes ), 'Routes should not be empty.' );
     76        $this->assertNotEmpty( $routes, 'Routes should not be empty.' );
    7777
    7878        $routes = array_filter( array_keys( $routes ), array( $this, 'is_builtin_route' ) );
     
    473473                "HTTP $status from $route[route]: " . json_encode( $data )
    474474            );
    475             $this->assertTrue( ! empty( $data ), $route['name'] . ' route should return data.' );
     475            $this->assertNotEmpty( $data, $route['name'] . ' route should return data.' );
    476476
    477477            $fixture           = $this->normalize_fixture( $data, $route['name'] );
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r51367 r51403  
    261261
    262262        foreach ( $users as $user ) {
    263             $this->assertTrue( count_user_posts( $user['id'], $rest_post_types ) > 0 );
     263            $this->assertNotEmpty( count_user_posts( $user['id'], $rest_post_types ) );
    264264
    265265            // Ensure we don't expose non-public data.
  • trunk/tests/phpunit/tests/term/wpInsertTerm.php

    r51331 r51403  
    188188        $term = self::factory()->tag->create_and_get( array( 'name' => 'Bozo' ) );
    189189        $this->assertNotWPError( $term );
    190         $this->assertTrue( empty( $term->errors ) );
     190        $this->assertEmpty( $term->errors );
    191191
    192192        // Test existing term name with unique slug.
  • trunk/tests/phpunit/tests/theme.php

    r51397 r51403  
    289289
    290290                $root_uri = get_theme_root_uri();
    291                 $this->assertTrue( ! empty( $root_uri ) );
     291                $this->assertNotEmpty( $root_uri );
    292292
    293293                $this->assertSame( $root_fs . '/' . get_stylesheet(), get_stylesheet_directory() );
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r51371 r51403  
    4646        $this->assertSame( $themes['WordPress Default'], $theme );
    4747
    48         $this->assertFalse( empty( $theme ) );
     48        $this->assertNotEmpty( $theme );
    4949
    5050        // echo gen_tests_array( 'theme', $theme );
     
    7575        $theme = get_theme( 'Sandbox' );
    7676
    77         $this->assertFalse( empty( $theme ) );
     77        $this->assertNotEmpty( $theme );
    7878
    7979        // echo gen_tests_array( 'theme', $theme );
     
    112112
    113113        $theme = $themes['Stylesheet Only'];
    114         $this->assertFalse( empty( $theme ) );
     114        $this->assertNotEmpty( $theme );
    115115
    116116        // echo gen_tests_array( 'theme', $theme );
     
    206206
    207207        $theme = $themes['Page Template Theme'];
    208         $this->assertFalse( empty( $theme ) );
     208        $this->assertNotEmpty( $theme );
    209209
    210210        $templates = $theme['Template Files'];
Note: See TracChangeset for help on using the changeset viewer.