Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (6 months ago)
Author:
SergeyBiryukov
Message:

Tests: Replace assertContains() with assertStringContainsString() when used with strings.

Using the assertContains() and assertNotContains() methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

  • assertStringContainsString()
  • assertStringContainsStringIgnoringCase
  • assertStringNotContainsString()
  • assertStringNotContainsStringIgnoringCase

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

Follow-up to [51331], [51451], [51461].

Props jrf, dd32, SergeyBiryukov.
See #53363, #46149.

File:
1 edited

Legend:

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

    r51331 r51462  
    102102        $actual = wp_dropdown_languages( $args );
    103103
    104         $this->assertContains( 'id="foo"', $actual );
    105         $this->assertContains( 'name="bar"', $actual );
    106         $this->assertContains( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    107         $this->assertContains( '<option value="de_DE" lang="de" selected=\'selected\' data-installed="1">Deutsch</option>', $actual );
    108         $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    109         $this->assertContains( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
     104        $this->assertStringContainsString( 'id="foo"', $actual );
     105        $this->assertStringContainsString( 'name="bar"', $actual );
     106        $this->assertStringContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
     107        $this->assertStringContainsString( '<option value="de_DE" lang="de" selected=\'selected\' data-installed="1">Deutsch</option>', $actual );
     108        $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
     109        $this->assertStringContainsString( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
    110110    }
    111111
     
    125125        $actual = wp_dropdown_languages( $args );
    126126
    127         $this->assertContains( 'id="foo"', $actual );
    128         $this->assertContains( 'name="bar"', $actual );
    129         $this->assertContains( '<option value="site-default" data-installed="1">Site Default</option>', $actual );
    130         $this->assertContains( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    131         $this->assertContains( '<option value="de_DE" lang="de" selected=\'selected\' data-installed="1">Deutsch</option>', $actual );
    132         $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    133         $this->assertContains( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
     127        $this->assertStringContainsString( 'id="foo"', $actual );
     128        $this->assertStringContainsString( 'name="bar"', $actual );
     129        $this->assertStringContainsString( '<option value="site-default" data-installed="1">Site Default</option>', $actual );
     130        $this->assertStringContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
     131        $this->assertStringContainsString( '<option value="de_DE" lang="de" selected=\'selected\' data-installed="1">Deutsch</option>', $actual );
     132        $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
     133        $this->assertStringContainsString( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
    134134    }
    135135
     
    149149        $actual = wp_dropdown_languages( $args );
    150150
    151         $this->assertNotContains( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
     151        $this->assertStringNotContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    152152    }
    153153
     
    166166        $actual = wp_dropdown_languages( $args );
    167167
    168         $this->assertContains( 'id="foo"', $actual );
    169         $this->assertContains( 'name="bar"', $actual );
    170         $this->assertContains( '<option value="" lang="en" data-installed="1" selected=\'selected\'>English (United States)</option>', $actual );
    171         $this->assertContains( '<option value="de_DE" lang="de" data-installed="1">Deutsch</option>', $actual );
    172         $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    173         $this->assertContains( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
     168        $this->assertStringContainsString( 'id="foo"', $actual );
     169        $this->assertStringContainsString( 'name="bar"', $actual );
     170        $this->assertStringContainsString( '<option value="" lang="en" data-installed="1" selected=\'selected\'>English (United States)</option>', $actual );
     171        $this->assertStringContainsString( '<option value="de_DE" lang="de" data-installed="1">Deutsch</option>', $actual );
     172        $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
     173        $this->assertStringContainsString( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
    174174    }
    175175
     
    189189        $actual = wp_dropdown_languages( $args );
    190190
    191         $this->assertContains( 'id="foo"', $actual );
    192         $this->assertContains( 'name="bar"', $actual );
    193         $this->assertContains( '<option value="site-default" data-installed="1">Site Default</option>', $actual );
    194         $this->assertContains( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    195         $this->assertContains( '<option value="de_DE" lang="de">Deutsch</option>', $actual );
    196         $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    197         $this->assertContains( '<option value="ja_JP" lang="ja" selected=\'selected\' data-installed="1">日本語</option>', $actual );
     191        $this->assertStringContainsString( 'id="foo"', $actual );
     192        $this->assertStringContainsString( 'name="bar"', $actual );
     193        $this->assertStringContainsString( '<option value="site-default" data-installed="1">Site Default</option>', $actual );
     194        $this->assertStringContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
     195        $this->assertStringContainsString( '<option value="de_DE" lang="de">Deutsch</option>', $actual );
     196        $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
     197        $this->assertStringContainsString( '<option value="ja_JP" lang="ja" selected=\'selected\' data-installed="1">日本語</option>', $actual );
    198198    }
    199199
     
    212212        $actual = wp_dropdown_languages( $args );
    213213
    214         $this->assertContains( 'id="foo"', $actual );
    215         $this->assertContains( 'name="bar"', $actual );
    216         $this->assertContains( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    217         $this->assertContains( '<option value="de_DE" lang="de" data-installed="1">Deutsch</option>', $actual );
    218         $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    219         $this->assertContains( '<option value="ja_JP" lang="ja" selected=\'selected\'>日本語</option>', $actual );
     214        $this->assertStringContainsString( 'id="foo"', $actual );
     215        $this->assertStringContainsString( 'name="bar"', $actual );
     216        $this->assertStringContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
     217        $this->assertStringContainsString( '<option value="de_DE" lang="de" data-installed="1">Deutsch</option>', $actual );
     218        $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
     219        $this->assertStringContainsString( '<option value="ja_JP" lang="ja" selected=\'selected\'>日本語</option>', $actual );
    220220    }
    221221
Note: See TracChangeset for help on using the changeset viewer.