Skip to content

Commit 2851328

Browse files
author
costdev
committed
Add tests for ::chmod().
1 parent 623062c commit 2851328

File tree

1 file changed

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

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Tests for the WP_Filesystem_Direct::chmod() 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::chmod
16+
*/
17+
class Tests_Filesystem_WpFilesystemDirect_Chmod extends WP_Filesystem_Direct_UnitTestCase {
18+
19+
/**
20+
* Tests that `WP_Filesystem_Direct::chmod()`
21+
* returns false for a path that does not exist.
22+
*
23+
* @ticket 57774
24+
*
25+
* @dataProvider data_paths_that_do_not_exist
26+
*
27+
* @param string $path The path.
28+
*/
29+
public function test_should_return_false( $path ) {
30+
$this->assertFalse( self::$filesystem->chmod( $path ) );
31+
}
32+
33+
/**
34+
* Tests that `WP_Filesystem_Direct::chmod()` should set
35+
* $mode when it is not passed.
36+
*
37+
* This test runs in a separate process so that it can define
38+
* constants without impacting other tests.
39+
*
40+
* This test does not preserve global state to prevent the exception
41+
* "Serialization of 'Closure' is not allowed." when running in a
42+
* separate process.
43+
*
44+
* @ticket 57774
45+
*
46+
* @dataProvider data_should_set_mode_when_not_passed
47+
*
48+
* @runInSeparateProcess
49+
* @preserveGlobalState disabled
50+
*
51+
* @param string $path The path.
52+
* @param string $type The type of path. "FILE" for file, "DIR" for directory.
53+
*/
54+
public function test_should_handle_set_mode_when_not_passed( $path, $type ) {
55+
define( 'FS_CHMOD_' . $type, ( 'FILE' === $type ? 0644 : 0755 ) );
56+
57+
$this->assertTrue( self::$filesystem->chmod( self::$file_structure['test_dir']['path'] . $path, false ) );
58+
}
59+
60+
/**
61+
* Data provider.
62+
*
63+
* @return array[]
64+
*/
65+
public function data_should_set_mode_when_not_passed() {
66+
return array(
67+
'a file' => array(
68+
'path' => 'a_file_that_exists.txt',
69+
'type' => 'FILE',
70+
),
71+
'a directory' => array(
72+
'path' => '',
73+
'type' => 'DIR',
74+
),
75+
);
76+
}
77+
78+
}

0 commit comments

Comments
 (0)