Skip to content

Commit 991afdd

Browse files
author
costdev
committed
Add tests for ::is_dir().
1 parent 278a322 commit 991afdd

File tree

1 file changed

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

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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()` determines that
21+
* a path is a directory.
22+
*
23+
* @ticket 57774
24+
*/
25+
public function test_should_determine_that_a_path_is_a_directory() {
26+
$this->assertTrue( self::$filesystem->is_dir( self::$file_structure['test_dir']['path'] ) );
27+
}
28+
29+
/**
30+
* Tests that `WP_Filesystem_Direct::is_directory()` determines that
31+
* a path is not a directory.
32+
*
33+
* @ticket 57774
34+
*
35+
* @dataProvider data_should_determine_that_a_path_is_not_a_directory
36+
*
37+
* @param string $path The path to check.
38+
* @param string $type The type of resource. Accepts 'f' or 'd'.
39+
* Used to invert $expected due to data provider setup.
40+
*/
41+
public function test_should_determine_that_a_path_is_not_a_directory( $path ) {
42+
$this->assertFalse( self::$filesystem->is_dir( self::$file_structure['test_dir']['path'] . $path ) );
43+
}
44+
45+
/**
46+
* Data provider.
47+
*
48+
* @return array[]
49+
*/
50+
public function data_should_determine_that_a_path_is_not_a_directory() {
51+
return array(
52+
'a file that exists' => array(
53+
'path' => 'a_file_that_exists.txt',
54+
),
55+
'a file that does not exist' => array(
56+
'path' => 'a_file_that_does_not_exist.txt',
57+
),
58+
'a directory that does not exist' => array(
59+
'path' => 'a_directory_that_does_not_exist',
60+
),
61+
);
62+
}
63+
}

0 commit comments

Comments
 (0)