aboutsummaryrefslogtreecommitdiff
path: root/js/tests/ElggLibTest.js
diff options
context:
space:
mode:
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-14 11:33:29 +0000
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-14 11:33:29 +0000
commitc9f5c056862553d5102d1dfb7d964ea449573d59 (patch)
tree1b005cf7858d8358d76ed3ed8966170a6d4bab99 /js/tests/ElggLibTest.js
parent72a4b251503eeb2ae4cc8efdea1f522817652406 (diff)
downloadelgg-c9f5c056862553d5102d1dfb7d964ea449573d59.tar.gz
elgg-c9f5c056862553d5102d1dfb7d964ea449573d59.tar.bz2
Refs #2538: Added vsprintf support to elgg.echo. Added unit tests for normalize_url, added prototype definitions for Array#forEach for compatibility with IE.
git-svn-id: http://code.elgg.org/elgg/trunk@7313 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'js/tests/ElggLibTest.js')
-rw-r--r--js/tests/ElggLibTest.js78
1 files changed, 35 insertions, 43 deletions
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