From 39bf700790bb403948e6821499b4ada0d3314610 Mon Sep 17 00:00:00 2001
From: Joas Schilling <nickvergessen@gmx.de>
Date: Mon, 28 Apr 2014 10:49:35 +0200
Subject: [PATCH] Update tests to test for create and update aswell

---
 tests/lib/files/view.php | 48 +++++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 13 deletions(-)

diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index c85f1128db..682f3bb52a 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -393,14 +393,15 @@ class View extends \PHPUnit_Framework_TestCase {
 		$rootView->file_put_contents('/foo.txt', 'asd');
 		$this->assertNull($this->hookPath);
 
+		$this->hookWritePath = $this->hookUpdatePath = $this->hookCreatePath = null;
+
 		$subView->file_put_contents('/foo.txt', 'asd');
-		$this->assertNotNull($this->hookPath);
 		$this->assertEquals('/substorage/foo.txt', $this->hookPath);
 	}
 
 	private $hookPath;
 
-	function dummyHook($params) {
+	public function dummyHook($params) {
 		$this->hookPath = $params['path'];
 	}
 
@@ -442,12 +443,6 @@ class View extends \PHPUnit_Framework_TestCase {
 		return $storage;
 	}
 
-	private $createHookPath;
-
-	function dummyCreateHook($params) {
-		$this->createHookPath = $params['path'];
-	}
-
 	/**
 	 * @medium
 	 */
@@ -466,23 +461,50 @@ class View extends \PHPUnit_Framework_TestCase {
 		$this->assertNull($this->hookPath);
 	}
 
+	private $hookWritePath;
+	private $hookCreatePath;
+	private $hookUpdatePath;
+
+	public function dummyHookWrite($params) {
+		$this->hookWritePath = $params['path'];
+	}
+
+	public function dummyHookUpdate($params) {
+		$this->hookUpdatePath = $params['path'];
+	}
+
+	public function dummyHookCreate($params) {
+		$this->hookCreatePath = $params['path'];
+	}
+
 	public function testEditNoCreateHook() {
 		$storage1 = $this->getTestStorage();
 		$storage2 = $this->getTestStorage();
 		$defaultRoot = \OC\Files\Filesystem::getRoot();
 		\OC\Files\Filesystem::mount($storage1, array(), '/');
 		\OC\Files\Filesystem::mount($storage2, array(), $defaultRoot);
-		\OC_Hook::connect('OC_Filesystem', 'post_create', $this, 'dummyCreateHook');
+		\OC_Hook::connect('OC_Filesystem', 'post_create', $this, 'dummyHookCreate');
+		\OC_Hook::connect('OC_Filesystem', 'post_update', $this, 'dummyHookUpdate');
+		\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHookWrite');
 
 		$view = new \OC\Files\View($defaultRoot);
-		$this->hookPath = null;
+		$this->hookWritePath = $this->hookUpdatePath = $this->hookCreatePath = null;
 
 		$view->file_put_contents('/asd.txt', 'foo');
-		$this->assertEquals('/asd.txt', $this->createHookPath);
-		$this->createHookPath = null;
+		$this->assertEquals('/asd.txt', $this->hookCreatePath);
+		$this->assertNull($this->hookUpdatePath);
+		$this->assertEquals('/asd.txt', $this->hookWritePath);
+
+		$this->hookWritePath = $this->hookUpdatePath = $this->hookCreatePath = null;
 
 		$view->file_put_contents('/asd.txt', 'foo');
-		$this->assertNull($this->createHookPath);
+		$this->assertNull($this->hookCreatePath);
+		$this->assertEquals('/asd.txt', $this->hookUpdatePath);
+		$this->assertEquals('/asd.txt', $this->hookWritePath);
+
+		\OC_Hook::clear('OC_Filesystem', 'post_create');
+		\OC_Hook::clear('OC_Filesystem', 'post_update');
+		\OC_Hook::clear('OC_Filesystem', 'post_write');
 	}
 
 	/**
-- 
GitLab