Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/attachments.php

    r48190 r48937  
    4040        // medium, medium_large, and full size will both point to the original.
    4141        $downsize = image_downsize( $id, 'medium' );
    42         $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
    43         $this->assertEquals( 50, $downsize[1] );
    44         $this->assertEquals( 50, $downsize[2] );
     42        $this->assertSame( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
     43        $this->assertSame( 50, $downsize[1] );
     44        $this->assertSame( 50, $downsize[2] );
    4545
    4646        $downsize = image_downsize( $id, 'medium_large' );
    47         $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
    48         $this->assertEquals( 50, $downsize[1] );
    49         $this->assertEquals( 50, $downsize[2] );
     47        $this->assertSame( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
     48        $this->assertSame( 50, $downsize[1] );
     49        $this->assertSame( 50, $downsize[2] );
    5050
    5151        $downsize = image_downsize( $id, 'full' );
    52         $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
    53         $this->assertEquals( 50, $downsize[1] );
    54         $this->assertEquals( 50, $downsize[2] );
     52        $this->assertSame( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) );
     53        $this->assertSame( 50, $downsize[1] );
     54        $this->assertSame( 50, $downsize[2] );
    5555    }
    5656
     
    7373        // Intermediate copies should exist: thumbnail only.
    7474        $thumb = image_get_intermediate_size( $id, 'thumbnail' );
    75         $this->assertEquals( 'a2-small-150x150.jpg', $thumb['file'] );
     75        $this->assertSame( 'a2-small-150x150.jpg', $thumb['file'] );
    7676
    7777        $uploads = wp_upload_dir();
     
    8282
    8383        // The thumb url should point to the thumbnail intermediate.
    84         $this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url( $id ) );
     84        $this->assertSame( $thumb['url'], wp_get_attachment_thumb_url( $id ) );
    8585
    8686        // image_downsize() should return the correct images and sizes.
    8787        $downsize = image_downsize( $id, 'thumbnail' );
    88         $this->assertEquals( 'a2-small-150x150.jpg', wp_basename( $downsize[0] ) );
    89         $this->assertEquals( 150, $downsize[1] );
    90         $this->assertEquals( 150, $downsize[2] );
     88        $this->assertSame( 'a2-small-150x150.jpg', wp_basename( $downsize[0] ) );
     89        $this->assertSame( 150, $downsize[1] );
     90        $this->assertSame( 150, $downsize[2] );
    9191
    9292        // medium, medium_large, and full will both point to the original.
    9393        $downsize = image_downsize( $id, 'medium' );
    94         $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) );
    95         $this->assertEquals( 400, $downsize[1] );
    96         $this->assertEquals( 300, $downsize[2] );
     94        $this->assertSame( 'a2-small.jpg', wp_basename( $downsize[0] ) );
     95        $this->assertSame( 400, $downsize[1] );
     96        $this->assertSame( 300, $downsize[2] );
    9797
    9898        $downsize = image_downsize( $id, 'medium_large' );
    99         $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) );
    100         $this->assertEquals( 400, $downsize[1] );
    101         $this->assertEquals( 300, $downsize[2] );
     99        $this->assertSame( 'a2-small.jpg', wp_basename( $downsize[0] ) );
     100        $this->assertSame( 400, $downsize[1] );
     101        $this->assertSame( 300, $downsize[2] );
    102102
    103103        $downsize = image_downsize( $id, 'full' );
    104         $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) );
    105         $this->assertEquals( 400, $downsize[1] );
    106         $this->assertEquals( 300, $downsize[2] );
     104        $this->assertSame( 'a2-small.jpg', wp_basename( $downsize[0] ) );
     105        $this->assertSame( 400, $downsize[1] );
     106        $this->assertSame( 300, $downsize[2] );
    107107    }
    108108
     
    129129        // Intermediate copies should exist: thumbnail and medium.
    130130        $thumb = image_get_intermediate_size( $id, 'thumbnail' );
    131         $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] );
     131        $this->assertSame( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] );
    132132        $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) );
    133133
    134134        $medium = image_get_intermediate_size( $id, 'medium' );
    135         $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
     135        $this->assertSame( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
    136136        $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path'] ) );
    137137
    138138        $medium_large = image_get_intermediate_size( $id, 'medium_large' );
    139         $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
     139        $this->assertSame( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
    140140        $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) );
    141141
    142142        // The thumb url should point to the thumbnail intermediate.
    143         $this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url( $id ) );
     143        $this->assertSame( $thumb['url'], wp_get_attachment_thumb_url( $id ) );
    144144
    145145        // image_downsize() should return the correct images and sizes.
    146146        $downsize = image_downsize( $id, 'thumbnail' );
    147         $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $downsize[0] ) );
    148         $this->assertEquals( 150, $downsize[1] );
    149         $this->assertEquals( 150, $downsize[2] );
     147        $this->assertSame( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $downsize[0] ) );
     148        $this->assertSame( 150, $downsize[1] );
     149        $this->assertSame( 150, $downsize[2] );
    150150
    151151        $downsize = image_downsize( $id, 'medium' );
    152         $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', wp_basename( $downsize[0] ) );
    153         $this->assertEquals( 400, $downsize[1] );
    154         $this->assertEquals( 602, $downsize[2] );
     152        $this->assertSame( '2007-06-17DSC_4173-400x602.jpg', wp_basename( $downsize[0] ) );
     153        $this->assertSame( 400, $downsize[1] );
     154        $this->assertSame( 602, $downsize[2] );
    155155
    156156        $downsize = image_downsize( $id, 'medium_large' );
    157         $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', wp_basename( $downsize[0] ) );
    158         $this->assertEquals( 600, $downsize[1] );
    159         $this->assertEquals( 904, $downsize[2] );
     157        $this->assertSame( '2007-06-17DSC_4173-600x904.jpg', wp_basename( $downsize[0] ) );
     158        $this->assertSame( 600, $downsize[1] );
     159        $this->assertSame( 904, $downsize[2] );
    160160
    161161        $downsize = image_downsize( $id, 'full' );
    162         $this->assertEquals( '2007-06-17DSC_4173.jpg', wp_basename( $downsize[0] ) );
    163         $this->assertEquals( 680, $downsize[1] );
    164         $this->assertEquals( 1024, $downsize[2] );
     162        $this->assertSame( '2007-06-17DSC_4173.jpg', wp_basename( $downsize[0] ) );
     163        $this->assertSame( 680, $downsize[1] );
     164        $this->assertSame( 1024, $downsize[2] );
    165165    }
    166166
     
    188188        // Check that the file and intermediates exist.
    189189        $thumb = image_get_intermediate_size( $id, 'thumbnail' );
    190         $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] );
     190        $this->assertSame( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] );
    191191        $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) );
    192192
    193193        $medium = image_get_intermediate_size( $id, 'medium' );
    194         $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
     194        $this->assertSame( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
    195195        $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path'] ) );
    196196
    197197        $medium_large = image_get_intermediate_size( $id, 'medium_large' );
    198         $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
     198        $this->assertSame( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
    199199        $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) );
    200200
     
    256256
    257257        // Make sure the update didn't remove the attached file.
    258         $this->assertEquals( $attached_file, get_post_meta( $id, '_wp_attached_file', true ) );
     258        $this->assertSame( $attached_file, get_post_meta( $id, '_wp_attached_file', true ) );
    259259    }
    260260
     
    273273        // Assert that the attachment is an orphan.
    274274        $attachment = get_post( $attachment_id );
    275         $this->assertEquals( $attachment->post_parent, 0 );
     275        $this->assertSame( $attachment->post_parent, 0 );
    276276
    277277        $post_id = wp_insert_post(
     
    285285        wp_insert_attachment( $attachment, '', $post_id );
    286286        $attachment = get_post( $attachment_id );
    287         $this->assertEquals( $attachment->post_parent, $post_id );
     287        $this->assertSame( $attachment->post_parent, $post_id );
    288288    }
    289289
Note: See TracChangeset for help on using the changeset viewer.