diff options
Diffstat (limited to 'js/tests')
-rw-r--r-- | js/tests/ElggEventsTest.js | 8 | ||||
-rw-r--r-- | js/tests/ElggLibTest.js | 78 | ||||
-rw-r--r-- | js/tests/jsTestDriver.conf | 1 |
3 files changed, 40 insertions, 47 deletions
diff --git a/js/tests/ElggEventsTest.js b/js/tests/ElggEventsTest.js index 1fc9c8e86..4765878cf 100644 --- a/js/tests/ElggEventsTest.js +++ b/js/tests/ElggEventsTest.js @@ -11,7 +11,7 @@ ElggEventsTest.prototype.testEventHandlersMustBeFunctions = function () { ElggEventsTest.prototype.testReturnValueDefaultsToTrue = function () { assertTrue(elgg.trigger_event('fee', 'fum')); - + elgg.register_event_handler('fee', 'fum', elgg.nullFunction); assertTrue(elgg.trigger_event('fee', 'fum')); }; @@ -19,10 +19,10 @@ ElggEventsTest.prototype.testReturnValueDefaultsToTrue = function () { ElggEventsTest.prototype.testCanGlomEventsWithAll = function () { elgg.register_event_handler('all', 'bar', elgg.abstractMethod); assertException("all,bar", function() { elgg.trigger_event('foo', 'bar'); }); - + elgg.register_event_handler('foo', 'all', elgg.abstractMethod); assertException("foo,all", function() { elgg.trigger_event('foo', 'baz'); }); - - elgg.register_event_handler('all', 'all', elgg.abstractMethod); + + elgg.register_event_handler('all', 'all', elgg.abstractMethod); assertException("all,all", function() { elgg.trigger_event('pinky', 'winky'); }); };
\ No newline at end of file diff --git a/js/tests/ElggLibTest.js b/js/tests/ElggLibTest.js index e810a47fb..132ad986a 100644 --- a/js/tests/ElggLibTest.js +++ b/js/tests/ElggLibTest.js @@ -8,50 +8,42 @@ ElggLibTest.prototype.testGlobal = function() { };
ElggLibTest.prototype.testAssertTypeOf = function() {
- var noexceptions = [
+ [//Valid inputs
['string', ''],
['object', {}],
- ['boolean', true],
- ['boolean', false],
- ['undefined', undefined],
- ['number', 0],
- ['function', elgg.nullFunction],
- ];
-
- for (var i in noexceptions) {
- assertNoException(function() {
- elgg.assertTypeOf.apply(elgg, noexceptions[i]);
+ ['boolean', true],
+ ['boolean', false],
+ ['undefined', undefined],
+ ['number', 0],
+ ['function', elgg.nullFunction]
+ ].forEach(function(args) {
+ assertNoException(function() {
+ elgg.assertTypeOf.apply(undefined, args);
});
- }
-
- var exceptions = [
+ });
+
+ [//Invalid inputs
['function', {}],
- ['object', elgg.nullFunction],
- ];
-
- for (var i in exceptions) {
- assertException(function() {
- elgg.assertTypeOf.apply(elgg, exceptions[i]);
+ ['object', elgg.nullFunction]
+ ].forEach(function() {
+ assertException(function(args) {
+ elgg.assertTypeOf.apply(undefined, args);
});
- }
+ });
};
-ElggLibTest.prototype.testProvide = function() {
+ElggLibTest.prototype.testProvideDoesntClobber = function() {
elgg.provide('foo.bar.baz');
-
- assertNotUndefined(foo);
- assertNotUndefined(foo.bar);
- assertNotUndefined(foo.bar.baz);
-
- var str = foo.bar.baz.oof = "don't overwrite me";
-
+
+ foo.bar.baz.oof = "test";
+
elgg.provide('foo.bar.baz');
-
- assertEquals(str, foo.bar.baz.oof);
+
+ assertEquals("test", foo.bar.baz.oof);
};
/**
- * Try requiring bogus input
+ * Try requiring bogus input
*/
ElggLibTest.prototype.testRequire = function () {
assertException(function(){ elgg.require(''); });
@@ -69,24 +61,24 @@ ElggLibTest.prototype.testRequire = function () { ElggLibTest.prototype.testInherit = function () {
function Base() {}
function Child() {}
-
+
elgg.inherit(Child, Base);
-
+
assertInstanceOf(Base, new Child());
assertEquals(Child, Child.prototype.constructor);
};
ElggLibTest.prototype.testNormalizeUrl = function() {
elgg.config.wwwroot = "http://elgg.org/";
-
- var inputs = [
- [elgg.config.wwwroot, ''],
- [elgg.config.wwwroot + 'pg/test', 'pg/test'],
+
+ [
+ ['', elgg.config.wwwroot],
+ ['pg/test', elgg.config.wwwroot + 'pg/test'],
['http://google.com', 'http://google.com'],
['//example.com', '//example.com'],
- ];
-
- for (var i in inputs) {
- assertEquals(inputs[i][0], elgg.normalize_url(inputs[i][1]));
- }
+ ['/pg/page', elgg.config.wwwroot + 'pg/page'],
+ ['mod/plugin/index.php', elgg.config.wwwroot + 'mod/plugin/index.php'],
+ ].forEach(function(args) {
+ assertEquals(args[1], elgg.normalize_url(args[0]));
+ });
};
\ No newline at end of file diff --git a/js/tests/jsTestDriver.conf b/js/tests/jsTestDriver.conf index 2f732da7b..606487c03 100644 --- a/js/tests/jsTestDriver.conf +++ b/js/tests/jsTestDriver.conf @@ -2,6 +2,7 @@ server: http://localhost:42442 load:
- vendors/jquery/jquery-1.4.2.min.js
+ - vendors/sprintf.js
- js/lib/elgglib.js
- js/classes/*.js
- js/lib/*.js
|