Make WordPress Core


Ignore:
Timestamp:
07/17/2021 10:36:52 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in various tests.

This replaces instances of assertTrue( strpos( ... ) > 0 ) with assertStringContainsString() to use native PHPUnit functionality.

Going forward, these methods introduced in PHPUnit 7.5 should be used for similar assertions:

  • assertStringContainsString()
  • assertStringNotContainsString()

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods are now added to the WP_UnitTestCase class for PHPUnit < 7.5.

Follow-up to [51335], [51337], [51367], [51397], [51403], [51404], [51436], [51438], [51448], [51449].

See #53363.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/oembed/template.php

    r50441 r51451  
    3333                $doc = new DOMDocument();
    3434                $this->assertTrue( $doc->loadHTML( $actual ) );
    35                 $this->assertFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
    36                 $this->assertNotFalse( strpos( $actual, 'Hello World' ) );
     35                $this->assertStringNotContainsString( 'That embed can&#8217;t be found.', $actual );
     36                $this->assertStringContainsString( 'Hello World', $actual );
    3737        }
    3838
     
    6565                $doc = new DOMDocument();
    6666                $this->assertTrue( $doc->loadHTML( $actual ) );
    67                 $this->assertFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
    68                 $this->assertNotFalse( strpos( $actual, 'Hello World' ) );
    69                 $this->assertNotFalse( strpos( $actual, 'canola.jpg' ) );
     67                $this->assertStringNotContainsString( 'That embed can&#8217;t be found.', $actual );
     68                $this->assertStringContainsString( 'Hello World', $actual );
     69                $this->assertStringContainsString( 'canola.jpg', $actual );
    7070        }
    7171
     
    8282                $doc = new DOMDocument();
    8383                $this->assertTrue( $doc->loadHTML( $actual ) );
    84                 $this->assertNotFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
     84                $this->assertStringContainsString( 'That embed can&#8217;t be found.', $actual );
    8585        }
    8686
     
    109109                $doc = new DOMDocument();
    110110                $this->assertTrue( $doc->loadHTML( $actual ) );
    111                 $this->assertFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
    112                 $this->assertNotFalse( strpos( $actual, 'Hello World' ) );
    113                 $this->assertNotFalse( strpos( $actual, 'canola.jpg' ) );
     111                $this->assertStringNotContainsString( 'That embed can&#8217;t be found.', $actual );
     112                $this->assertStringContainsString( 'Hello World', $actual );
     113                $this->assertStringContainsString( 'canola.jpg', $actual );
    114114        }
    115115
     
    134134                $doc = new DOMDocument();
    135135                $this->assertTrue( $doc->loadHTML( $actual ) );
    136                 $this->assertNotFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
     136                $this->assertStringContainsString( 'That embed can&#8217;t be found.', $actual );
    137137        }
    138138
     
    158158                $doc = new DOMDocument();
    159159                $this->assertTrue( $doc->loadHTML( $actual ) );
    160                 $this->assertNotFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
     160                $this->assertStringContainsString( 'That embed can&#8217;t be found.', $actual );
    161161        }
    162162
     
    181181                $doc = new DOMDocument();
    182182                $this->assertTrue( $doc->loadHTML( $actual ) );
    183                 $this->assertNotFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
     183                $this->assertStringContainsString( 'That embed can&#8217;t be found.', $actual );
    184184        }
    185185
     
    208208                $doc = new DOMDocument();
    209209                $this->assertTrue( $doc->loadHTML( $actual ) );
    210                 $this->assertFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
    211                 $this->assertNotFalse( strpos( $actual, 'Hello World' ) );
     210                $this->assertStringNotContainsString( 'That embed can&#8217;t be found.', $actual );
     211                $this->assertStringContainsString( 'Hello World', $actual );
    212212        }
    213213
Note: See TracChangeset for help on using the changeset viewer.