Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
17.86% |
5 / 28 |
|
33.33% |
2 / 6 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_filesystem_realpath_test | |
17.86% |
5 / 28 |
|
33.33% |
2 / 6 |
43.47 | |
0.00% |
0 / 1 |
| setUpBeforeClass | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setUp | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| realpath_resolve_absolute_without_symlinks_data | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| realpath_resolve_relative_without_symlinks_data | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| test_realpath_absolute_without_links | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_realpath_relative_without_links | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class phpbb_filesystem_realpath_test extends phpbb_test_case |
| 15 | { |
| 16 | protected static $filesystem_own_realpath; |
| 17 | |
| 18 | /** @var \phpbb\filesystem\filesystem_interface */ |
| 19 | protected $filesystem; |
| 20 | |
| 21 | static public function setUpBeforeClass(): void |
| 22 | { |
| 23 | parent::setUpBeforeClass(); |
| 24 | |
| 25 | $reflection_class = new ReflectionClass('\phpbb\filesystem\filesystem'); |
| 26 | self::$filesystem_own_realpath = $reflection_class->getMethod('phpbb_own_realpath'); |
| 27 | } |
| 28 | |
| 29 | protected function setUp(): void |
| 30 | { |
| 31 | parent::setUp(); |
| 32 | |
| 33 | $this->filesystem = new \phpbb\filesystem\filesystem(); |
| 34 | } |
| 35 | |
| 36 | public static function realpath_resolve_absolute_without_symlinks_data() |
| 37 | { |
| 38 | return array( |
| 39 | // Constant data |
| 40 | array(__DIR__, __DIR__), |
| 41 | array(__DIR__ . '/../filesystem/../filesystem', __DIR__), |
| 42 | array(__DIR__ . '/././', __DIR__), |
| 43 | array(__DIR__ . '/non_existent', false), |
| 44 | array(null, getcwd()), |
| 45 | |
| 46 | array(__FILE__, __FILE__), |
| 47 | array(__FILE__ . '../', false), |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | public static function realpath_resolve_relative_without_symlinks_data() |
| 52 | { |
| 53 | if (!function_exists('getcwd')) |
| 54 | { |
| 55 | return array(); |
| 56 | } |
| 57 | |
| 58 | $filesystem = new \phpbb\filesystem\filesystem(); |
| 59 | $relative_path = $filesystem->make_path_relative(__DIR__, getcwd()); |
| 60 | |
| 61 | return array( |
| 62 | array($relative_path, __DIR__), |
| 63 | array($relative_path . '../filesystem/../filesystem', __DIR__), |
| 64 | array($relative_path . '././', __DIR__), |
| 65 | |
| 66 | array($relative_path . 'realpath_test.php', __FILE__), |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @dataProvider realpath_resolve_absolute_without_symlinks_data |
| 72 | */ |
| 73 | public function test_realpath_absolute_without_links($path, $expected) |
| 74 | { |
| 75 | $this->assertEquals($expected, self::$filesystem_own_realpath->invoke($this->filesystem, $path)); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @dataProvider realpath_resolve_relative_without_symlinks_data |
| 80 | */ |
| 81 | public function test_realpath_relative_without_links($path, $expected) |
| 82 | { |
| 83 | if (!function_exists('getcwd')) |
| 84 | { |
| 85 | $this->markTestSkipped('phpbb_own_realpath() cannot be tested with relative paths: getcwd is not available.'); |
| 86 | } |
| 87 | |
| 88 | $this->assertEquals($expected, self::$filesystem_own_realpath->invoke($this->filesystem, $path)); |
| 89 | } |
| 90 | } |