Skip to content

Commit

Permalink
Tests: replace assert[Not]Contains() with `assertString[Not]Contain…
Browse files Browse the repository at this point in the history
…sString()`

... when used with strings.

Using `assertContains()` and `assertNotContains()` with string haystacks was soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

For string haystacks, the `assertStringContainsString()`, `assertStringContainsStringIgnoringCase()`, `assertStringNotContainsString()` and `assertStringNotContainsStringIgnoringCase()` were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3422
  • Loading branch information
jrfnl committed Aug 16, 2020
1 parent bc70d3a commit ccd4948
Show file tree
Hide file tree
Showing 93 changed files with 795 additions and 795 deletions.
44 changes: 22 additions & 22 deletions tests/phpunit/tests/admin/includesListTable.php
Expand Up @@ -221,7 +221,7 @@ protected function _test_list_hierarchical_page( array $args, array $expected_id
$this->assertCount( count( $expected_ids ), array_keys( $matches[0] ) );

foreach ( $expected_ids as $id ) {
$this->assertContains( sprintf( 'id="post-%d"', $id ), $output );
$this->assertStringContainsString( sprintf( 'id="post-%d"', $id ), $output );
}
}

Expand All @@ -236,7 +236,7 @@ function test_filter_button_should_not_be_shown_if_there_are_no_posts() {
$this->table->extra_tablenav( 'top' );
$output = ob_get_clean();

$this->assertNotContains( 'id="post-query-submit"', $output );
$this->assertStringNotContainsString( 'id="post-query-submit"', $output );
}

