]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactor tests to use a dataProvider method
authorJoas Schilling <nickvergessen@gmx.de>
Mon, 17 Nov 2014 15:52:45 +0000 (16:52 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Mon, 17 Nov 2014 15:52:45 +0000 (16:52 +0100)
tests/lib/files/filesystem.php

index 88e98fbb8c69dc570010f55215657e83567a03be..447c2717dbbb579c1d0c206cb82a1bd4295213de 100644 (file)
@@ -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() {