[ticket/15253] Update tests

PHPBB3-15253
This commit is contained in:
Rubén Calvo 2017-06-27 12:16:39 +02:00
parent b1755d9dac
commit 45334eadb6
4 changed files with 73 additions and 73 deletions

View file

@ -23,25 +23,23 @@ class phpbb_filesystem_helper_clean_path_test extends phpbb_test_case
public function clean_path_data() public function clean_path_data()
{ {
return array( yield ['foo', 'foo'];
array('foo', 'foo'), yield ['foo/bar', 'foo/bar'];
array('foo/bar', 'foo/bar'), yield ['foo/bar/', 'foo/bar/'];
array('foo/bar/', 'foo/bar/'), yield ['foo/./bar', 'foo/bar'];
array('foo/./bar', 'foo/bar'), yield ['foo/./././bar', 'foo/bar'];
array('foo/./././bar', 'foo/bar'), yield ['foo/bar/.', 'foo/bar'];
array('foo/bar/.', 'foo/bar'), yield ['./foo/bar', './foo/bar'];
array('./foo/bar', './foo/bar'), yield ['../foo/bar', '../foo/bar'];
array('../foo/bar', '../foo/bar'), yield ['./../foo/bar', './../foo/bar'];
array('./../foo/bar', './../foo/bar'), yield ['././../foo/bar', './../foo/bar'];
array('././../foo/bar', './../foo/bar'), yield ['one/two/three', 'one/two/three'];
array('one/two/three', 'one/two/three'), yield ['one/two/../three', 'one/three'];
array('one/two/../three', 'one/three'), yield ['one/../two/three', 'two/three'];
array('one/../two/three', 'two/three'), yield ['one/two/..', 'one'];
array('one/two/..', 'one'), yield ['one/two/../', 'one/'];
array('one/two/../', 'one/'), yield ['one/two/../three/../four', 'one/four'];
array('one/two/../three/../four', 'one/four'), yield ['one/two/three/../../four', 'one/four'];
array('one/two/three/../../four', 'one/four'),
);
} }
/** /**

View file

@ -11,7 +11,7 @@
* *
*/ */
use phpbb\filesystem\helper as filesystem_helper; use phpbb\filesystem\helper as filesystem_helper;
class phpbb_filesystem_helper_is_absolute_test extends phpbb_test_case class phpbb_filesystem_helper_is_absolute_test extends phpbb_test_case
{ {
@ -23,37 +23,35 @@ class phpbb_filesystem_helper_is_absolute_test extends phpbb_test_case
static public function is_absolute_data() static public function is_absolute_data()
{ {
return array( // Empty
// Empty yield ['', false];
array('', false),
// Absolute unix style // Absolute unix style
array('/etc/phpbb', true), yield ['/etc/phpbb', true];
// Unix does not support \ so that is not an absolute path // Unix does not support \ so that is not an absolute path
array('\etc\phpbb', false), yield ['\etc\phpbb', false];
// Absolute windows style // Absolute windows style
array('c:\windows', true), yield ['c:\windows', true];
array('C:\Windows', true), yield ['C:\Windows', true];
array('c:/windows', true), yield ['c:/windows', true];
array('C:/Windows', true), yield ['C:/Windows', true];
// Executable // Executable
array('etc/phpbb', false), yield ['etc/phpbb', false];
array('explorer.exe', false), yield ['explorer.exe', false];
// Relative subdir // Relative subdir
array('Windows\System32', false), yield ['Windows\System32', false];
array('Windows\System32\explorer.exe', false), yield ['Windows\System32\explorer.exe', false];
array('Windows/System32', false), yield ['Windows/System32', false];
array('Windows/System32/explorer.exe', false), yield ['Windows/System32/explorer.exe', false];
// Relative updir // Relative updir
array('..\Windows\System32', false), yield ['..\Windows\System32', false];
array('..\Windows\System32\explorer.exe', false), yield ['..\Windows\System32\explorer.exe', false];
array('../Windows/System32', false), yield ['../Windows/System32', false];
array('../Windows/System32/explorer.exe', false), yield ['../Windows/System32/explorer.exe', false];
);
} }
/** /**

View file

@ -11,7 +11,7 @@
* *
*/ */
use phpbb\filesystem\helper as filesystem_helper; use phpbb\filesystem\helper as filesystem_helper;
class phpbb_filesystem_helper_realpath_test extends phpbb_test_case class phpbb_filesystem_helper_realpath_test extends phpbb_test_case
{ {
@ -21,7 +21,7 @@ class phpbb_filesystem_helper_realpath_test extends phpbb_test_case
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
self::$filesystem_helper_phpbb_own_realpath = new ReflectionMethod('filesystem_helper', 'phpbb_own_realpath'); self::$filesystem_helper_phpbb_own_realpath = new ReflectionMethod('\phpbb\filesystem\helper', 'phpbb_own_realpath');
self::$filesystem_helper_phpbb_own_realpath->setAccessible(true); self::$filesystem_helper_phpbb_own_realpath->setAccessible(true);
} }
@ -32,16 +32,14 @@ class phpbb_filesystem_helper_realpath_test extends phpbb_test_case
public function realpath_resolve_absolute_without_symlinks_data() public function realpath_resolve_absolute_without_symlinks_data()
{ {
return array( // Constant data
// Constant data yield [__DIR__, __DIR__];
array(__DIR__, __DIR__), yield [__DIR__ . '/../filesystem/../filesystem', __DIR__];
array(__DIR__ . '/../filesystem/../filesystem', __DIR__), yield [__DIR__ . '/././', __DIR__];
array(__DIR__ . '/././', __DIR__), yield [__DIR__ . '/non_existent', false];
array(__DIR__ . '/non_existent', false),
array(__FILE__, __FILE__), yield [__FILE__, __FILE__];
array(__FILE__ . '../', false), yield [__FILE__ . '../', false];
);
} }
public function realpath_resolve_relative_without_symlinks_data() public function realpath_resolve_relative_without_symlinks_data()
@ -53,13 +51,11 @@ class phpbb_filesystem_helper_realpath_test extends phpbb_test_case
$relative_path = filesystem_helper::make_path_relative(__DIR__, getcwd()); $relative_path = filesystem_helper::make_path_relative(__DIR__, getcwd());
return array( yield [$relative_path, __DIR__];
array($relative_path, __DIR__), yield [$relative_path . '../filesystem/../filesystem', __DIR__];
array($relative_path . '../filesystem/../filesystem', __DIR__), yield [$relative_path . '././', __DIR__];
array($relative_path . '././', __DIR__),
array($relative_path . 'helper_realpath_test.php', __FILE__), yield [$relative_path . 'helper_realpath_test.php', __FILE__];
);
} }
/** /**

View file

@ -28,6 +28,14 @@
$this->adapter = new \phpbb\storage\adapter\local($config, $filesystem, $phpbb_root_path, $path_key); $this->adapter = new \phpbb\storage\adapter\local($config, $filesystem, $phpbb_root_path, $path_key);
} }
public function data_test_exists()
{
yield ['README.md', true];
yield ['nonexistent_file.php', false];
yield ['phpBB/phpbb', true];
yield ['nonexistent/folder', false];
}
public function tearDown() public function tearDown()
{ {
$this->adapter = null; $this->adapter = null;
@ -48,24 +56,24 @@
unlink('file.txt'); unlink('file.txt');
} }
public function test_exists() /**
* @dataProvider data_test_exists
*/
public function test_exists($path, $expected)
{ {
// Exists with files $this->assertSame($expected, $this->adapter->exists($path));
$this->assertTrue($this->adapter->exists('README.md'));
$this->assertFalse($this->adapter->exists('nonexistent_file.php'));
// exists with directory
$this->assertTrue($this->adapter->exists('phpBB'));
$this->assertFalse($this->adapter->exists('nonexistet_folder'));
} }
public function test_delete() public function test_delete_file()
{ {
// Delete with files
file_put_contents('file.txt', ''); file_put_contents('file.txt', '');
$this->assertTrue(file_exists('file.txt')); $this->assertTrue(file_exists('file.txt'));
$this->adapter->delete('file.txt'); $this->adapter->delete('file.txt');
$this->assertFalse(file_exists('file.txt')); $this->assertFalse(file_exists('file.txt'));
// Delete with directories }
public function test_delete_folder()
{
mkdir('path/to/dir', 0777, true); mkdir('path/to/dir', 0777, true);
$this->assertTrue(file_exists('path/to/dir')); $this->assertTrue(file_exists('path/to/dir'));
$this->adapter->delete('path'); $this->adapter->delete('path');