Skip to content

Commit af7a9d3

Browse files
author
costdev
committed
Add tests for ::is_dir().
1 parent 363919b commit af7a9d3

File tree

1 file changed

+44
-0
lines changed
  • tests/phpunit/tests/filesystem/wpFilesystemDirect

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Tests for the WP_Filesystem_Direct::is_dir() method.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
require_once __DIR__ . '/base.php';
9+
10+
/**
11+
* @group admin
12+
* @group filesystem
13+
* @group filesystem-direct
14+
*
15+
* @covers WP_Filesystem_Direct::is_dir
16+
*/
17+
class Tests_Filesystem_WpFilesystemDirect_IsDir extends WP_Filesystem_Direct_UnitTestCase {
18+
19+
/**
20+
* Tests that `WP_Filesystem_Direct::is_directory()` returns the correct value
21+
* when checking whether a path is a directory.
22+
*
23+
* @ticket 57774
24+
*
25+
* @dataProvider data_paths_that_exist
26+
* @dataProvider data_paths_that_do_not_exist
27+
*
28+
* @param string $path The path to check.
29+
* @param bool $expected The expected result.
30+
* @param string $type The type of resource. Accepts 'f' or 'd'.
31+
* Used to invert $expected due to data provider setup.
32+
*/
33+
public function test_should_determine_if_a_path_is_a_directory( $path, $expected, $type ) {
34+
/*
35+
* Invert the data provider's $expected value for
36+
* files containing "exists" in the name.
37+
*/
38+
if ( 'f' === $type && false !== strpos( $path, 'exists' ) ) {
39+
$expected = ! $expected;
40+
}
41+
42+
$this->assertSame( $expected, self::$filesystem->is_dir( self::$file_structure['test_dir']['path'] . $path ) );
43+
}
44+
}

0 commit comments

Comments
 (0)