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/oembed/filterResult.php

    r47947 r48937  
    1010        $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' );
    1111
    12         $this->assertEquals( $html, $actual );
     12        $this->assertSame( $html, $actual );
    1313    }
    1414
     
    2222        $this->assertTrue( isset( $matches[1] ) );
    2323        $this->assertTrue( isset( $matches[2] ) );
    24         $this->assertEquals( $matches[1], $matches[2] );
     24        $this->assertSame( $matches[1], $matches[2] );
    2525    }
    2626
     
    2929        $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
    3030
    31         $this->assertEquals( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
     31        $this->assertSame( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
    3232    }
    3333
     
    4242        $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
    4343
    44         $this->assertEquals( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
     44        $this->assertSame( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
    4545    }
    4646
     
    6666        $this->assertTrue( isset( $matches[1] ) );
    6767        $this->assertTrue( isset( $matches[2] ) );
    68         $this->assertEquals( $matches[1], $matches[2] );
     68        $this->assertSame( $matches[1], $matches[2] );
    6969    }
    7070
     
    7272        $actual = wp_filter_oembed_result( 'some string', (object) array( 'type' => 'link' ), '' );
    7373
    74         $this->assertEquals( 'some string', $actual );
     74        $this->assertSame( 'some string', $actual );
    7575    }
    7676
     
    8484        $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
    8585
    86         $this->assertEquals( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"></iframe>', $actual );
     86        $this->assertSame( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"></iframe>', $actual );
    8787    }
    8888
     
    9191        $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
    9292
    93         $this->assertEquals( '<blockquote class="wp-embedded-content"><a href=""></a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"></iframe>', $actual );
     93        $this->assertSame( '<blockquote class="wp-embedded-content"><a href=""></a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"></iframe>', $actual );
    9494    }
    9595
     
    125125        );
    126126        $actual = _wp_oembed_get_object()->data2html( $data, 'https://untrusted.localhost' );
    127         $this->assertEquals( $expected, $actual );
     127        $this->assertSame( $expected, $actual );
    128128    }
    129129
     
    135135        $actual = _oembed_filter_feed_content( wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ) );
    136136
    137         $this->assertEquals( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
     137        $this->assertSame( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
    138138    }
    139139}
Note: See TracChangeset for help on using the changeset viewer.