Filesystem API: Add basic tests for `wp_is_stream()`.

Props JPry.
See #44533.

git-svn-id: https://develop.svn.wordpress.org/trunk@43501 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2018-07-18 01:01:28 +00:00
parent b2d63fd056
commit 6f0218d8bc
1 changed files with 38 additions and 0 deletions

View File

@ -1451,4 +1451,42 @@ class Tests_Functions extends WP_UnitTestCase {
);
}
/**
* Test stream URL validation.
*
* @dataProvider data_test_wp_is_stream
*
* @param string $path The resource path or URL.
* @param bool $expected Expected result.
*/
public function test_wp_is_stream( $path, $expected ) {
$this->assertSame( $expected, wp_is_stream( $path ) );
}
/**
* Data provider for stream URL validation.
*
* @return array {
* @type array $0... {
* @type string $0 The resource path or URL.
* @type bool $1 Expected result.
* }
* }
*/
public function data_test_wp_is_stream() {
return array(
// Legitimate stream examples.
array( 'https://example.com', true ),
array( 'ftp://example.com', true ),
array( 'file:///path/to/some/file', true ),
array( 'php://some/php/file.php', true ),
// Non-stream examples.
array( 'fakestream://foo/bar/baz', false ),
array( '../../some/relative/path', false ),
array( 'some/other/relative/path', false ),
array( '/leading/relative/path', false ),
);
}
}