aboutsummaryrefslogtreecommitdiff
path: root/js/tests/ElggAjaxTest.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/ElggAjaxTest.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/ElggAjaxTest.js')
-rw-r--r--js/tests/ElggAjaxTest.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/js/tests/ElggAjaxTest.js b/js/tests/ElggAjaxTest.js
new file mode 100644
index 000000000..1fa5daca5
--- /dev/null
+++ b/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);
+};