/**
Expand All @@ -250,7 +250,7 @@ function test_months_dropdown_should_not_be_shown_if_there_are_no_posts() {
$this->table->extra_tablenav( 'top' );
$output = ob_get_clean();

$this->assertNotContains( 'id="filter-by-date"', $output );
$this->assertStringNotContainsString( 'id="filter-by-date"', $output );
}

/**
Expand All @@ -264,7 +264,7 @@ function test_category_dropdown_should_not_be_shown_if_there_are_no_posts() {
$this->table->extra_tablenav( 'top' );
$output = ob_get_clean();

$this->assertNotContains( 'id="cat"', $output );
$this->assertStringNotContainsString( 'id="cat"', $output );
}

/**
Expand All @@ -278,7 +278,7 @@ public function test_empty_trash_button_should_not_be_shown_if_there_are_no_post
$this->table->extra_tablenav( 'top' );
$output = ob_get_clean();

$this->assertNotContains( 'id="delete_all"', $output );
$this->assertStringNotContainsString( 'id="delete_all"', $output );
}

/**
Expand All @@ -291,7 +291,7 @@ public function test_filter_button_should_not_be_shown_if_there_are_no_comments(
$table->extra_tablenav( 'top' );
$output = ob_get_clean();

$this->assertNotContains( 'id="post-query-submit"', $output );
$this->assertStringNotContainsString( 'id="post-query-submit"', $output );
}

/**
Expand All @@ -313,7 +313,7 @@ public function test_filter_button_should_be_shown_if_there_are_comments() {
$table->extra_tablenav( 'top' );
$output = ob_get_clean();

$this->assertContains( 'id="post-query-submit"', $output );
$this->assertStringContainsString( 'id="post-query-submit"', $output );
}

/**
Expand All @@ -335,8 +335,8 @@ public function test_filter_comment_status_dropdown_should_be_shown_if_there_are
$table->extra_tablenav( 'top' );
$output = ob_get_clean();

$this->assertContains( 'id="filter-by-comment-type"', $output );
$this->assertContains( "<option value='comment'>", $output );
$this->assertStringContainsString( 'id="filter-by-comment-type"', $output );
$this->assertStringContainsString( "<option value='comment'>", $output );
}

/**
Expand All @@ -349,7 +349,7 @@ public function test_empty_trash_button_should_not_be_shown_if_there_are_no_comm
$table->extra_tablenav( 'top' );
$output = ob_get_clean();

$this->assertNotContains( 'id="delete_all"', $output );
$this->assertStringNotContainsString( 'id="delete_all"', $output );
}

/**
Expand All @@ -376,14 +376,14 @@ public function test_sortable_columns() {

$output = get_echo( array( $object, 'print_column_headers' ) );

$this->assertContains( '?orderby=comment_author&#038;order=desc', $output, 'Mismatch of the default link ordering for comment author column. Should be desc.' );
$this->assertContains( 'column-author sortable asc', $output, 'Mismatch of CSS classes for the comment author column.' );
$this->assertStringContainsString( '?orderby=comment_author&#038;order=desc', $output, 'Mismatch of the default link ordering for comment author column. Should be desc.' );
$this->assertStringContainsString( 'column-author sortable asc', $output, 'Mismatch of CSS classes for the comment author column.' );

$this->assertContains( '?orderby=comment_post_ID&#038;order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
$this->assertContains( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
$this->assertStringContainsString( '?orderby=comment_post_ID&#038;order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
$this->assertStringContainsString( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );

$this->assertContains( '?orderby=comment_date&#038;order=desc', $output, 'Mismatch of the default link ordering for comment date column. Should be asc.' );
$this->assertContains( 'column-date sortable asc', $output, 'Mismatch of CSS classes for the comment date column.' );
$this->assertStringContainsString( '?orderby=comment_date&#038;order=desc', $output, 'Mismatch of the default link ordering for comment date column. Should be asc.' );
$this->assertStringContainsString( 'column-date sortable asc', $output, 'Mismatch of CSS classes for the comment date column.' );
}

/**
Expand Down Expand Up @@ -414,14 +414,14 @@ public function test_sortable_columns_with_current_ordering() {

$output = get_echo( array( $object, 'print_column_headers' ) );

$this->assertContains( '?orderby=comment_author&#038;order=asc', $output, 'Mismatch of the default link ordering for comment author column. Should be asc.' );
$this->assertContains( 'column-author sortable desc', $output, 'Mismatch of CSS classes for the comment author column.' );
$this->assertStringContainsString( '?orderby=comment_author&#038;order=asc', $output, 'Mismatch of the default link ordering for comment author column. Should be asc.' );
$this->assertStringContainsString( 'column-author sortable desc', $output, 'Mismatch of CSS classes for the comment author column.' );

$this->assertContains( '?orderby=comment_post_ID&#038;order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
$this->assertContains( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );
$this->assertStringContainsString( '?orderby=comment_post_ID&#038;order=asc', $output, 'Mismatch of the default link ordering for comment response column. Should be asc.' );
$this->assertStringContainsString( 'column-response sortable desc', $output, 'Mismatch of CSS classes for the comment post ID column.' );

$this->assertContains( '?orderby=comment_date&#038;order=asc', $output, 'Mismatch of the current link ordering for comment date column. Should be asc.' );
$this->assertContains( 'column-date sorted desc', $output, 'Mismatch of CSS classes for the comment date column.' );
$this->assertStringContainsString( '?orderby=comment_date&#038;order=asc', $output, 'Mismatch of the current link ordering for comment date column. Should be asc.' );
$this->assertStringContainsString( 'column-date sorted desc', $output, 'Mismatch of CSS classes for the comment date column.' );
}

}
26 changes: 13 additions & 13 deletions tests/phpunit/tests/admin/includesPost.php
Expand Up @@ -391,8 +391,8 @@ public function test_get_sample_permalink_html_should_use_default_permalink_for_
);

$found = get_sample_permalink_html( $p );
$this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found );
$this->assertContains( '>' . get_option( 'home' ) . '/?p=' . $p . '<', $found );
$this->assertStringContainsString( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found );
$this->assertStringContainsString( '>' . get_option( 'home' ) . '/?p=' . $p . '<', $found );
}

/**
Expand All @@ -415,8 +415,8 @@ public function test_get_sample_permalink_html_should_use_pretty_permalink_for_v

$found = get_sample_permalink_html( $p );
$post = get_post( $p );
$this->assertContains( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found );
$this->assertContains( '>' . urldecode( $post->post_name ) . '<', $found );
$this->assertStringContainsString( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found );
$this->assertStringContainsString( '>' . urldecode( $post->post_name ) . '<', $found );
}

/**
Expand All @@ -440,8 +440,8 @@ public function test_get_sample_permalink_html_should_use_pretty_permalink_for_v

$found = get_sample_permalink_html( $p );
$post = get_post( $p );
$this->assertContains( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found );
$this->assertContains( '>' . urldecode( get_permalink( $post ) ) . '<', $found );
$this->assertStringContainsString( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found );
$this->assertStringContainsString( '>' . urldecode( get_permalink( $post ) ) . '<', $found );
}

/**
Expand All @@ -464,8 +464,8 @@ public function test_get_sample_permalink_html_should_use_correct_permalink_for_
$found = get_sample_permalink_html( $p, null, 'new_slug-صورة' );
$post = get_post( $p );
$message = 'Published post';
$this->assertContains( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found, $message );
$this->assertContains( '>new_slug-صورة<', $found, $message );
$this->assertStringContainsString( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found, $message );
$this->assertStringContainsString( '>new_slug-صورة<', $found, $message );

// Scheduled posts should use published permalink.
$future_date = gmdate( 'Y-m-d H:i:s', time() + 100 );
Expand All @@ -480,8 +480,8 @@ public function test_get_sample_permalink_html_should_use_correct_permalink_for_
$found = get_sample_permalink_html( $p, null, 'new_slug-صورة' );
$post = get_post( $p );
$message = 'Scheduled post';
$this->assertContains( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found, $message );
$this->assertContains( '>new_slug-صورة<', $found, $message );
$this->assertStringContainsString( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found, $message );
$this->assertStringContainsString( '>new_slug-صورة<', $found, $message );

// Draft posts should use preview link.
$p = self::factory()->post->create(
Expand All @@ -498,8 +498,8 @@ public function test_get_sample_permalink_html_should_use_correct_permalink_for_
$preview_link = get_permalink( $post->ID );
$preview_link = add_query_arg( 'preview', 'true', $preview_link );

$this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message );
$this->assertContains( '>new_slug-صورة<', $found, $message );
$this->assertStringContainsString( 'href="' . esc_url( $preview_link ) . '"', $found, $message );
$this->assertStringContainsString( '>new_slug-صورة<', $found, $message );
}

/**
Expand All @@ -522,7 +522,7 @@ public function test_get_sample_permalink_html_should_use_preview_links_for_draf

$found = get_sample_permalink_html( $p );
$post = get_post( $p );
$this->assertContains( 'href="' . esc_url( get_preview_post_link( $post ) ), $found );
$this->assertStringContainsString( 'href="' . esc_url( get_preview_post_link( $post ) ), $found );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/admin/includesTemplate.php
Expand Up @@ -188,8 +188,8 @@ public function test_settings_errors_css_classes( $type, $expected ) {

$expected = sprintf( 'notice %s settings-error is-dismissible', $expected );

$this->assertContains( $expected, $output );
$this->assertNotContains( 'notice-notice-', $output );
$this->assertStringContainsString( $expected, $output );
$this->assertStringNotContainsString( 'notice-notice-', $output );
}

public function settings_errors_css_classes_provider() {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/admin/wpPrivacyRequestsTable.php
Expand Up @@ -82,7 +82,7 @@ public function test_columns_should_be_sortable( $order, $orderby, $search, $exp
unset( $_REQUEST['orderby'] );
unset( $_REQUEST['s'] );

$this->assertContains( "ORDER BY {$wpdb->posts}.{$expected}", $this->sql );
$this->assertStringContainsString( "ORDER BY {$wpdb->posts}.{$expected}", $this->sql );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/adminbar.php
Expand Up @@ -264,7 +264,7 @@ public function test_admin_bar_with_tabindex_meta( $node_data, $expected_html )
$admin_bar = new WP_Admin_Bar();
$admin_bar->add_node( $node_data );
$admin_bar_html = get_echo( array( $admin_bar, 'render' ) );
$this->assertContains( $expected_html, $admin_bar_html );
$this->assertStringContainsString( $expected_html, $admin_bar_html );
}

/**
Expand Down Expand Up @@ -688,7 +688,7 @@ public function test_customize_link() {
$query_params = array();
wp_parse_str( $parsed_url['query'], $query_params );
$this->assertEquals( $uuid, $query_params['changeset_uuid'] );
$this->assertNotContains( 'changeset_uuid', $query_params['url'] );
$this->assertStringNotContainsString( 'changeset_uuid', $query_params['url'] );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/ajax/Compression.php
Expand Up @@ -50,7 +50,7 @@ public function test_text() {
}

// Ensure we found the right match.
$this->assertContains( 'wpCompressionTest', $this->_last_response );
$this->assertStringContainsString( 'wpCompressionTest', $this->_last_response );
}

/**
Expand All @@ -77,7 +77,7 @@ public function test_gzdeflate() {
}

// Ensure we found the right match.
$this->assertContains( 'wpCompressionTest', gzinflate( $this->_last_response ) );
$this->assertStringContainsString( 'wpCompressionTest', gzinflate( $this->_last_response ) );
}

/**
Expand All @@ -104,7 +104,7 @@ public function test_gzencode() {
}

// Ensure we found the right match.
$this->assertContains( 'wpCompressionTest', $this->_gzdecode( $this->_last_response ) );
$this->assertStringContainsString( 'wpCompressionTest', $this->_gzdecode( $this->_last_response ) );
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/tests/ajax/CustomizeManager.php
Expand Up @@ -474,8 +474,8 @@ public function test_save_autosave() {
$autosave_revision = wp_get_post_autosave( $post_id );
$this->assertInstanceOf( 'WP_Post', $autosave_revision );

$this->assertContains( 'New Site Title', get_post( $post_id )->post_content );
$this->assertContains( 'Autosaved Site Title', $autosave_revision->post_content );
$this->assertStringContainsString( 'New Site Title', get_post( $post_id )->post_content );
$this->assertStringContainsString( 'Autosaved Site Title', $autosave_revision->post_content );
}

/**
Expand Down Expand Up @@ -679,7 +679,7 @@ public function test_handle_dismiss_autosave_or_lock_request() {
$_REQUEST['dismiss_autosave'] = true;
$this->assertNotWPError( $r );
$this->assertFalse( wp_get_post_autosave( $wp_customize->changeset_post_id() ) );
$this->assertContains( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content );
$this->assertStringContainsString( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content );

// Since no autosave yet, confirm no action.
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
Expand All @@ -700,8 +700,8 @@ public function test_handle_dismiss_autosave_or_lock_request() {
$this->assertNotWPError( $r );
$autosave_revision = wp_get_post_autosave( $wp_customize->changeset_post_id() );
$this->assertInstanceOf( 'WP_Post', $autosave_revision );
$this->assertContains( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content );
$this->assertContains( 'Bar', $autosave_revision->post_content );
$this->assertStringContainsString( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content );
$this->assertStringContainsString( 'Bar', $autosave_revision->post_content );

// Confirm autosave gets deleted.
$this->make_ajax_call( 'customize_dismiss_autosave_or_lock' );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/ajax/DimComment.php
Expand Up @@ -199,7 +199,7 @@ public function test_with_bad_id() {
// Ensure everything is correct.
$this->assertEquals( '0', (string) $xml->response[0]->comment['id'] );
$this->assertEquals( 'dim-comment_0', (string) $xml->response['action'] );
$this->assertContains( 'Comment ' . $_POST['id'] . ' does not exist', $this->_last_response );
$this->assertStringContainsString( 'Comment ' . $_POST['id'] . ' does not exist', $this->_last_response );

} catch ( Exception $e ) {
$this->fail( 'Unexpected exception type: ' . get_class( $e ) );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/ajax/ReplytoComment.php
Expand Up @@ -223,7 +223,7 @@ public function test_blocked_comment() {
$this->fail();
} catch ( WPAjaxDieStopException $e ) {
$wpdb->suppress_errors( false );
$this->assertContains( '1', $e->getMessage() );
$this->assertStringContainsString( '1', $e->getMessage() );
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/blocks/render.php
Expand Up @@ -304,7 +304,7 @@ public function test_render_latest_comments_on_password_protected_post() {
);
$comments = do_blocks( '<!-- wp:latest-comments {"commentsToShow":1,"displayExcerpt":true} /-->' );

$this->assertNotContains( $comment_text, $comments );
$this->assertStringNotContainsString( $comment_text, $comments );
}

/**
Expand Down
18 changes: 9 additions & 9 deletions tests/phpunit/tests/category/wpDropdownCategories.php
Expand Up @@ -25,7 +25,7 @@ public function test_wp_dropdown_categories_value_field_should_default_to_term_i
);

// Test to see if it returns the default with the category ID.
$this->assertContains( 'value="' . $cat_id . '"', $dropdown_default );
$this->assertStringContainsString( 'value="' . $cat_id . '"', $dropdown_default );
}

/**
Expand All @@ -50,7 +50,7 @@ public function test_wp_dropdown_categories_value_field_term_id() {
);

// Test to see if it returns the default with the category ID.
$this->assertContains( 'value="' . $cat_id . '"', $found );
$this->assertStringContainsString( 'value="' . $cat_id . '"', $found );
}

/**
Expand All @@ -75,7 +75,7 @@ public function test_wp_dropdown_categories_value_field_slug() {
);

// Test to see if it returns the default with the category slug.
$this->assertContains( 'value="test_category"', $found );
$this->assertStringContainsString( 'value="test_category"', $found );
}

/**
Expand All @@ -100,7 +100,7 @@ public function test_wp_dropdown_categories_value_field_should_fall_back_on_term
);

// Test to see if it returns the default with the category slug.
$this->assertContains( 'value="' . $cat_id . '"', $found );
$this->assertStringContainsString( 'value="' . $cat_id . '"', $found );
}

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ public function test_wp_dropdown_categories_selected_should_respect_custom_value
)
);

$this->assertContains( 'value="test_category_2" selected="selected"', $found );
$this->assertStringContainsString( 'value="test_category_2" selected="selected"', $found );
}

/**
Expand All @@ -148,11 +148,11 @@ public function test_wp_dropdown_categories_show_option_all_should_be_selected_i
)
);

$this->assertContains( "value='0' selected='selected'", $found );
$this->assertStringContainsString( "value='0' selected='selected'", $found );

foreach ( $cats as $cat ) {
$_cat = get_term( $cat, 'category' );
$this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found );
$this->assertStringNotContainsString( 'value="' . $_cat->slug . '" selected="selected"', $found );
}
}

Expand All @@ -172,11 +172,11 @@ public function test_wp_dropdown_categories_show_option_all_should_be_selected_i
)
);

$this->assertContains( "value='0' selected='selected'", $found );
$this->assertStringContainsString( "value='0' selected='selected'", $found );

foreach ( $cats as $cat ) {
$_cat = get_term( $cat, 'category' );
$this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found );
$this->assertStringNotContainsString( 'value="' . $_cat->slug . '" selected="selected"', $found );
}
}

Expand Down

0 comments on commit ccd4948

Please sign in to comment.