mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-22 16:40:21 +01:00
[ticket/15253] Add old tests
PHPBB3-15253
This commit is contained in:
parent
436410761d
commit
7bf1a27db4
54
tests/filesystem/clean_path_test.php
Normal file
54
tests/filesystem/clean_path_test.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_filesystem_clean_path_test extends phpbb_test_case
|
||||
{
|
||||
protected $filesystem;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||
}
|
||||
|
||||
public function clean_path_data()
|
||||
{
|
||||
return array(
|
||||
array('foo', 'foo'),
|
||||
array('foo/bar', 'foo/bar'),
|
||||
array('foo/bar/', 'foo/bar/'),
|
||||
array('foo/./bar', 'foo/bar'),
|
||||
array('foo/./././bar', 'foo/bar'),
|
||||
array('foo/bar/.', 'foo/bar'),
|
||||
array('./foo/bar', './foo/bar'),
|
||||
array('../foo/bar', '../foo/bar'),
|
||||
array('./../foo/bar', './../foo/bar'),
|
||||
array('././../foo/bar', './../foo/bar'),
|
||||
array('one/two/three', 'one/two/three'),
|
||||
array('one/two/../three', 'one/three'),
|
||||
array('one/../two/three', 'two/three'),
|
||||
array('one/two/..', 'one'),
|
||||
array('one/two/../', 'one/'),
|
||||
array('one/two/../three/../four', 'one/four'),
|
||||
array('one/two/three/../../four', 'one/four'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider clean_path_data
|
||||
*/
|
||||
public function test_clean_path($input, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->filesystem->clean_path($input));
|
||||
}
|
||||
}
|
68
tests/filesystem/is_absolute_test.php
Normal file
68
tests/filesystem/is_absolute_test.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_filesystem_is_absolute_test extends phpbb_test_case
|
||||
{
|
||||
/** @var \phpbb\filesystem\filesystem_interface */
|
||||
protected $filesystem;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||
}
|
||||
|
||||
static public function is_absolute_data()
|
||||
{
|
||||
return array(
|
||||
// Empty
|
||||
array('', false),
|
||||
|
||||
// Absolute unix style
|
||||
array('/etc/phpbb', true),
|
||||
// Unix does not support \ so that is not an absolute path
|
||||
array('\etc\phpbb', false),
|
||||
|
||||
// Absolute windows style
|
||||
array('c:\windows', true),
|
||||
array('C:\Windows', true),
|
||||
array('c:/windows', true),
|
||||
array('C:/Windows', true),
|
||||
|
||||
// Executable
|
||||
array('etc/phpbb', false),
|
||||
array('explorer.exe', false),
|
||||
|
||||
// Relative subdir
|
||||
array('Windows\System32', false),
|
||||
array('Windows\System32\explorer.exe', false),
|
||||
array('Windows/System32', false),
|
||||
array('Windows/System32/explorer.exe', false),
|
||||
|
||||
// Relative updir
|
||||
array('..\Windows\System32', false),
|
||||
array('..\Windows\System32\explorer.exe', false),
|
||||
array('../Windows/System32', false),
|
||||
array('../Windows/System32/explorer.exe', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider is_absolute_data
|
||||
*/
|
||||
public function test_is_absolute($path, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->filesystem->is_absolute_path($path));
|
||||
}
|
||||
}
|
90
tests/filesystem/realpath_test.php
Normal file
90
tests/filesystem/realpath_test.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_filesystem_realpath_test extends phpbb_test_case
|
||||
{
|
||||
static protected $filesystem_own_realpath;
|
||||
|
||||
/** @var \phpbb\filesystem\filesystem_interface */
|
||||
protected $filesystem;
|
||||
|
||||
static public function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
$reflection_class = new ReflectionClass('\phpbb\filesystem\filesystem');
|
||||
self::$filesystem_own_realpath = $reflection_class->getMethod('phpbb_own_realpath');
|
||||
self::$filesystem_own_realpath->setAccessible(true);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||
}
|
||||
|
||||
public function realpath_resolve_absolute_without_symlinks_data()
|
||||
{
|
||||
return array(
|
||||
// Constant data
|
||||
array(__DIR__, __DIR__),
|
||||
array(__DIR__ . '/../filesystem/../filesystem', __DIR__),
|
||||
array(__DIR__ . '/././', __DIR__),
|
||||
array(__DIR__ . '/non_existent', false),
|
||||
|
||||
array(__FILE__, __FILE__),
|
||||
array(__FILE__ . '../', false),
|
||||
);
|
||||
}
|
||||
|
||||
public function realpath_resolve_relative_without_symlinks_data()
|
||||
{
|
||||
if (!function_exists('getcwd'))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$filesystem = new \phpbb\filesystem\filesystem();
|
||||
$relative_path = $filesystem->make_path_relative(__DIR__, getcwd());
|
||||
|
||||
return array(
|
||||
array($relative_path, __DIR__),
|
||||
array($relative_path . '../filesystem/../filesystem', __DIR__),
|
||||
array($relative_path . '././', __DIR__),
|
||||
|
||||
array($relative_path . 'realpath_test.php', __FILE__),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider realpath_resolve_absolute_without_symlinks_data
|
||||
*/
|
||||
public function test_realpath_absolute_without_links($path, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, self::$filesystem_own_realpath->invoke($this->filesystem, $path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider realpath_resolve_relative_without_symlinks_data
|
||||
*/
|
||||
public function test_realpath_relative_without_links($path, $expected)
|
||||
{
|
||||
if (!function_exists('getcwd'))
|
||||
{
|
||||
$this->markTestSkipped('phpbb_own_realpath() cannot be tested with relative paths: getcwd is not available.');
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, self::$filesystem_own_realpath->invoke($this->filesystem, $path));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user