summaryrefslogtreecommitdiffstats
path: root/tests/lib/HookHelper.php
blob: f1cce831477b86e9d1d0716340ad9f9c145b8016 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
 * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

namespace Test;

use OC\Files\Filesystem;

/**
 * Helper class to register hooks on
 */
class HookHelper {
	public static $hookCalls;

	public static function setUpHooks() {
		self::clear();
		\OCP\Util::connectHook(
			Filesystem::CLASSNAME,
			Filesystem::signal_create,
			'\Test\HookHelper',
			'createCallback'
		);
		\OCP\Util::connectHook(
			Filesystem::CLASSNAME,
			Filesystem::signal_update,
			'\Test\HookHelper',
			'updateCallback'
		);
		\OCP\Util::connectHook(
			Filesystem::CLASSNAME,
			Filesystem::signal_write,
			'\Test\HookHelper',
			'writeCallback'
		);

		\OCP\Util::connectHook(
			Filesystem::CLASSNAME,
			Filesystem::signal_post_create,
			'\Test\HookHelper',
			'postCreateCallback'
		);
		\OCP\Util::connectHook(
			Filesystem::CLASSNAME,
			Filesystem::signal_post_update,
			'\Test\HookHelper',
			'postUpdateCallback'
		);
		\OCP\Util::connectHook(
			Filesystem::CLASSNAME,
			Filesystem::signal_post_write,
			'\Test\HookHelper',
			'postWriteCallback'
		);
	}

	public static function clear() {
		self::$hookCalls = [];
	}

	public static function createCallback($params) {
		self::$hookCalls[] = array(
			'signal' => Filesystem::signal_create,
			'params' => $params
		);
	}

	public static function updateCallback($params) {
		self::$hookCalls[] = array(
			'signal' => Filesystem::signal_update,
			'params' => $params
		);
	}

	public static function writeCallback($params) {
		self::$hookCalls[] = array(
			'signal' => Filesystem::signal_write,
			'params' => $params
		);
	}

	public static function postCreateCallback($params) {
		self::$hookCalls[] = array(
			'signal' => Filesystem::signal_post_create,
			'params' => $params
		);
	}

	public static function postUpdateCallback($params) {
		self::$hookCalls[] = array(
			'signal' => Filesystem::signal_post_update,
			'params' => $params
		);
	}

	public static function postWriteCallback($params) {
		self::$hookCalls[] = array(
			'signal' => Filesystem::signal_post_write,
			'params' => $params
		);
	}

	/**
	 * Callback that sets the run parameter to false
	 */
	public static function cancellingCallback($params) {
		$params[Filesystem::signal_param_run] = false;
	}
}