Skip to content

Commit 278a322

Browse files
author
costdev
committed
Add tests for ::is_file().
1 parent 64f8560 commit 278a322

File tree

1 file changed

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

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Tests for the WP_Filesystem_Direct::is_file() 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_file
16+
*/
17+
class Tests_Filesystem_WpFilesystemDirect_IsFile extends WP_Filesystem_Direct_UnitTestCase {
18+
19+
/**
20+
* Tests that `WP_Filesystem_Direct::is_file()` determies that
21+
* a path is a file.
22+
*
23+
* @ticket 57774
24+
*/
25+
public function test_should_determine_that_a_path_is_a_file() {
26+
$this->assertTrue( self::$filesystem->is_file( self::$file_structure['test_dir']['path'] . 'a_file_that_exists.txt' ) );
27+
}
28+
29+
/**
30+
* Tests that `WP_Filesystem_Direct::is_file()` determies that
31+
* a path is not a file.
32+
*
33+
* @ticket 57774
34+
*
35+
* @dataProvider data_should_determine_if_a_path_is_not_a_file
36+
*
37+
* @param string $path The path to check.
38+
*/
39+
public function test_should_determine_that_a_path_is_not_a_file( $path ) {
40+
$this->assertFalse( self::$filesystem->is_file( self::$file_structure['test_dir']['path'] . $path ) );
41+
}
42+
43+
/**
44+
* Data provider.
45+
*
46+
* @return array[]
47+
*/
48+
public function data_should_determine_if_a_path_is_not_a_file() {
49+
return array(
50+
'a file that does not exist' => array(
51+
'path' => 'a_file_that_does_not_exist.txt',
52+
),
53+
'a directory that exists' => array(
54+
'path' => '',
55+
),
56+
'a directory that does not exist' => array(
57+
'path' => 'a_directory_that_does_not_exist',
58+
),
59+
);
60+
}
61+
62+
}

0 commit comments

Comments
 (0)