WordPress.org

Make WordPress Core

Changeset 51565


Ignore:
Timestamp:
08/06/2021 09:52:06 PM (4 months ago)
Author:
SergeyBiryukov
Message:

Tests: Replace assertRegExp() with assertMatchesRegularExpression().

The assertRegExp() and assertNotRegExp() methods were hard deprecated in PHPUnit 9.1 and the functionality will be removed in PHPUnit 10.0.

The assertMatchesRegularExpression() and assertDoesNotMatchRegularExpression() methods were introduced as a replacement in PHPUnit 9.1.

These new PHPUnit methods are polyfilled by the PHPUnit Polyfills and switching to them will future-proof the tests some more.

References:

Follow-up to [51559-51564].

Props jrf.
See #46149.

Location:
trunk/tests/phpunit/tests
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/Response.php

    r51404 r51565  
    101101        // Check the XML tag.
    102102        $contents = ob_get_clean();
    103         $this->assertRegExp( '/<\?xml\s+version=\'1.0\'\s+encoding=\'' . preg_quote( get_option( 'blog_charset' ) ) . '\'\s+standalone=\'yes\'\?>/', $contents );
     103        $this->assertMatchesRegularExpression( '/<\?xml\s+version=\'1.0\'\s+encoding=\'' . preg_quote( get_option( 'blog_charset' ) ) . '\'\s+standalone=\'yes\'\?>/', $contents );
    104104    }
    105105}
  • trunk/tests/phpunit/tests/avatar.php

    r48937 r51565  
    258258
    259259        $this->assertTrue( is_avatar_comment_type( $comment_type ) );
    260         $this->assertRegexp( '|^http?://[0-9]+.gravatar.com/avatar/[0-9a-f]{32}\?|', $actual_data['url'] );
     260        $this->assertMatchesRegularExpression( '|^http?://[0-9]+.gravatar.com/avatar/[0-9a-f]{32}\?|', $actual_data['url'] );
    261261    }
    262262
  • trunk/tests/phpunit/tests/category/wpDropdownCategories.php

    r51462 r51565  
    203203
    204204        // Test to see if it contains the "required" attribute.
    205         $this->assertRegExp( '/<select[^>]+required/', $dropdown_categories );
     205        $this->assertMatchesRegularExpression( '/<select[^>]+required/', $dropdown_categories );
    206206    }
    207207
  • trunk/tests/phpunit/tests/category/wpListCategories.php

    r51462 r51565  
    3131
    3232        $this->assertNotRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat[^"]*"/', $found );
    33         $this->assertRegExp( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat[^"]*"/', $found );
     33        $this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat[^"]*"/', $found );
    3434    }
    3535
     
    5050        );
    5151
    52         $this->assertRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat-parent[^"]*"/', $found );
     52        $this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat-parent[^"]*"/', $found );
    5353        $this->assertNotRegExp( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat-parent[^"]*"/', $found );
    5454    }
     
    6868        );
    6969
    70         $this->assertRegExp( '/class="[^"]*cat-item-' . $cats[0] . '[^"]*current-cat[^"]*"/', $found );
     70        $this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $cats[0] . '[^"]*current-cat[^"]*"/', $found );
    7171        $this->assertNotRegExp( '/class="[^"]*cat-item-' . $cats[1] . '[^"]*current[^"]*"/', $found );
    72         $this->assertRegExp( '/class="[^"]*cat-item-' . $cats[2] . '[^"]*current-cat[^"]*"/', $found );
     72        $this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $cats[2] . '[^"]*current-cat[^"]*"/', $found );
    7373    }
    7474
     
    651651        );
    652652
    653         $this->assertRegExp( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
    654         $this->assertRegExp( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     653        $this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
     654        $this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual );
    655655        $this->assertNotRegExp( '/class="[^"]*cat-item-' . $grandchild . '[^"]*current-cat-ancestor[^"]*"/', $actual );
    656656        $this->assertNotRegExp( '/class="[^"]*cat-item-' . $child2 . '[^"]*current-cat-ancestor[^"]*"/', $actual );
  • trunk/tests/phpunit/tests/comment/commentForm.php

    r51462 r51565  
    1919        $button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
    2020        $hidden = get_comment_id_fields( $p );
    21         $this->assertRegExp( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
     21        $this->assertMatchesRegularExpression( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
    2222    }
    2323
     
    5454        $button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
    5555        $hidden = get_comment_id_fields( $p );
    56         $this->assertRegExp( '|<p class="my\-custom\-submit\-field">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
     56        $this->assertMatchesRegularExpression( '|<p class="my\-custom\-submit\-field">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
    5757    }
    5858
     
    7676        $button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
    7777        $hidden = get_comment_id_fields( $p );
    78         $this->assertRegExp( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
     78        $this->assertMatchesRegularExpression( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
    7979    }
    8080
     
    103103        remove_filter( 'option_show_comments_cookies_opt_in', '__return_true' );
    104104
    105         $this->assertRegExp( '|<p class="comment\-form\-cookies\-consent">.*?</p>|', $form );
     105        $this->assertMatchesRegularExpression( '|<p class="comment\-form\-cookies\-consent">.*?</p>|', $form );
    106106    }
    107107
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r51462 r51565  
    771771            foreach ( $post_types as $type ) {
    772772                $this->assertStringContainsString( 'available-menu-items-post_type-' . esc_attr( $type->name ), $template );
    773                 $this->assertRegExp( '#<h4 class="accordion-section-title".*>\s*' . esc_html( $type->labels->name ) . '#', $template );
     773                $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*' . esc_html( $type->labels->name ) . '#', $template );
    774774                $this->assertStringContainsString( 'data-type="post_type"', $template );
    775775                $this->assertStringContainsString( 'data-object="' . esc_attr( $type->name ) . '"', $template );
     
    782782            foreach ( $taxonomies as $tax ) {
    783783                $this->assertStringContainsString( 'available-menu-items-taxonomy-' . esc_attr( $tax->name ), $template );
    784                 $this->assertRegExp( '#<h4 class="accordion-section-title".*>\s*' . esc_html( $tax->labels->name ) . '#', $template );
     784                $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*' . esc_html( $tax->labels->name ) . '#', $template );
    785785                $this->assertStringContainsString( 'data-type="taxonomy"', $template );
    786786                $this->assertStringContainsString( 'data-object="' . esc_attr( $tax->name ) . '"', $template );
     
    790790
    791791        $this->assertStringContainsString( 'available-menu-items-custom_type', $template );
    792         $this->assertRegExp( '#<h4 class="accordion-section-title".*>\s*Custom#', $template );
     792        $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*Custom#', $template );
    793793        $this->assertStringContainsString( 'data-type="custom_type"', $template );
    794794        $this->assertStringContainsString( 'data-object="custom_object"', $template );
     
    10141014        foreach ( $drafted_post_ids as $post_id ) {
    10151015            $this->assertSame( 'publish', get_post_status( $post_id ) );
    1016             $this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name );
     1016            $this->assertMatchesRegularExpression( '/^auto-draft-\d+$/', get_post( $post_id )->post_name );
    10171017            $this->assertEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
    10181018        }
  • trunk/tests/phpunit/tests/customize/widgets.php

    r51462 r51565  
    611611
    612612        $this->assertSame( 'widget_form', $params['type'] );
    613         $this->assertRegExp( '#^<li[^>]+>\s*</li>$#', $params['content'] );
    614         $this->assertRegExp( '#^<div[^>]*class=\'widget\'[^>]*#s', $params['widget_control'] );
     613        $this->assertMatchesRegularExpression( '#^<li[^>]+>\s*</li>$#', $params['content'] );
     614        $this->assertMatchesRegularExpression( '#^<div[^>]*class=\'widget\'[^>]*#s', $params['widget_control'] );
    615615        $this->assertStringContainsString( '<div class="widget-content"></div>', $params['widget_control'] );
    616616        $this->assertStringNotContainsString( '<input class="widefat"', $params['widget_control'] );
  • trunk/tests/phpunit/tests/date/query.php

    r51462 r51565  
    714714        // $compare value is floating point - use regex to account for
    715715        // varying precision on different PHP installations.
    716         $this->assertRegExp( "/DATE_FORMAT\( post_date, '%H\.%i' \) = 5\.150*/", $wpdb->remove_placeholder_escape( $found ) );
     716        $this->assertMatchesRegularExpression( "/DATE_FORMAT\( post_date, '%H\.%i' \) = 5\.150*/", $wpdb->remove_placeholder_escape( $found ) );
    717717    }
    718718
     
    725725        // $compare value is floating point - use regex to account for
    726726        // varying precision on different PHP installations.
    727         $this->assertRegExp( "/DATE_FORMAT\( post_date, '%H\.%i%s' \) = 5\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
     727        $this->assertMatchesRegularExpression( "/DATE_FORMAT\( post_date, '%H\.%i%s' \) = 5\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
    728728    }
    729729
     
    736736        // $compare value is floating point - use regex to account for
    737737        // varying precision on different PHP installations.
    738         $this->assertRegExp( "/DATE_FORMAT\( post_date, '0\.%i%s' \) = 0\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
     738        $this->assertMatchesRegularExpression( "/DATE_FORMAT\( post_date, '0\.%i%s' \) = 0\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
    739739    }
    740740
  • trunk/tests/phpunit/tests/functions.php

    r51564 r51565  
    12081208        for ( $i = 0; $i < 20; $i += 1 ) {
    12091209            $id = wp_unique_id( 'foo-' );
    1210             $this->assertRegExp( '/^foo-\d+$/', $id );
     1210            $this->assertMatchesRegularExpression( '/^foo-\d+$/', $id );
    12111211            $ids[] = $id;
    12121212        }
  • trunk/tests/phpunit/tests/meta/query.php

    r51462 r51565  
    926926
    927927        // Use regex because we don't care about the whitespace before OR.
    928         $this->assertRegExp( "/{$wpdb->postmeta}\.meta_key = \'exclude\'\s+OR/", $sql['where'] );
     928        $this->assertMatchesRegularExpression( "/{$wpdb->postmeta}\.meta_key = \'exclude\'\s+OR/", $sql['where'] );
    929929        $this->assertStringNotContainsString( "{$wpdb->postmeta}.post_id IS NULL", $sql['where'] );
    930930    }
  • trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php

    r51462 r51565  
    3535    public function test_full_true() {
    3636        $maybe_string = get_posts_by_author_sql( 'post', true );
    37         $this->assertRegExp( '/^WHERE /', $maybe_string );
     37        $this->assertMatchesRegularExpression( '/^WHERE /', $maybe_string );
    3838    }
    3939
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r51449 r51565  
    461461
    462462        // The markup should include whitespace between <li>'s.
    463         $this->assertRegExp( '/\s<li.*>|<\/li>\s/U', $menu );
     463        $this->assertMatchesRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
    464464        $this->assertNotRegExp( '/<\/li><li.*>/U', $menu );
    465465
     
    475475        // The markup should not include whitespace around <li>'s.
    476476        $this->assertNotRegExp( '/\s<li.*>|<\/li>\s/U', $menu );
    477         $this->assertRegExp( '/><li.*>|<\/li></U', $menu );
     477        $this->assertMatchesRegularExpression( '/><li.*>|<\/li></U', $menu );
    478478    }
    479479
  • trunk/tests/phpunit/tests/post/template.php

    r51462 r51565  
    341341        );
    342342
    343         $this->assertRegExp( '/<select[^>]+class=\'bar\'/', $found );
     343        $this->assertMatchesRegularExpression( '/<select[^>]+class=\'bar\'/', $found );
    344344    }
    345345
     
    420420
    421421        // After falling back, the 'before' argument should be set and output as '<ul>'.
    422         $this->assertRegExp( '/<div class="menu"><ul>/', $menu );
     422        $this->assertMatchesRegularExpression( '/<div class="menu"><ul>/', $menu );
    423423
    424424        // After falling back, the 'after' argument should be set and output as '</ul>'.
    425         $this->assertRegExp( '/<\/ul><\/div>/', $menu );
     425        $this->assertMatchesRegularExpression( '/<\/ul><\/div>/', $menu );
    426426
    427427        // After falling back, the markup should include whitespace around <li>'s.
    428         $this->assertRegExp( '/\s<li.*>|<\/li>\s/U', $menu );
     428        $this->assertMatchesRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
    429429        $this->assertNotRegExp( '/><li.*>|<\/li></U', $menu );
    430430
     
    438438
    439439        // After falling back, the empty 'container' argument should still return a container element.
    440         $this->assertRegExp( '/<div class="menu">/', $menu );
     440        $this->assertMatchesRegularExpression( '/<div class="menu">/', $menu );
    441441
    442442        // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without white-space.
     
    450450        // After falling back, the markup should not include whitespace around <li>'s.
    451451        $this->assertNotRegExp( '/\s<li.*>|<\/li>\s/U', $menu );
    452         $this->assertRegExp( '/><li.*>|<\/li></U', $menu );
     452        $this->assertMatchesRegularExpression( '/><li.*>|<\/li></U', $menu );
    453453
    454454    }
  • trunk/tests/phpunit/tests/query/results.php

    r51462 r51565  
    796796
    797797        $this->assertEmpty( $posts );
    798         $this->assertRegExp( '#AND 1=0#', $this->q->request );
     798        $this->assertMatchesRegularExpression( '#AND 1=0#', $this->q->request );
    799799
    800800        foreach ( array_keys( $wp_post_types ) as $slug ) {
  • trunk/tests/phpunit/tests/term/wpGenerateTagCloud.php

    r51462 r51565  
    130130        );
    131131
    132         $this->assertRegExp( "|^<ul class='wp-tag-cloud' role='list'>|", $found );
    133         $this->assertRegExp( "|</ul>\n|", $found );
     132        $this->assertMatchesRegularExpression( "|^<ul class='wp-tag-cloud' role='list'>|", $found );
     133        $this->assertMatchesRegularExpression( "|</ul>\n|", $found );
    134134        $this->assertStringContainsString( '>' . $tags[0]->name . '<', $found );
    135135    }
     
    185185        );
    186186
    187         $this->assertRegExp( "|^<ul class='wp-tag-cloud' role='list'>|", $found );
    188         $this->assertRegExp( "|</ul>\n|", $found );
     187        $this->assertMatchesRegularExpression( "|^<ul class='wp-tag-cloud' role='list'>|", $found );
     188        $this->assertMatchesRegularExpression( "|</ul>\n|", $found );
    189189
    190190        foreach ( $tags as $tag ) {
  • trunk/tests/phpunit/tests/widgets.php

    r51462 r51565  
    799799        unregister_widget( 'WP_Widget_Text' );
    800800
    801         $this->assertRegExp( '/<span class="special widget_text">/', $actual );
     801        $this->assertMatchesRegularExpression( '/<span class="special widget_text">/', $actual );
    802802
    803803    }
Note: See TracChangeset for help on using the changeset viewer.