forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopyDir.php
More file actions
83 lines (66 loc) · 2.05 KB
/
copyDir.php
File metadata and controls
83 lines (66 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Tests copy_dir().
*
* @group file
* @group filesystem
*
* @covers ::copy_dir
*/
class Tests_Filesystem_CopyDir extends WP_UnitTestCase {
/**
* The test directory.
*
* @var string $test_dir
*/
private static $test_dir;
/**
* Sets up the filesystem and test directory before any tests run.
*/
public static function set_up_before_class() {
parent::set_up_before_class();
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
self::$test_dir = get_temp_dir() . 'copy_dir/';
}
/**
* Sets up the test directory before each test.
*/
public function set_up() {
global $wp_filesystem;
parent::set_up();
// Create the root directory.
$wp_filesystem->mkdir( self::$test_dir );
}
/**
* Removes the test directory after each test.
*/
public function tear_down() {
global $wp_filesystem;
// Delete the root directory and its contents.
$wp_filesystem->delete( self::$test_dir, true );
parent::tear_down();
}
/**
* Tests that the destination is created if it does not already exist.
*
* @ticket 41855
*/
public function test_should_create_destination_it_if_does_not_exist() {
global $wp_filesystem;
$from = self::$test_dir . 'folder1/folder2/';
$to = self::$test_dir . 'folder3/folder2/';
// Create the file structure for the test.
$wp_filesystem->mkdir( self::$test_dir . 'folder1' );
$wp_filesystem->mkdir( self::$test_dir . 'folder3' );
$wp_filesystem->mkdir( $from );
$wp_filesystem->touch( $from . 'file1.txt' );
$wp_filesystem->mkdir( $from . 'subfolder1' );
$wp_filesystem->touch( $from . 'subfolder1/file2.txt' );
$this->assertTrue( copy_dir( $from, $to ), 'copy_dir() failed.' );
$this->assertDirectoryExists( $to, 'The destination was not created.' );
$this->assertFileExists( $to . 'file1.txt', 'The destination file was not created.' );
$this->assertDirectoryExists( $to . 'subfolder1/', 'The destination subfolder was not created.' );
$this->assertFileExists( $to . 'subfolder1/file2.txt', 'The destination subfolder file was not created.' );
}
}