From 45334eadb6363add197c54483f1205baef461710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 27 Jun 2017 12:16:39 +0200 Subject: [PATCH] [ticket/15253] Update tests PHPBB3-15253 --- tests/filesystem/helper_clean_path_test.php | 36 +++++++------- tests/filesystem/helper_is_absolute_test.php | 52 ++++++++++---------- tests/filesystem/helper_realpath_test.php | 30 +++++------ tests/storage/adapter/local_test.php | 28 +++++++---- 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/tests/filesystem/helper_clean_path_test.php b/tests/filesystem/helper_clean_path_test.php index 6b723cbc50..fd9ed605c8 100644 --- a/tests/filesystem/helper_clean_path_test.php +++ b/tests/filesystem/helper_clean_path_test.php @@ -23,25 +23,23 @@ class phpbb_filesystem_helper_clean_path_test extends phpbb_test_case 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'), - ); + yield ['foo', 'foo']; + yield ['foo/bar', 'foo/bar']; + yield ['foo/bar/', 'foo/bar/']; + yield ['foo/./bar', 'foo/bar']; + yield ['foo/./././bar', 'foo/bar']; + yield ['foo/bar/.', 'foo/bar']; + yield ['./foo/bar', './foo/bar']; + yield ['../foo/bar', '../foo/bar']; + yield ['./../foo/bar', './../foo/bar']; + yield ['././../foo/bar', './../foo/bar']; + yield ['one/two/three', 'one/two/three']; + yield ['one/two/../three', 'one/three']; + yield ['one/../two/three', 'two/three']; + yield ['one/two/..', 'one']; + yield ['one/two/../', 'one/']; + yield ['one/two/../three/../four', 'one/four']; + yield ['one/two/three/../../four', 'one/four']; } /** diff --git a/tests/filesystem/helper_is_absolute_test.php b/tests/filesystem/helper_is_absolute_test.php index 6105f48ca0..e7562bfaee 100644 --- a/tests/filesystem/helper_is_absolute_test.php +++ b/tests/filesystem/helper_is_absolute_test.php @@ -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 { @@ -23,37 +23,35 @@ class phpbb_filesystem_helper_is_absolute_test extends phpbb_test_case static public function is_absolute_data() { - return array( - // Empty - array('', false), + // Empty + yield ['', false]; - // Absolute unix style - array('/etc/phpbb', true), - // Unix does not support \ so that is not an absolute path - array('\etc\phpbb', false), + // Absolute unix style + yield ['/etc/phpbb', true]; + // Unix does not support \ so that is not an absolute path + yield ['\etc\phpbb', false]; - // Absolute windows style - array('c:\windows', true), - array('C:\Windows', true), - array('c:/windows', true), - array('C:/Windows', true), + // Absolute windows style + yield ['c:\windows', true]; + yield ['C:\Windows', true]; + yield ['c:/windows', true]; + yield ['C:/Windows', true]; - // Executable - array('etc/phpbb', false), - array('explorer.exe', false), + // Executable + yield ['etc/phpbb', false]; + yield ['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 subdir + yield ['Windows\System32', false]; + yield ['Windows\System32\explorer.exe', false]; + yield ['Windows/System32', false]; + yield ['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), - ); + // Relative updir + yield ['..\Windows\System32', false]; + yield ['..\Windows\System32\explorer.exe', false]; + yield ['../Windows/System32', false]; + yield ['../Windows/System32/explorer.exe', false]; } /** diff --git a/tests/filesystem/helper_realpath_test.php b/tests/filesystem/helper_realpath_test.php index 7dde12e82f..9f2d5513df 100644 --- a/tests/filesystem/helper_realpath_test.php +++ b/tests/filesystem/helper_realpath_test.php @@ -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 { @@ -21,7 +21,7 @@ class phpbb_filesystem_helper_realpath_test extends phpbb_test_case { 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); } @@ -32,16 +32,14 @@ class phpbb_filesystem_helper_realpath_test extends phpbb_test_case 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), + // Constant data + yield [__DIR__, __DIR__]; + yield [__DIR__ . '/../filesystem/../filesystem', __DIR__]; + yield [__DIR__ . '/././', __DIR__]; + yield [__DIR__ . '/non_existent', false]; - array(__FILE__, __FILE__), - array(__FILE__ . '../', false), - ); + yield [__FILE__, __FILE__]; + yield [__FILE__ . '../', false]; } 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()); - return array( - array($relative_path, __DIR__), - array($relative_path . '../filesystem/../filesystem', __DIR__), - array($relative_path . '././', __DIR__), + yield [$relative_path, __DIR__]; + yield [$relative_path . '../filesystem/../filesystem', __DIR__]; + yield [$relative_path . '././', __DIR__]; - array($relative_path . 'helper_realpath_test.php', __FILE__), - ); + yield [$relative_path . 'helper_realpath_test.php', __FILE__]; } /** diff --git a/tests/storage/adapter/local_test.php b/tests/storage/adapter/local_test.php index bed30aa77f..42b4c5929b 100644 --- a/tests/storage/adapter/local_test.php +++ b/tests/storage/adapter/local_test.php @@ -28,6 +28,14 @@ $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() { $this->adapter = null; @@ -48,24 +56,24 @@ unlink('file.txt'); } - public function test_exists() + /** + * @dataProvider data_test_exists + */ + public function test_exists($path, $expected) { - // Exists with files - $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')); + $this->assertSame($expected, $this->adapter->exists($path)); } - public function test_delete() + public function test_delete_file() { - // Delete with files file_put_contents('file.txt', ''); $this->assertTrue(file_exists('file.txt')); $this->adapter->delete('file.txt'); $this->assertFalse(file_exists('file.txt')); - // Delete with directories + } + + public function test_delete_folder() + { mkdir('path/to/dir', 0777, true); $this->assertTrue(file_exists('path/to/dir')); $this->adapter->delete('path');