diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-11-17 16:52:45 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-11-17 16:52:45 +0100 |
commit | 806284f06c9689449fc6b118bc9478843a9472ec (patch) | |
tree | 719bb096ba40137ba2c12108b5d87a835e7e9d63 /tests/lib/files | |
parent | 6625d5c88f74edade459ec7e2ee0bfb79f21fedd (diff) | |
download | nextcloud-server-806284f06c9689449fc6b118bc9478843a9472ec.tar.gz nextcloud-server-806284f06c9689449fc6b118bc9478843a9472ec.zip |
Refactor tests to use a dataProvider method
Diffstat (limited to 'tests/lib/files')
-rw-r--r-- | tests/lib/files/filesystem.php | 135 |
1 files changed, 73 insertions, 62 deletions
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index 88e98fbb8c6..447c2717dbb 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -75,71 +75,82 @@ class Filesystem extends \Test\TestCase { $this->assertEquals('folder', $internalPath); } - public function testNormalize() { - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('')); - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('/')); - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('/', false)); - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('//')); - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('//', false)); - $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('/path/')); - $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('/path/', false)); - $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('path')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/')); - $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo//bar/', false)); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/////bar')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/.')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/./')); - $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/bar/./', false)); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/./.')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/././')); - $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/bar/././', false)); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/./bar/')); - $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/./bar/', false)); - $this->assertEquals('/foo/.bar', \OC\Files\Filesystem::normalizePath('/foo/.bar/')); - $this->assertEquals('/foo/.bar/', \OC\Files\Filesystem::normalizePath('/foo/.bar/', false)); - $this->assertEquals('/foo/.bar/tee', \OC\Files\Filesystem::normalizePath('/foo/.bar/tee')); - - // normalize does not resolve '..' (by design) - $this->assertEquals('/foo/..', \OC\Files\Filesystem::normalizePath('/foo/../')); - - if (class_exists('Patchwork\PHP\Shim\Normalizer')) { - $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88")); - } + public function normalizePathData() { + return array( + array('/', ''), + array('/', '/'), + array('/', '//'), + array('/', '/', false), + array('/', '//', false), + + array('/path', '/path/'), + array('/path/', '/path/', false), + array('/path', 'path'), + + array('/foo/bar', '/foo//bar/'), + array('/foo/bar/', '/foo//bar/', false), + 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/./', false), + array('/foo/bar', '/foo/bar/./.'), + array('/foo/bar', '/foo/bar/././'), + array('/foo/bar/', '/foo/bar/././', false), + array('/foo/bar', '/foo/./bar/'), + array('/foo/bar/', '/foo/./bar/', false), + array('/foo/.bar', '/foo/.bar/'), + array('/foo/.bar/', '/foo/.bar/', false), + array('/foo/.bar/tee', '/foo/.bar/tee'), + + // Windows paths + array('/', ''), + array('/', '\\'), + array('/', '\\', false), + array('/', '\\\\'), + array('/', '\\\\', false), + + array('/path', '\\path'), + array('/path', '\\path', false), + array('/path', '\\path\\'), + array('/path/', '\\path\\', false), + + array('/foo/bar', '\\foo\\\\bar\\'), + array('/foo/bar/', '\\foo\\\\bar\\', false), + 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\\.\\', false), + array('/foo/bar', '\\foo\\bar\\.\\.'), + array('/foo/bar', '\\foo\\bar\\.\\.\\'), + array('/foo/bar/', '\\foo\\bar\\.\\.\\', false), + array('/foo/bar', '\\foo\\.\\bar\\'), + array('/foo/bar/', '\\foo\\.\\bar\\', false), + array('/foo/.bar', '\\foo\\.bar\\'), + array('/foo/.bar/', '\\foo\\.bar\\', false), + array('/foo/.bar/tee', '\\foo\\.bar\\tee'), + + // normalize does not resolve '..' (by design) + array('/foo/..', '/foo/../'), + array('/foo/..', '\\foo\\..\\'), + ); } - public function testNormalizeWindowsPaths() { - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('')); - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\')); - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\', false)); - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\\\')); - $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\\\', false)); - $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path')); - $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path', false)); - $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path\\')); - $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('\\path\\', false)); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\bar\\')); - $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\\\bar\\', false)); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\\\\\bar')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\\\\\\\bar')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\')); - $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\', false)); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.')); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.\\')); - $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.\\', false)); - $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\.\\bar\\')); - $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\.\\bar\\', false)); - $this->assertEquals('/foo/.bar', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\')); - $this->assertEquals('/foo/.bar/', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\', false)); - $this->assertEquals('/foo/.bar/tee', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\tee')); - - // normalize does not resolve '..' (by design) - $this->assertEquals('/foo/..', \OC\Files\Filesystem::normalizePath('\\foo\\..\\')); - - if (class_exists('Patchwork\PHP\Shim\Normalizer')) { - $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("\\foo\\baru\xCC\x88")); + /** + * @dataProvider normalizePathData + */ + public function testNormalizePath($expected, $path, $stripTrailingSlash = true, $isAbsolutePath = false) { + $this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash, $isAbsolutePath)); + } + + public function testNormalizePathUTF8() { + if (!class_exists('Patchwork\PHP\Shim\Normalizer')) { + $this->markTestSkipped('UTF8 normalizer Patchwork was not found'); } + + $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88")); + $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("\\foo\\baru\xCC\x88")); } public function testHooks() { |