Skip to content

Commit a1154ad

Browse files
author
costdev
committed
Add tests for ::put_contents().
1 parent 02f3a2d commit a1154ad

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Tests for the WP_Filesystem_Direct::put_contents() 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::put_contents
16+
*/
17+
class Tests_Filesystem_WpFilesystemDirect_PutContents extends WP_Filesystem_Direct_UnitTestCase {
18+
19+
/**
20+
* Tests that `WP_Filesystem_Direct::put_contents()`
21+
* returns false for a directory.
22+
*
23+
* @ticket 57774
24+
*/
25+
public function test_should_return_false_for_a_directory() {
26+
$this->assertFalse( self::$filesystem->put_contents( self::$file_structure['test_dir']['path'], 'New content.' ) );
27+
}
28+
29+
/**
30+
* Tests that `WP_Filesystem_Direct::put_contents()` inserts
31+
* content into the provided file.
32+
*
33+
* @ticket 57774
34+
*/
35+
public function test_should_insert_contents_into_file() {
36+
$file = self::$file_structure['test_dir']['path'] . 'file-to-create.txt';
37+
$actual = self::$filesystem->put_contents( $file, 'New content.', 0644 );
38+
unlink( $file );
39+
40+
$this->assertTrue( $actual, 'The contents were not inserted.' );
41+
}
42+
43+
}

0 commit comments

Comments
 (0)