summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-11-18 10:24:46 +0100
committerLukas Reschke <lukas@owncloud.com>2014-11-18 10:24:46 +0100
commit8071657cd590f5c3b773dc9da897936ecdd5560a (patch)
treec06ab3a1d60105be64c431d36f8a087768af2299 /tests
parent944cd327b1f144a434d9ff437660ba8f99f884b2 (diff)
parentccc100113803ec82fc2eab7c62620e2b3a4c7df6 (diff)
downloadnextcloud-server-8071657cd590f5c3b773dc9da897936ecdd5560a.tar.gz
nextcloud-server-8071657cd590f5c3b773dc9da897936ecdd5560a.zip
Merge pull request #12234 from owncloud/normalizepath-absolute-tests
Add tests for normalizePath() with absolute paths on windows
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/filesystem.php163
1 files changed, 102 insertions, 61 deletions
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 88e98fbb8c6..f24d86b212d 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -75,71 +75,112 @@ 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'),
+
+ // Absolute windows paths NOT marked as absolute
+ array('/C:', 'C:\\'),
+ array('/C:/', 'C:\\', false),
+ array('/C:/tests', 'C:\\tests'),
+ array('/C:/tests', 'C:\\tests', false),
+ array('/C:/tests', 'C:\\tests\\'),
+ array('/C:/tests/', 'C:\\tests\\', false),
+
+ // normalize does not resolve '..' (by design)
+ array('/foo/..', '/foo/../'),
+ array('/foo/..', '\\foo\\..\\'),
+ );
+ }
+
+ /**
+ * @dataProvider normalizePathData
+ */
+ public function testNormalizePath($expected, $path, $stripTrailingSlash = true) {
+ $this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash));
+ }
+
+ public function normalizePathWindowsAbsolutePathData() {
+ return array(
+ array('C:/', 'C:\\'),
+ array('C:/', 'C:\\', false),
+ array('C:/tests', 'C:\\tests'),
+ array('C:/tests', 'C:\\tests', false),
+ array('C:/tests', 'C:\\tests\\'),
+ array('C:/tests/', 'C:\\tests\\', false),
+ );
+ }
+
+ /**
+ * @dataProvider normalizePathWindowsAbsolutePathData
+ */
+ public function testNormalizePathWindowsAbsolutePath($expected, $path, $stripTrailingSlash = true) {
+ if (!\OC_Util::runningOnWindows()) {
+ $this->markTestSkipped('This test is Windows only');
}
+
+ $this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash, true));
}
- 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"));
+ 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() {