Skip to content

Commit 20ba6e4

Browse files
author
costdev
committed
Add tests for ::size().
1 parent 0676fc0 commit 20ba6e4

File tree

1 file changed

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

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Tests for the WP_Filesystem_Direct::size() 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::size
16+
*/
17+
class Tests_Filesystem_WpFilesystemDirect_Size extends WP_Filesystem_Direct_UnitTestCase {
18+
19+
/**
20+
* Tests that `WP_Filesystem_Direct::size()` determines
21+
* the file size of a path that exists.
22+
*
23+
* @ticket 57774
24+
*
25+
* @dataProvider data_paths_that_exist
26+
*
27+
* @param string $path The path.
28+
*/
29+
public function test_should_determine_file_size( $path ) {
30+
$result = self::$filesystem->size( self::$file_structure['test_dir']['path'] . $path );
31+
$has_filesize = false !== $result;
32+
33+
$this->assertTrue(
34+
$has_filesize,
35+
'The file size was not determined.'
36+
);
37+
38+
$this->assertIsInt(
39+
$result,
40+
'The file size is not an integer.'
41+
);
42+
}
43+
44+
/**
45+
* Tests that `WP_Filesystem_Direct::size()` does not determine
46+
* the filesize of 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_not_determine_file_size( $path ) {
55+
$result = self::$filesystem->size( self::$file_structure['test_dir']['path'] . $path );
56+
$has_filesize = false !== $result;
57+
58+
$this->assertFalse(
59+
$has_filesize,
60+
'A file size was determined.'
61+
);
62+
}
63+
64+
}

0 commit comments

Comments
 (0)