diff options
Diffstat (limited to 'engine/js/tests')
-rw-r--r-- | engine/js/tests/ElggAjaxOptionsTest.js | 60 | ||||
-rw-r--r-- | engine/js/tests/ElggAjaxTest.js | 59 | ||||
-rw-r--r-- | engine/js/tests/ElggLibTest.js | 49 | ||||
-rw-r--r-- | engine/js/tests/ElggSecurityTest.js | 51 | ||||
-rw-r--r-- | engine/js/tests/ElggSessionTest.js | 36 |
5 files changed, 255 insertions, 0 deletions
diff --git a/engine/js/tests/ElggAjaxOptionsTest.js b/engine/js/tests/ElggAjaxOptionsTest.js new file mode 100644 index 000000000..1f6f251de --- /dev/null +++ b/engine/js/tests/ElggAjaxOptionsTest.js @@ -0,0 +1,60 @@ +ElggAjaxOptionsTest = TestCase("ElggAjaxOptionsTest");
+
+ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsNoArgs = function() {
+ assertNotUndefined(elgg.ajax.handleOptions());
+
+};
+
+ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsUrl = function() {
+ var url = 'url',
+ result = elgg.ajax.handleOptions(url);
+
+ assertEquals(url, result.url);
+};
+
+ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsDataOnly = function() {
+ var options = {},
+ result = elgg.ajax.handleOptions(options);
+
+ assertEquals(options, result.data);
+};
+
+ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsOptions = function() {
+ var options = {data:{arg:1}},
+ result = elgg.ajax.handleOptions(options);
+
+ assertEquals(options, result);
+
+ function func() {}
+ options = {success: func};
+ result = elgg.ajax.handleOptions(options);
+
+ assertEquals(options, result);
+};
+
+ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsUrlThenDataOnly = function() {
+ var url = 'url',
+ options = {arg:1},
+ result = elgg.ajax.handleOptions(url, options);
+
+ assertEquals(url, result.url);
+ assertEquals(options, result.data);
+};
+
+ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsUrlThenSuccessOnly = function() {
+ var url = 'url',
+ success = function() {},
+ result = elgg.ajax.handleOptions(url, success);
+
+ assertEquals(url, result.url);
+ assertEquals(success, result.success);
+};
+
+ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsUrlThenOptions = function() {
+ var url = 'url',
+ options = {data:{arg:1}},
+ result = elgg.ajax.handleOptions(url, options);
+
+ assertEquals(url, result.url);
+ assertEquals(options.data, result.data);
+};
\ No newline at end of file diff --git a/engine/js/tests/ElggAjaxTest.js b/engine/js/tests/ElggAjaxTest.js new file mode 100644 index 000000000..1fa5daca5 --- /dev/null +++ b/engine/js/tests/ElggAjaxTest.js @@ -0,0 +1,59 @@ +/**
+ * Makes sure that each of the helper ajax functions ends up calling $.ajax
+ * with the right options.
+ */
+ElggAjaxTest = TestCase("ElggAjaxTest");
+
+ElggAjaxTest.prototype.setUp = function() {
+
+ this.wwwroot = elgg.config.wwwroot;
+ this.ajax = $.ajax;
+
+ elgg.config.wwwroot = 'http://www.elgg.org/';
+
+ $.ajax = function(options) {
+ return options;
+ };
+};
+
+ElggAjaxTest.prototype.tearDown = function() {
+ $.ajax = this.ajax;
+ elgg.config.wwwroot = this.wwwroot;
+};
+
+ElggAjaxTest.prototype.testElggAjax = function() {
+ assertEquals(elgg.config.wwwroot, elgg.ajax().url);
+};
+
+ElggAjaxTest.prototype.testElggGet = function() {
+ assertEquals('get', elgg.get().type);
+};
+
+ElggAjaxTest.prototype.testElggGetJSON = function() {
+ assertEquals('json', elgg.getJSON().dataType);
+};
+
+ElggAjaxTest.prototype.testElggPost = function() {
+ assertEquals('post', elgg.post().type);
+};
+
+ElggAjaxTest.prototype.testElggAction = function() {
+ assertException(function() { elgg.action(); });
+ assertException(function() { elgg.action({}); });
+
+ var result = elgg.action('action');
+ assertEquals('post', result.type);
+ assertEquals('json', result.dataType);
+ assertEquals(elgg.config.wwwroot + 'action/action', result.url);
+ assertEquals(elgg.security.token.__elgg_ts, result.data.__elgg_ts);
+};
+
+ElggAjaxTest.prototype.testElggAPI = function() {
+ assertException(function() { elgg.api(); });
+ assertException(function() { elgg.api({}); });
+
+ var result = elgg.api('method');
+ assertEquals('json', result.dataType);
+ assertEquals('method', result.data.method);
+ assertEquals(elgg.config.wwwroot + 'services/api/rest/json/', result.url);
+};
diff --git a/engine/js/tests/ElggLibTest.js b/engine/js/tests/ElggLibTest.js new file mode 100644 index 000000000..1cd1b139c --- /dev/null +++ b/engine/js/tests/ElggLibTest.js @@ -0,0 +1,49 @@ +ElggLibTest = TestCase("ElggLibTest");
+
+ElggLibTest.prototype.testGlobal = function() {
+ assertTrue(window === elgg.global);
+};
+
+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.testExtendUrl = function() {
+ var url;
+ elgg.config.wwwroot = "http://www.elgg.org/";
+
+ url = '';
+ assertEquals(elgg.config.wwwroot, elgg.extendUrl(url));
+
+ url = 'pg/test';
+ assertEquals('http://www.elgg.org/pg/test', elgg.extendUrl(url));
+};
+
+
+
+
+
+
+
diff --git a/engine/js/tests/ElggSecurityTest.js b/engine/js/tests/ElggSecurityTest.js new file mode 100644 index 000000000..2b497b869 --- /dev/null +++ b/engine/js/tests/ElggSecurityTest.js @@ -0,0 +1,51 @@ +ElggSecurityTest = TestCase("ElggSecurityTest");
+
+ElggSecurityTest.prototype.setUp = function() {
+ //fill with fake, but reasonable, values for testing
+ this.ts = elgg.security.token.__elgg_ts = 12345;
+ this.token = elgg.security.token.__elgg_token = 'abcdef';
+};
+
+ElggSecurityTest.prototype.testAddTokenAcceptsUndefined = function() {
+ var input,
+ expected = {
+ __elgg_ts: this.ts,
+ __elgg_token: this.token
+ };
+
+ assertEquals(expected, elgg.security.addToken(input));
+};
+
+ElggSecurityTest.prototype.testAddTokenAcceptsObject = function() {
+ var input = {},
+ expected = {
+ __elgg_ts: this.ts,
+ __elgg_token: this.token
+ };
+
+ assertEquals(expected, elgg.security.addToken(input));
+};
+
+ElggSecurityTest.prototype.testAddTokenAcceptsString = function() {
+ var input,
+ str = "__elgg_ts=" + this.ts + "&__elgg_token=" + this.token;
+
+ input = "";
+ assertEquals(str, elgg.security.addToken(input));
+
+ input = "data=sofar";
+ assertEquals(input+'&'+str, elgg.security.addToken(input));
+
+};
+
+ElggSecurityTest.prototype.testSetTokenSetsElggSecurityToken = function() {
+ var json = {
+ __elgg_ts: 4567,
+ __elgg_token: 'abcdef'
+ };
+
+ elgg.security.setToken(json);
+ assertEquals(json, elgg.security.token);
+};
+
+
diff --git a/engine/js/tests/ElggSessionTest.js b/engine/js/tests/ElggSessionTest.js new file mode 100644 index 000000000..0245e9e90 --- /dev/null +++ b/engine/js/tests/ElggSessionTest.js @@ -0,0 +1,36 @@ +ElggSessionTest = TestCase("ElggSessionTest");
+
+ElggSessionTest.prototype.testGetCookie = function() {
+ assertEquals(document.cookie, elgg.session.cookie());
+};
+
+ElggSessionTest.prototype.testGetCookieKey = function() {
+ document.cookie = "name=value";
+ assertEquals('value', elgg.session.cookie('name'));
+
+ document.cookie = "name=value2";
+ assertEquals('value2', elgg.session.cookie('name'));
+
+ document.cookie = "name=value";
+ document.cookie = "name2=value2";
+ assertEquals('value', elgg.session.cookie('name'));
+ assertEquals('value2', elgg.session.cookie('name2'));
+};
+
+ElggSessionTest.prototype.testSetCookieKey = function() {
+ elgg.session.cookie('name', 'value');
+ assertEquals('value', elgg.session.cookie('name'));
+
+ elgg.session.cookie('name', 'value2');
+ assertEquals('value2', elgg.session.cookie('name'));
+
+ elgg.session.cookie('name', 'value');
+ elgg.session.cookie('name2', 'value2');
+ assertEquals('value', elgg.session.cookie('name'));
+ assertEquals('value2', elgg.session.cookie('name2'));
+
+ elgg.session.cookie('name', null);
+ elgg.session.cookie('name2', null);
+ assertUndefined(elgg.session.cookie('name'));
+ assertUndefined(elgg.session.cookie('name2'));
+};
\ No newline at end of file |