aboutsummaryrefslogtreecommitdiff
path: root/js/tests/ElggAjaxTest.js
blob: 1fa5daca553df9a1b281aac65113657c62b621d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
};