Debian Codegraph @

old-tests/tests_onhold/4_server-side/fnServerParams.js

raw
1 // DATA_TEMPLATE: empty_table
2 oTest.fnStart( "fnServerParams" );
3
4
5 $(document).ready( function () {
6 /* Check the default */
7 var json = {};
8 var oTable = $('#example').dataTable( {
9 "bServerSide": true,
10 "sAjaxSource": "../data_sources/param.php"
11 } ).on('xhr', function (e, settings, o) {
12 json = o;
13 } );
14
15 oTest.fnWaitTest(
16 "jQuery anti-cache parameter was sent",
17 null,
18 function () {
19 return json.get && json.get._;
20 }
21 );
22
23 oTest.fnWaitTest(
24 "Default SSP parameters were sent",
25 null,
26 function () {
27 return 36 === $.map( json.get, function (val) {
28 return val;
29 } ).length;
30 }
31 );
32
33 oTest.fnWaitTest(
34 "Send additional parameters",
35 function () {
36 oSession.fnRestore();
37 json = {};
38
39 $('#example').dataTable( {
40 "bServerSide": true,
41 "sAjaxSource": "../data_sources/param.php",
42 "fnServerParams": function ( data ) {
43 data.push( { name: 'test', value: 'unit' } );
44 }
45 } ).on('xhr', function (e, settings, o) {
46 json = o;
47 } );
48 },
49 function () {
50 return json.get && json.get.test === 'unit';
51 }
52 );
53
54 oTest.fnTest(
55 "Default parameters were still sent",
56 null,
57 function () {
58 return 37 === $.map( json.get, function (val) {
59 return val;
60 } ).length;
61 }
62 );
63
64 oTest.fnWaitTest(
65 "Send multiple parameters",
66 function () {
67 oSession.fnRestore();
68 json = {};
69
70 $('#example').dataTable( {
71 "bServerSide": true,
72 "sAjaxSource": "../data_sources/param.php",
73 "fnServerParams": function ( data ) {
74 data.push( { name: 'test', value: 'unit' } );
75 data.push( { name: 'tapestry', value: 'king' } );
76 }
77 } ).on('xhr', function (e, settings, o) {
78 json = o;
79 } );
80 },
81 function () {
82 return json.get && json.get.test === 'unit' && json.get.tapestry === 'king';
83 }
84 );
85
86 oTest.fnWaitTest(
87 "Delete parameters",
88 function () {
89 oSession.fnRestore();
90 json = {};
91
92 $('#example').dataTable( {
93 "bServerSide": true,
94 "sAjaxSource": "../data_sources/param.php",
95 "fnServerParams": function ( data ) {
96 var remove = function ( a, param ) {
97 for ( var i=0 ; i<a.length ; i++ ) {
98 if ( a[i].name === param ) {
99 a.splice( i, 1 );
100 return;
101 }
102 }
103 };
104 remove( data, 'bRegex_0' );
105 remove( data, 'bRegex_1' );
106 remove( data, 'bRegex_2' );
107 remove( data, 'bRegex_3' );
108 remove( data, 'bRegex_4' );
109 }
110 } ).on('xhr', function (e, settings, o) {
111 json = o;
112 } );
113 },
114 function () {
115 return json.get && 31 === $.map( json.get, function (val) {
116 return val;
117 } ).length;
118 }
119 );
120
121 oTest.fnComplete();
122 } );