WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months 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/admin/includesPost.php

    r48117 r48937  
    3838        $_results = _wp_translate_postdata( false, $_post_data );
    3939        $this->assertNotWPError( $_results );
    40         $this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
    41         $this->assertEquals( 'draft', $_results['post_status'] );
     40        $this->assertSame( $_post_data['post_author'], $_results['post_author'] );
     41        $this->assertSame( 'draft', $_results['post_status'] );
    4242
    4343        // Submit post for approval.
     
    4949        $_results = _wp_translate_postdata( false, $_post_data );
    5050        $this->assertNotWPError( $_results );
    51         $this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
    52         $this->assertEquals( 'pending', $_results['post_status'] );
     51        $this->assertSame( $_post_data['post_author'], $_results['post_author'] );
     52        $this->assertSame( 'pending', $_results['post_status'] );
    5353
    5454        // Create new draft post for another user.
     
    6060        $_results = _wp_translate_postdata( false, $_post_data );
    6161        $this->assertInstanceOf( 'WP_Error', $_results );
    62         $this->assertEquals( 'edit_others_posts', $_results->get_error_code() );
    63         $this->assertEquals( 'Sorry, you are not allowed to create posts as this user.', $_results->get_error_message() );
     62        $this->assertSame( 'edit_others_posts', $_results->get_error_code() );
     63        $this->assertSame( 'Sorry, you are not allowed to create posts as this user.', $_results->get_error_message() );
    6464
    6565        // Edit draft post for another user.
     
    7373        $_results = _wp_translate_postdata( true, $_post_data );
    7474        $this->assertInstanceOf( 'WP_Error', $_results );
    75         $this->assertEquals( 'edit_others_posts', $_results->get_error_code() );
    76         $this->assertEquals( 'Sorry, you are not allowed to edit posts as this user.', $_results->get_error_message() );
     75        $this->assertSame( 'edit_others_posts', $_results->get_error_code() );
     76        $this->assertSame( 'Sorry, you are not allowed to edit posts as this user.', $_results->get_error_message() );
    7777    }
    7878
     
    8888        $_results = _wp_translate_postdata( false, $_post_data );
    8989        $this->assertNotWPError( $_results );
    90         $this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
    91         $this->assertEquals( 'draft', $_results['post_status'] );
     90        $this->assertSame( $_post_data['post_author'], $_results['post_author'] );
     91        $this->assertSame( 'draft', $_results['post_status'] );
    9292
    9393        // Publish post.
     
    9999        $_results = _wp_translate_postdata( false, $_post_data );
    100100        $this->assertNotWPError( $_results );
    101         $this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
    102         $this->assertEquals( 'publish', $_results['post_status'] );
     101        $this->assertSame( $_post_data['post_author'], $_results['post_author'] );
     102        $this->assertSame( 'publish', $_results['post_status'] );
    103103
    104104        // Create new draft post for another user.
     
    110110        $_results = _wp_translate_postdata( false, $_post_data );
    111111        $this->assertNotWPError( $_results );
    112         $this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
    113         $this->assertEquals( 'draft', $_results['post_status'] );
     112        $this->assertSame( $_post_data['post_author'], $_results['post_author'] );
     113        $this->assertSame( 'draft', $_results['post_status'] );
    114114
    115115        // Edit draft post for another user.
     
    123123        $_results = _wp_translate_postdata( true, $_post_data );
    124124        $this->assertNotWPError( $_results );
    125         $this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
    126         $this->assertEquals( 'draft', $_results['post_status'] );
     125        $this->assertSame( $_post_data['post_author'], $_results['post_author'] );
     126        $this->assertSame( 'draft', $_results['post_status'] );
    127127    }
    128128
     
    135135        wp_set_current_user( self::$editor_id );
    136136        $post = self::factory()->post->create_and_get( array( 'post_status' => 'auto-draft' ) );
    137         $this->assertEquals( 'auto-draft', $post->post_status );
     137        $this->assertSame( 'auto-draft', $post->post_status );
    138138        $post_data = array(
    139139            'post_title' => 'Post title',
     
    143143        );
    144144        edit_post( $post_data );
    145         $this->assertEquals( 'draft', get_post( $post->ID )->post_status );
     145        $this->assertSame( 'draft', get_post( $post->ID )->post_status );
    146146    }
    147147
     
    253253
    254254        // Check that the first post's values don't stomp the second post.
    255         $this->assertEquals( 'draft', $post->post_status );
     255        $this->assertSame( 'draft', $post->post_status );
    256256        $this->assertEquals( self::$author_ids[1], $post->post_author );
    257         $this->assertEquals( 'closed', $post->comment_status );
    258         $this->assertEquals( 'closed', $post->ping_status );
     257        $this->assertSame( 'closed', $post->comment_status );
     258        $this->assertSame( 'closed', $post->ping_status );
    259259    }
    260260
     
    315315    public function check_post_format( $post_id ) {
    316316        if ( self::$post_id === $post_id ) {
    317             $this->assertEquals( 'aside', get_post_format( $post_id ) );
     317            $this->assertSame( 'aside', get_post_format( $post_id ) );
    318318        }
    319319    }
     
    539539
    540540        $found = get_sample_permalink( $p );
    541         $this->assertEquals( '2015-2', $found[1] );
     541        $this->assertSame( '2015-2', $found[1] );
    542542    }
    543543
     
    555555
    556556        $found = get_sample_permalink( $p );
    557         $this->assertEquals( '2015', $found[1] );
     557        $this->assertSame( '2015', $found[1] );
    558558    }
    559559
     
    571571
    572572        $found = get_sample_permalink( $p );
    573         $this->assertEquals( '11-2', $found[1] );
     573        $this->assertSame( '11-2', $found[1] );
    574574    }
    575575
     
    587587
    588588        $found = get_sample_permalink( $p );
    589         $this->assertEquals( '13', $found[1] );
     589        $this->assertSame( '13', $found[1] );
    590590    }
    591591
     
    603603
    604604        $found = get_sample_permalink( $p );
    605         $this->assertEquals( '30-2', $found[1] );
     605        $this->assertSame( '30-2', $found[1] );
    606606    }
    607607
     
    625625
    626626        $found = get_sample_permalink( $p );
    627         $this->assertEquals( '30-3', $found[1] );
     627        $this->assertSame( '30-3', $found[1] );
    628628    }
    629629
     
    641641
    642642        $found = get_sample_permalink( $p );
    643         $this->assertEquals( '32', $found[1] );
     643        $this->assertSame( '32', $found[1] );
    644644    }
    645645
     
    657657
    658658        $found = get_sample_permalink( $p );
    659         $this->assertEquals( '30', $found[1] );
     659        $this->assertSame( '30', $found[1] );
    660660    }
    661661
     
    826826        $name     = 'core/test';
    827827        $settings = array(
     828            'icon'            => 'text',
    828829            'category'        => 'common',
    829             'icon'            => 'text',
    830830            'render_callback' => 'foo',
    831831        );
     
    838838
    839839        $this->assertArrayHasKey( $name, $blocks );
    840         $this->assertEquals(
     840        $this->assertSame(
    841841            array(
    842842                'title'       => '',
    843843                'description' => '',
     844                'icon'        => 'text',
    844845                'category'    => 'common',
    845                 'icon'        => 'text',
    846846                'keywords'    => array(),
    847847                'usesContext' => array(),
     
    866866
    867867        $this->assertNotFalse( add_meta( $p ) );
    868         $this->assertEquals( '', get_post_meta( $p, 'testkey', true ) );
     868        $this->assertSame( '', get_post_meta( $p, 'testkey', true ) );
    869869    }
    870870
Note: See TracChangeset for help on using the changeset viewer.