aboutsummaryrefslogtreecommitdiff
path: root/js/tests/ElggHooksTest.js
blob: e7a2440e7285cc8c38d70508b6f71389380fc54a (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
ElggHooksTest = TestCase("ElggHooksTest");

ElggHooksTest.prototype.setUp = function() {
	elgg.config.hooks = {};
	elgg.provide('elgg.config.hooks.all.all');
};

ElggHooksTest.prototype.testHookHandlersMustBeFunctions = function () {
	assertException(function() { elgg.register_hook_handler('str', 'str', 'oops'); });
};

ElggHooksTest.prototype.testReturnValueDefaultsToTrue = function () {
	assertTrue(elgg.trigger_hook('fee', 'fum'));

	elgg.register_hook_handler('fee', 'fum', elgg.nullFunction);
	assertTrue(elgg.trigger_hook('fee', 'fum'));
};

ElggHooksTest.prototype.testCanGlomHooksWithAll = function () {
	elgg.register_hook_handler('all', 'bar', elgg.abstractMethod);
	assertException("all,bar", function() { elgg.trigger_hook('foo', 'bar'); });

	elgg.register_hook_handler('foo', 'all', elgg.abstractMethod);
	assertException("foo,all", function() { elgg.trigger_hook('foo', 'baz'); });

	elgg.register_hook_handler('all', 'all', elgg.abstractMethod);
	assertException("all,all", function() { elgg.trigger_hook('pinky', 'winky'); });
};