Skip to content

Commit 02f3a2d

Browse files
author
costdev
committed
Add tests for ::get_contents_array().
1 parent 408c12c commit 02f3a2d

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Tests for the WP_Filesystem_Direct::get_contents_array() 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::get_contents_array
16+
*/
17+
class Tests_Filesystem_WpFilesystemDirect_GetContentsArray extends WP_Filesystem_Direct_UnitTestCase {
18+
19+
/**
20+
* Tests that `WP_Filesystem_Direct::get_contents_array()` gets
21+
* the contents of the provided file.
22+
*
23+
* @ticket 57774
24+
*/
25+
public function test_should_get_the_contents_of_a_file_as_an_array() {
26+
$file = self::$file_structure['visible_file']['path'];
27+
$contents = self::$filesystem->get_contents_array( $file );
28+
29+
$this->assertIsArray(
30+
$contents,
31+
'The file contents are not an array.'
32+
);
33+
34+
$this->assertSameSetsWithIndex(
35+
array(
36+
"Contents of a file.\r\n",
37+
"Next line of a file.\r\n",
38+
),
39+
$contents,
40+
'The file contents do not match the expected value.'
41+
);
42+
}
43+
44+
/**
45+
* Tests that `WP_Filesystem_Direct::get_contents_array()`
46+
* returns false for a path that does not exist.
47+
*
48+
* @ticket 57774
49+
*
50+
* @dataProvider data_paths_that_do_not_exist
51+
*
52+
* @param string $path The path.
53+
*/
54+
public function test_should_return_false( $path ) {
55+
$this->assertFalse( self::$filesystem->get_contents_array( self::$file_structure['test_dir']['path'] . $path ) );
56+
}
57+
58+
}

0 commit comments

Comments
 (0)