Skip to content

Commit ef79628

Browse files
author
costdev
committed
Add tests for ::copy().
1 parent 3140bc5 commit ef79628

File tree

1 file changed

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

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Tests for the WP_Filesystem_Direct::copy() 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::copy
16+
*/
17+
class Tests_Filesystem_WpFilesystemDirect_Copy extends WP_Filesystem_Direct_UnitTestCase {
18+
19+
/**
20+
* Tests that `WP_Filesystem_Direct::copy()` overwrites an existing
21+
* destination when overwriting is enabled.
22+
*
23+
* @ticket 57774
24+
*/
25+
public function test_should_overwrite_an_existing_file_when_overwriting_is_enabled() {
26+
$source = self::$file_structure['visible_file']['path'];
27+
$destination = self::$file_structure['test_dir']['path'] . 'a_file_that_exists.dest';
28+
29+
if ( ! file_exists( $destination ) ) {
30+
touch( $destination );
31+
}
32+
33+
$actual = self::$filesystem->copy( $source, $destination, true );
34+
35+
unlink( $destination );
36+
37+
$this->assertTrue( $actual );
38+
}
39+
40+
/**
41+
* Tests that `WP_Filesystem_Direct::copy()` does not overwrite
42+
* an existing destination when overwriting is disabled.
43+
*
44+
* @ticket 57774
45+
*/
46+
public function test_should_not_overwrite_an_existing_file_when_overwriting_is_disabled() {
47+
$source = self::$file_structure['test_dir']['path'] . 'a_file_that_exists.txt';
48+
$destination = self::$file_structure['test_dir']['path'] . 'a_file_that_exists.dest';
49+
50+
if ( ! file_exists( $destination ) ) {
51+
touch( $destination );
52+
}
53+
54+
$actual = self::$filesystem->copy( $source, $destination );
55+
56+
unlink( $destination );
57+
58+
$this->assertFalse( $actual );
59+
}
60+
61+
/**
62+
* Tests that `WP_Filesystem_Direct::copy()` does not overwrite an existing
63+
* destination when overwriting is enabled and the source and destination
64+
* are the same.
65+
*
66+
* @ticket 57774
67+
*/
68+
public function test_should_not_overwrite_when_overwriting_is_enabled_and_source_and_destination_are_the_same() {
69+
$source = self::$file_structure['test_dir']['path'] . 'a_file_that_exists.txt';
70+
$this->assertFalse( self::$filesystem->copy( $source, $source, true ) );
71+
}
72+
73+
}

0 commit comments

Comments
 (0)