From f77dc9b30fd1720ed3cc84c52fe0ba1b1c186e8c Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Mon, 1 Oct 2012 14:00:14 +0200
Subject: [PATCH] add test to make sure filepaths that are passed to
 filesystems hooks are normalized

---
 tests/lib/filesystem.php | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php
index bc3b4d06aa..050dfa5280 100644
--- a/tests/lib/filesystem.php
+++ b/tests/lib/filesystem.php
@@ -71,4 +71,27 @@ class Test_Filesystem extends UnitTestCase {
 			$this->assertEqual("/foo/bar\xC3\xBC", OC_Filesystem::normalizePath("/foo/baru\xCC\x88"));
 		}
 	}
+
+	public function testHooks() {
+		$user = OC_User::getUser();
+		OC_Hook::clear('OC_Filesystem');
+		OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
+
+		OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
+
+		OC_Filesystem::init('');
+		OC_Filesystem::file_put_contents('/foo', 'foo');
+		OC_Filesystem::mkdir('/bar');
+		OC_Filesystem::file_put_contents('/bar//foo', 'foo');
+
+		$tmpFile = OC_Helper::tmpFile();
+		file_put_contents($tmpFile, 'foo');
+		$fh = fopen($tmpFile, 'r');
+		OC_Filesystem::file_put_contents('/bar//foo', $fh);
+	}
+
+	public function dummyHook($arguments) {
+		$path = $arguments['path'];
+		$this->assertEqual($path, OC_Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
+	}
 }
-- 
GitLab