mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51462 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -823,12 +823,12 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains( 'src="https://example.com/foo.mp3', $actual );
|
||||
$this->assertNotContains( 'loop', $actual );
|
||||
$this->assertNotContains( 'autoplay', $actual );
|
||||
$this->assertContains( 'preload="none"', $actual );
|
||||
$this->assertContains( 'class="wp-audio-shortcode"', $actual );
|
||||
$this->assertContains( 'style="width: 100%;"', $actual );
|
||||
$this->assertStringContainsString( 'src="https://example.com/foo.mp3', $actual );
|
||||
$this->assertStringNotContainsString( 'loop', $actual );
|
||||
$this->assertStringNotContainsString( 'autoplay', $actual );
|
||||
$this->assertStringContainsString( 'preload="none"', $actual );
|
||||
$this->assertStringContainsString( 'class="wp-audio-shortcode"', $actual );
|
||||
$this->assertStringContainsString( 'style="width: 100%;"', $actual );
|
||||
|
||||
$actual = wp_audio_shortcode(
|
||||
array(
|
||||
@@ -841,12 +841,12 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains( 'src="https://example.com/foo.mp3', $actual );
|
||||
$this->assertContains( 'loop="1"', $actual );
|
||||
$this->assertContains( 'autoplay="1"', $actual );
|
||||
$this->assertContains( 'preload="1"', $actual );
|
||||
$this->assertContains( 'class="foobar"', $actual );
|
||||
$this->assertContains( 'style="padding:0;"', $actual );
|
||||
$this->assertStringContainsString( 'src="https://example.com/foo.mp3', $actual );
|
||||
$this->assertStringContainsString( 'loop="1"', $actual );
|
||||
$this->assertStringContainsString( 'autoplay="1"', $actual );
|
||||
$this->assertStringContainsString( 'preload="1"', $actual );
|
||||
$this->assertStringContainsString( 'class="foobar"', $actual );
|
||||
$this->assertStringContainsString( 'style="padding:0;"', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -928,13 +928,13 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains( 'src="https://example.com/foo.mp4', $actual );
|
||||
$this->assertNotContains( 'loop', $actual );
|
||||
$this->assertNotContains( 'autoplay', $actual );
|
||||
$this->assertContains( 'preload="metadata"', $actual );
|
||||
$this->assertContains( 'width="640"', $actual );
|
||||
$this->assertContains( 'height="360"', $actual );
|
||||
$this->assertContains( 'class="wp-video-shortcode"', $actual );
|
||||
$this->assertStringContainsString( 'src="https://example.com/foo.mp4', $actual );
|
||||
$this->assertStringNotContainsString( 'loop', $actual );
|
||||
$this->assertStringNotContainsString( 'autoplay', $actual );
|
||||
$this->assertStringContainsString( 'preload="metadata"', $actual );
|
||||
$this->assertStringContainsString( 'width="640"', $actual );
|
||||
$this->assertStringContainsString( 'height="360"', $actual );
|
||||
$this->assertStringContainsString( 'class="wp-video-shortcode"', $actual );
|
||||
|
||||
$actual = wp_video_shortcode(
|
||||
array(
|
||||
@@ -949,14 +949,14 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains( 'src="https://example.com/foo.mp4', $actual );
|
||||
$this->assertContains( 'poster="https://example.com/foo.png', $actual );
|
||||
$this->assertContains( 'loop="1"', $actual );
|
||||
$this->assertContains( 'autoplay="1"', $actual );
|
||||
$this->assertContains( 'preload="1"', $actual );
|
||||
$this->assertContains( 'width="123"', $actual );
|
||||
$this->assertContains( 'height="456"', $actual );
|
||||
$this->assertContains( 'class="foobar"', $actual );
|
||||
$this->assertStringContainsString( 'src="https://example.com/foo.mp4', $actual );
|
||||
$this->assertStringContainsString( 'poster="https://example.com/foo.png', $actual );
|
||||
$this->assertStringContainsString( 'loop="1"', $actual );
|
||||
$this->assertStringContainsString( 'autoplay="1"', $actual );
|
||||
$this->assertStringContainsString( 'preload="1"', $actual );
|
||||
$this->assertStringContainsString( 'width="123"', $actual );
|
||||
$this->assertStringContainsString( 'height="456"', $actual );
|
||||
$this->assertStringContainsString( 'class="foobar"', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -970,7 +970,7 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertNotContains( 'feature=youtu.be', $actual );
|
||||
$this->assertStringNotContainsString( 'feature=youtu.be', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -984,7 +984,7 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains( 'src="https://www.youtube.com/watch?v=72xdCU__XCk', $actual );
|
||||
$this->assertStringContainsString( 'src="https://www.youtube.com/watch?v=72xdCU__XCk', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -998,8 +998,8 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains( 'src="https://vimeo.com/76979871', $actual );
|
||||
$this->assertNotContains( 'blah=meh', $actual );
|
||||
$this->assertStringContainsString( 'src="https://vimeo.com/76979871', $actual );
|
||||
$this->assertStringNotContainsString( 'blah=meh', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1013,7 +1013,7 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains( 'src="https://vimeo.com/76979871?loop=0', $actual );
|
||||
$this->assertStringContainsString( 'src="https://vimeo.com/76979871?loop=0', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1028,7 +1028,7 @@ VIDEO;
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains( 'src="https://vimeo.com/76979871?loop=1', $actual );
|
||||
$this->assertStringContainsString( 'src="https://vimeo.com/76979871?loop=1', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2862,7 +2862,7 @@ EOF;
|
||||
$img = '<img src="example.png" alt=" width="300" height="225" />';
|
||||
$img = wp_img_tag_add_loading_attr( $img, 'test' );
|
||||
|
||||
$this->assertContains( ' loading="lazy"', $img );
|
||||
$this->assertStringContainsString( ' loading="lazy"', $img );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2873,7 +2873,7 @@ EOF;
|
||||
$img = '<img alt=" width="300" height="225" />';
|
||||
$img = wp_img_tag_add_loading_attr( $img, 'test' );
|
||||
|
||||
$this->assertNotContains( ' loading=', $img );
|
||||
$this->assertStringNotContainsString( ' loading=', $img );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2884,11 +2884,11 @@ EOF;
|
||||
$img = "<img src='example.png' alt=' width='300' height='225' />";
|
||||
$img = wp_img_tag_add_loading_attr( $img, 'test' );
|
||||
|
||||
$this->assertNotContains( ' loading=', $img );
|
||||
$this->assertStringNotContainsString( ' loading=', $img );
|
||||
|
||||
// Test specifically that the attribute is not there with double-quotes,
|
||||
// to avoid regressions.
|
||||
$this->assertNotContains( ' loading="lazy"', $img );
|
||||
$this->assertStringNotContainsString( ' loading="lazy"', $img );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2899,7 +2899,7 @@ EOF;
|
||||
$img = '<img src="example.png" alt=" width="300" height="225" />';
|
||||
add_filter( 'wp_img_tag_add_loading_attr', '__return_false' );
|
||||
|
||||
$this->assertNotContains( ' loading=', $img );
|
||||
$this->assertStringNotContainsString( ' loading=', $img );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2909,7 +2909,7 @@ EOF;
|
||||
$iframe = '<iframe src="https://www.example.com" width="640" height="360"></iframe>';
|
||||
$iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' );
|
||||
|
||||
$this->assertContains( ' loading="lazy"', $iframe );
|
||||
$this->assertStringContainsString( ' loading="lazy"', $iframe );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2919,7 +2919,7 @@ EOF;
|
||||
$iframe = '<iframe width="640" height="360"></iframe>';
|
||||
$iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' );
|
||||
|
||||
$this->assertNotContains( ' loading=', $iframe );
|
||||
$this->assertStringNotContainsString( ' loading=', $iframe );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2929,11 +2929,11 @@ EOF;
|
||||
$iframe = "<iframe src='https://www.example.com' width='640' height='360'></iframe>";
|
||||
$iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' );
|
||||
|
||||
$this->assertNotContains( ' loading=', $iframe );
|
||||
$this->assertStringNotContainsString( ' loading=', $iframe );
|
||||
|
||||
// Test specifically that the attribute is not there with double-quotes,
|
||||
// to avoid regressions.
|
||||
$this->assertNotContains( ' loading="lazy"', $iframe );
|
||||
$this->assertStringNotContainsString( ' loading="lazy"', $iframe );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2944,7 +2944,7 @@ EOF;
|
||||
add_filter( 'wp_iframe_tag_add_loading_attr', '__return_false' );
|
||||
$iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' );
|
||||
|
||||
$this->assertNotContains( ' loading=', $iframe );
|
||||
$this->assertStringNotContainsString( ' loading=', $iframe );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2956,7 +2956,7 @@ EOF;
|
||||
$iframe = wp_filter_oembed_result( $fallback . $iframe, (object) array( 'type' => 'rich' ), 'https://www.example.com' );
|
||||
$iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' );
|
||||
|
||||
$this->assertNotContains( ' loading=', $iframe );
|
||||
$this->assertStringNotContainsString( ' loading=', $iframe );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2966,7 +2966,7 @@ EOF;
|
||||
function test_wp_get_attachment_image_loading() {
|
||||
$img = wp_get_attachment_image( self::$large_id );
|
||||
|
||||
$this->assertContains( ' loading="lazy"', $img );
|
||||
$this->assertStringContainsString( ' loading="lazy"', $img );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2978,7 +2978,7 @@ EOF;
|
||||
$img = wp_get_attachment_image( self::$large_id );
|
||||
|
||||
// There should not be any loading attribute in this case.
|
||||
$this->assertNotContains( ' loading=', $img );
|
||||
$this->assertStringNotContainsString( ' loading=', $img );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2993,7 +2993,7 @@ EOF;
|
||||
$img = wp_get_attachment_image( self::$large_id, 'thumbnail', false, array( 'loading' => false ) );
|
||||
|
||||
// There should not be any loading attribute in this case.
|
||||
$this->assertNotContains( ' loading=', $img );
|
||||
$this->assertStringNotContainsString( ' loading=', $img );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3116,7 +3116,7 @@ EOF;
|
||||
'ids' => self::$large_id,
|
||||
)
|
||||
);
|
||||
$this->assertContains( '?attachment_id=', $actual );
|
||||
$this->assertStringContainsString( '?attachment_id=', $actual );
|
||||
|
||||
// File: Links to image file URL.
|
||||
$actual = gallery_shortcode(
|
||||
@@ -3134,7 +3134,7 @@ EOF;
|
||||
'link' => 'none',
|
||||
)
|
||||
);
|
||||
$this->assertNotContains( '<a ', $actual );
|
||||
$this->assertStringNotContainsString( '<a ', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user