aboutsummaryrefslogtreecommitdiff
path: root/js/tests/ElggLibTest.js
diff options
context:
space:
mode:
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-02 16:06:53 +0000
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-02 16:06:53 +0000
commit441c9e85dcb824dba2a44657a31fa29ad71a4ee1 (patch)
treee3558477d639a95bb5a24807d2a8174c73e1ac83 /js/tests/ElggLibTest.js
parent99b267a9fc4b023e54a9d2c8ec9bd9fe42a32e54 (diff)
downloadelgg-441c9e85dcb824dba2a44657a31fa29ad71a4ee1.tar.gz
elgg-441c9e85dcb824dba2a44657a31fa29ad71a4ee1.tar.bz2
Refs #2538: Moved js directory to elgg root.
git-svn-id: http://code.elgg.org/elgg/trunk@7189 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'js/tests/ElggLibTest.js')
-rw-r--r--js/tests/ElggLibTest.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/js/tests/ElggLibTest.js b/js/tests/ElggLibTest.js
new file mode 100644
index 000000000..035b60325
--- /dev/null
+++ b/js/tests/ElggLibTest.js
@@ -0,0 +1,88 @@
+/**
+ * Test basic elgg library functions
+ */
+ElggLibTest = TestCase("ElggLibTest");
+
+ElggLibTest.prototype.testGlobal = function() {
+ assertTrue(window === elgg.global);
+};
+
+ElggLibTest.prototype.testAssertTypeOf = function() {
+ var noexceptions = [
+ ['string', ''],
+ ['object', {}],
+ ['boolean', true],
+ ['boolean', false],
+ ['undefined', undefined],
+ ['number', 0],
+ ['function', function() {}],
+ ];
+
+ for (var i in noexceptions) {
+ assertNoException(function() {
+ elgg.assertTypeOf.apply(elgg, noexceptions[i]);
+ });
+ }
+
+ var exceptions = [
+ ['function', {}],
+ ['object', function() {}],
+ ];
+
+ for (var i in exceptions) {
+ assertException(function() {
+ elgg.assertTypeOf.apply(elgg, exceptions[i]);
+ });
+ }
+};
+
+ElggLibTest.prototype.testProvide = 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";
+
+ elgg.provide('foo.bar.baz');
+
+ assertEquals(str, foo.bar.baz.oof);
+};
+
+ElggLibTest.prototype.testRequire = function() {
+ /* Try requiring bogus input */
+ assertException(function(){ elgg.require(''); });
+ assertException(function(){ elgg.require('garbage'); });
+ assertException(function(){ elgg.require('gar.ba.ge'); });
+
+ assertNoException(function(){ elgg.require('jQuery'); });
+ assertNoException(function(){ elgg.require('elgg'); });
+ assertNoException(function(){ elgg.require('elgg.config'); });
+ assertNoException(function(){ elgg.require('elgg.security'); });
+};
+
+ElggLibTest.prototype.testInherit = function() {
+ function Base() {}
+ function Child() {}
+
+ elgg.inherit(Child, Base);
+
+ assertInstanceOf(Base, new Child());
+ assertEquals(Child, Child.prototype.constructor);
+};
+
+ElggLibTest.prototype.testExtendUrl = function() {
+ elgg.config.wwwroot = "http://elgg.org/";
+
+ var inputs = [
+ [elgg.config.wwwroot, ''],
+ [elgg.config.wwwroot + 'pg/test', '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]));
+ }
+}; \ No newline at end of file