Fixed #1419 where IE failed with .text() on an XML node. This is part of a series...
[jquery.git] / test / unit / core.js
1 module("core");
2
3 test("Basic requirements", function() {
4         expect(7);
5         ok( Array.prototype.push, "Array.push()" );
6         ok( Function.prototype.apply, "Function.apply()" );
7         ok( document.getElementById, "getElementById" );
8         ok( document.getElementsByTagName, "getElementsByTagName" );
9         ok( RegExp, "RegExp" );
10         ok( jQuery, "jQuery" );
11         ok( $, "$()" );
12 });
13
14 test("$()", function() {
15         expect(4);
16         
17         var main = $("#main");
18         isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
19         
20 /*
21         // disabled since this test was doing nothing. i tried to fix it but i'm not sure
22         // what the expected behavior should even be. FF returns "\n" for the text node
23         // make sure this is handled
24         var crlfContainer = $('<p>\r\n</p>');
25         var x = crlfContainer.contents().get(0).nodeValue;
26         equals( x, what???, "Check for \\r and \\n in jQuery()" );
27 */
28         
29         /* // Disabled until we add this functionality in
30         var pass = true;
31         try {
32                 $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
33         } catch(e){
34                 pass = false;
35         }
36         ok( pass, "$('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
37
38         var code = $("<code/>");
39         equals( code.length, 1, "Correct number of elements generated for code" );
40         var img = $("<img/>");
41         equals( img.length, 1, "Correct number of elements generated for img" );
42         var div = $("<div/><hr/><code/><b/>");
43         equals( div.length, 4, "Correct number of elements generated for div hr code b" );
44 });
45
46 test("noConflict", function() {
47         expect(6);
48         
49         var old = jQuery;
50         var newjQuery = jQuery.noConflict();
51
52         ok( newjQuery == old, "noConflict returned the jQuery object" );
53         ok( jQuery == old, "Make sure jQuery wasn't touched." );
54         ok( $ == "$", "Make sure $ was reverted." );
55
56         jQuery = $ = old;
57
58         newjQuery = jQuery.noConflict(true);
59
60         ok( newjQuery == old, "noConflict returned the jQuery object" );
61         ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
62         ok( $ == "$", "Make sure $ was reverted." );
63
64         jQuery = $ = old;
65 });
66
67 test("isFunction", function() {
68         expect(21);
69
70         // Make sure that false values return false
71         ok( !jQuery.isFunction(), "No Value" );
72         ok( !jQuery.isFunction( null ), "null Value" );
73         ok( !jQuery.isFunction( undefined ), "undefined Value" );
74         ok( !jQuery.isFunction( "" ), "Empty String Value" );
75         ok( !jQuery.isFunction( 0 ), "0 Value" );
76
77         // Check built-ins
78         // Safari uses "(Internal Function)"
79         ok( jQuery.isFunction(String), "String Function" );
80         ok( jQuery.isFunction(Array), "Array Function" );
81         ok( jQuery.isFunction(Object), "Object Function" );
82         ok( jQuery.isFunction(Function), "Function Function" );
83
84         // When stringified, this could be misinterpreted
85         var mystr = "function";
86         ok( !jQuery.isFunction(mystr), "Function String" );
87
88         // When stringified, this could be misinterpreted
89         var myarr = [ "function" ];
90         ok( !jQuery.isFunction(myarr), "Function Array" );
91
92         // When stringified, this could be misinterpreted
93         var myfunction = { "function": "test" };
94         ok( !jQuery.isFunction(myfunction), "Function Object" );
95
96         // Make sure normal functions still work
97         var fn = function(){};
98         ok( jQuery.isFunction(fn), "Normal Function" );
99
100         var obj = document.createElement("object");
101
102         // Firefox says this is a function
103         ok( !jQuery.isFunction(obj), "Object Element" );
104
105         // IE says this is an object
106         ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
107
108         var nodes = document.body.childNodes;
109
110         // Safari says this is a function
111         ok( !jQuery.isFunction(nodes), "childNodes Property" );
112
113         var first = document.body.firstChild;
114         
115         // Normal elements are reported ok everywhere
116         ok( !jQuery.isFunction(first), "A normal DOM Element" );
117
118         var input = document.createElement("input");
119         input.type = "text";
120         document.body.appendChild( input );
121
122         // IE says this is an object
123         ok( jQuery.isFunction(input.focus), "A default function property" );
124
125         document.body.removeChild( input );
126
127         var a = document.createElement("a");
128         a.href = "some-function";
129         document.body.appendChild( a );
130
131         // This serializes with the word 'function' in it
132         ok( !jQuery.isFunction(a), "Anchor Element" );
133
134         document.body.removeChild( a );
135
136         // Recursive function calls have lengths and array-like properties
137         function callme(callback){
138                 function fn(response){
139                         callback(response);
140                 }
141
142                 ok( jQuery.isFunction(fn), "Recursive Function Call" );
143
144         fn({ some: "data" });
145         };
146
147         callme(function(){
148         callme(function(){});
149         });
150 });
151
152 var foo = false;
153
154 test("$('html')", function() {
155         expect(4);
156
157         reset();
158         foo = false;
159         var s = $("<script>var foo='test';</script>")[0];
160         ok( s, "Creating a script" );
161         ok( !foo, "Make sure the script wasn't executed prematurely" );
162         $("body").append(s);
163         ok( foo, "Executing a scripts contents in the right context" );
164         
165         reset();
166         ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
167         
168         reset();
169 });
170
171 test("$('html', context)", function() {
172         expect(1);
173
174         var $div = $("<div/>");
175         var $span = $("<span/>", $div);
176         equals($span.length, 1, "Verify a span created with a div context works, #1763");
177 });
178
179 test("$(selector, xml).text(str) - Loaded via XML document", function() {
180         expect(2);
181         stop();
182         $.get('data/dashboard.xml', function(xml) { 
183                 // tests for #1419 where IE was a problem
184                 equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" );
185                 $("tab:first", xml).text("newtext");
186                 equals( $("tab:first", xml).text(), "newtext", "Verify new text correct" );
187                 start();
188         });
189 });
190
191 test("length", function() {
192         expect(1);
193         ok( $("p").length == 6, "Get Number of Elements Found" );
194 });
195
196 test("size()", function() {
197         expect(1);
198         ok( $("p").size() == 6, "Get Number of Elements Found" );
199 });
200
201 test("get()", function() {
202         expect(1);
203         isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
204 });
205
206 test("get(Number)", function() {
207         expect(1);
208         ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" );
209 });
210
211 test("add(String|Element|Array)", function() {
212         expect(7);
213         isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
214         isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
215         ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
216         
217         var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
218         ok( x[0].id == "x1", "Check on-the-fly element1" );
219         ok( x[1].id == "x2", "Check on-the-fly element2" );
220         
221         var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
222         ok( x[0].id == "x1", "Check on-the-fly element1" );
223         ok( x[1].id == "x2", "Check on-the-fly element2" );
224 });
225
226 test("each(Function)", function() {
227         expect(1);
228         var div = $("div");
229         div.each(function(){this.foo = 'zoo';});
230         var pass = true;
231         for ( var i = 0; i < div.size(); i++ ) {
232           if ( div.get(i).foo != "zoo" ) pass = false;
233         }
234         ok( pass, "Execute a function, Relative" );
235 });
236
237 test("index(Object)", function() {
238         expect(8);
239         ok( $([window, document]).index(window) == 0, "Check for index of elements" );
240         ok( $([window, document]).index(document) == 1, "Check for index of elements" );
241         var inputElements = $('#radio1,#radio2,#check1,#check2');
242         ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
243         ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
244         ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
245         ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
246         ok( inputElements.index(window) == -1, "Check for not found index" );
247         ok( inputElements.index(document) == -1, "Check for not found index" );
248 });
249
250 test("attr(String)", function() {
251         expect(20);
252         ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
253         ok( $('#text1').attr('value', "Test2").attr('defaultValue') == "Test", 'Check for defaultValue attribute' );
254         ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
255         ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
256         ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
257         ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
258         ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
259         ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
260         ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
261         ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
262         ok( $('#name').attr('name') == "name", 'Check for name attribute' );
263         ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
264         ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
265         ok( $('#text1').attr('maxlength') == '30', 'Check for maxlength attribute' );
266         ok( $('#text1').attr('maxLength') == '30', 'Check for maxLength attribute' );
267         ok( $('#area1').attr('maxLength') == '30', 'Check for maxLength attribute' );
268         ok( $('#select2').attr('selectedIndex') == 3, 'Check for selectedIndex attribute' );
269         ok( $('#foo').attr('nodeName') == 'DIV', 'Check for nodeName attribute' );
270         ok( $('#foo').attr('tagName') == 'DIV', 'Check for tagName attribute' );
271         
272         $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
273         ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
274 });
275
276 if ( !isLocal ) {
277     test("attr(String) in XML Files", function() {
278         expect(2);
279         stop();
280         $.get("data/dashboard.xml", function(xml) {
281             ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
282             ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
283             start();
284         });
285     });
286 }
287
288 test("attr(String, Function)", function() {
289         expect(2);
290         ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
291         ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
292 });
293
294 test("attr(Hash)", function() {
295         expect(1);
296         var pass = true;
297         $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
298           if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
299         });
300         ok( pass, "Set Multiple Attributes" );
301 });
302
303 test("attr(String, Object)", function() {
304         expect(16);
305         var div = $("div");
306         div.attr("foo", "bar");
307         var pass = true;
308         for ( var i = 0; i < div.size(); i++ ) {
309           if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
310         }
311         ok( pass, "Set Attribute" );
312
313         ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );    
314         
315         $("#name").attr('name', 'something');
316         ok( $("#name").attr('name') == 'something', 'Set name attribute' );
317         $("#check2").attr('checked', true);
318         ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
319         $("#check2").attr('checked', false);
320         ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
321         $("#text1").attr('readonly', true);
322         ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
323         $("#text1").attr('readonly', false);
324         ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
325         $("#name").attr('maxlength', '5');
326         ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' );
327         $("#name").attr('maxLength', '10');
328         ok( document.getElementById('name').maxLength == '10', 'Set maxlength attribute' );
329
330         // for #1070
331         $("#name").attr('someAttr', '0');
332         equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
333         $("#name").attr('someAttr', 0);
334         equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
335         $("#name").attr('someAttr', 1);
336         equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
337
338         reset();
339
340         var type = $("#check2").attr('type');
341         var thrown = false;
342         try {
343                 $("#check2").attr('type','hidden');
344         } catch(e) {
345                 thrown = true;
346         }
347         ok( thrown, "Exception thrown when trying to change type property" );
348         equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
349
350         var check = document.createElement("input");
351         var thrown = true;
352         try {
353                 $(check).attr('type','checkbox');
354         } catch(e) {
355                 thrown = false;
356         }
357         ok( thrown, "Exception thrown when trying to change type property" );
358         equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
359 });
360
361 if ( !isLocal ) {
362     test("attr(String, Object) - Loaded via XML document", function() {
363         expect(2);
364         stop();
365         $.get('data/dashboard.xml', function(xml) { 
366               var titles = [];
367               $('tab', xml).each(function() {
368                     titles.push($(this).attr('title'));
369               });
370               equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
371               equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
372               start();
373         });
374     });
375 }
376
377 test("css(String|Hash)", function() {
378         expect(19);
379         
380         ok( $('#main').css("display") == 'none', 'Check for css property "display"');
381         
382         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
383         $('#foo').css({display: 'none'});
384         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
385         $('#foo').css({display: 'block'});
386         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
387         
388         $('#floatTest').css({styleFloat: 'right'});
389         ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
390         $('#floatTest').css({cssFloat: 'left'});
391         ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
392         $('#floatTest').css({'float': 'right'});
393         ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
394         $('#floatTest').css({'font-size': '30px'});
395         ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
396         
397         $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
398                 $('#foo').css({opacity: n});
399                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
400                 $('#foo').css({opacity: parseFloat(n)});
401                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
402         });     
403         $('#foo').css({opacity: ''});
404         ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
405 });
406
407 test("css(String, Object)", function() {
408         expect(19);
409         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
410         $('#foo').css('display', 'none');
411         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
412         $('#foo').css('display', 'block');
413         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
414         
415         $('#floatTest').css('styleFloat', 'left');
416         ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
417         $('#floatTest').css('cssFloat', 'right');
418         ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
419         $('#floatTest').css('float', 'left');
420         ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
421         $('#floatTest').css('font-size', '20px');
422         ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
423         
424         $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
425                 $('#foo').css('opacity', n);
426                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
427                 $('#foo').css('opacity', parseFloat(n));
428                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
429         });
430         $('#foo').css('opacity', '');
431         ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
432         // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
433         if (jQuery.browser.msie) {
434                 $('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
435         }
436         equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
437 });
438
439 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
440         expect(4);
441
442         var $checkedtest = $("#checkedtest");
443         // IE6 was clearing "checked" in jQuery.css(elem, "height");
444         jQuery.css($checkedtest[0], "height");
445         ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
446         ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
447         ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
448         ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
449 });
450
451 test("width()", function() {
452         expect(2);
453
454         $("#nothiddendiv").width(30);
455         equals($("#nothiddendiv").width(), 30, "Test set to 30 correctly");
456         $("#nothiddendiv").width(-1); // handle negative numbers by ignoring #1599
457         equals($("#nothiddendiv").width(), 30, "Test negative width ignored");
458 });
459
460 test("text()", function() {
461         expect(1);
462         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
463         ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
464 });
465
466 test("wrap(String|Element)", function() {
467         expect(6);
468         var defaultText = 'Try them out:'
469         var result = $('#first').wrap('<div class="red"><span></span></div>').text();
470         ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
471         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
472
473         reset();
474         var defaultText = 'Try them out:'
475         var result = $('#first').wrap(document.getElementById('empty')).parent();
476         ok( result.is('ol'), 'Check for element wrapping' );
477         ok( result.text() == defaultText, 'Check for element wrapping' );
478         
479         reset();
480         $('#check1').click(function() {         
481                 var checkbox = this;            
482                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
483                 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
484                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
485         }).click();
486 });
487
488 test("wrapAll(String|Element)", function() {
489         expect(8);
490         var prev = $("#first")[0].previousSibling;
491         var p = $("#first")[0].parentNode;
492         var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
493         equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
494         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
495         ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
496         equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
497         equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
498
499         reset();
500         var prev = $("#first")[0].previousSibling;
501         var p = $("#first")[0].parentNode;
502         var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
503         equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
504         equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
505         equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
506 });
507
508 test("wrapInner(String|Element)", function() {
509         expect(6);
510         var num = $("#first").children().length;
511         var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
512         equals( $("#first").children().length, 1, "Only one child" );
513         ok( $("#first").children().is(".red"), "Verify Right Element" );
514         equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
515
516         reset();
517         var num = $("#first").children().length;
518         var result = $('#first').wrapInner(document.getElementById('empty'));
519         equals( $("#first").children().length, 1, "Only one child" );
520         ok( $("#first").children().is("#empty"), "Verify Right Element" );
521         equals( $("#first").children().children().length, num, "Verify Elements Intact" );
522 });
523
524 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
525         expect(18);
526         var defaultText = 'Try them out:'
527         var result = $('#first').append('<b>buga</b>');
528         ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
529         ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
530         
531         reset();
532         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
533         $('#sap').append(document.getElementById('first'));
534         ok( expected == $('#sap').text(), "Check for appending of element" );
535         
536         reset();
537         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
538         $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
539         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
540         
541         reset();
542         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
543         $('#sap').append($("#first, #yahoo"));
544         ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
545
546         reset();
547         $("#sap").append( 5 );
548         ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
549
550         reset();
551         $("#sap").append( " text with spaces " );
552         ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
553
554         reset();
555         ok( $("#sap").append([]), "Check for appending an empty array." );
556         ok( $("#sap").append(""), "Check for appending an empty string." );
557         ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
558         
559         reset();
560         $("#sap").append(document.getElementById('form'));
561         ok( $("#sap>form").size() == 1, "Check for appending a form" );  // Bug #910
562
563         reset();
564         var pass = true;
565         try {
566                 $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
567         } catch(e) {
568                 pass = false;
569         }
570
571         ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
572         
573         reset();
574         $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
575         t( 'Append legend', '#legend', ['legend'] );
576         
577         reset();
578         $('#select1').append('<OPTION>Test</OPTION>');
579         ok( $('#select1 option:last').text() == "Test", "Appending &lt;OPTION&gt; (all caps)" );
580         
581         $('#table').append('<colgroup></colgroup>');
582         ok( $('#table colgroup').length, "Append colgroup" );
583         
584         $('#table colgroup').append('<col/>');
585         ok( $('#table colgroup col').length, "Append col" );
586         
587         reset();
588         $('#table').append('<caption></caption>');
589         ok( $('#table caption').length, "Append caption" );
590
591         reset();
592         $('form:last')
593                 .append('<select id="appendSelect1"></select>')
594                 .append('<select id="appendSelect2"><option>Test</option></select>');
595         
596         t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
597 });
598
599 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
600         expect(6);
601         var defaultText = 'Try them out:'
602         $('<b>buga</b>').appendTo('#first');
603         ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
604         ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
605         
606         reset();
607         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
608         $(document.getElementById('first')).appendTo('#sap');
609         ok( expected == $('#sap').text(), "Check for appending of element" );
610         
611         reset();
612         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
613         $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
614         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
615         
616         reset();
617         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
618         $("#first, #yahoo").appendTo('#sap');
619         ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
620         
621         reset();
622         $('#select1').appendTo('#foo');
623         t( 'Append select', '#foo select', ['select1'] );
624 });
625
626 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
627         expect(5);
628         var defaultText = 'Try them out:'
629         var result = $('#first').prepend('<b>buga</b>');
630         ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
631         ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
632         
633         reset();
634         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
635         $('#sap').prepend(document.getElementById('first'));
636         ok( expected == $('#sap').text(), "Check for prepending of element" );
637
638         reset();
639         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
640         $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
641         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
642         
643         reset();
644         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
645         $('#sap').prepend($("#first, #yahoo"));
646         ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
647 });
648
649 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
650         expect(6);
651         var defaultText = 'Try them out:'
652         $('<b>buga</b>').prependTo('#first');
653         ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
654         ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
655         
656         reset();
657         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
658         $(document.getElementById('first')).prependTo('#sap');
659         ok( expected == $('#sap').text(), "Check for prepending of element" );
660
661         reset();
662         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
663         $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
664         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
665         
666         reset();
667         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
668         $("#yahoo, #first").prependTo('#sap');
669         ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
670         
671         reset();
672         $('<select id="prependSelect1"></select>').prependTo('form:last');
673         $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
674         
675         t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
676 });
677
678 test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
679         expect(4);
680         var expected = 'This is a normal link: bugaYahoo';
681         $('#yahoo').before('<b>buga</b>');
682         ok( expected == $('#en').text(), 'Insert String before' );
683         
684         reset();
685         expected = "This is a normal link: Try them out:Yahoo";
686         $('#yahoo').before(document.getElementById('first'));
687         ok( expected == $('#en').text(), "Insert element before" );
688         
689         reset();
690         expected = "This is a normal link: Try them out:diveintomarkYahoo";
691         $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
692         ok( expected == $('#en').text(), "Insert array of elements before" );
693         
694         reset();
695         expected = "This is a normal link: Try them out:diveintomarkYahoo";
696         $('#yahoo').before($("#first, #mark"));
697         ok( expected == $('#en').text(), "Insert jQuery before" );
698 });
699
700 test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
701         expect(4);
702         var expected = 'This is a normal link: bugaYahoo';
703         $('<b>buga</b>').insertBefore('#yahoo');
704         ok( expected == $('#en').text(), 'Insert String before' );
705         
706         reset();
707         expected = "This is a normal link: Try them out:Yahoo";
708         $(document.getElementById('first')).insertBefore('#yahoo');
709         ok( expected == $('#en').text(), "Insert element before" );
710         
711         reset();
712         expected = "This is a normal link: Try them out:diveintomarkYahoo";
713         $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
714         ok( expected == $('#en').text(), "Insert array of elements before" );
715         
716         reset();
717         expected = "This is a normal link: Try them out:diveintomarkYahoo";
718         $("#first, #mark").insertBefore('#yahoo');
719         ok( expected == $('#en').text(), "Insert jQuery before" );
720 });
721
722 test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
723         expect(4);
724         var expected = 'This is a normal link: Yahoobuga';
725         $('#yahoo').after('<b>buga</b>');
726         ok( expected == $('#en').text(), 'Insert String after' );
727         
728         reset();
729         expected = "This is a normal link: YahooTry them out:";
730         $('#yahoo').after(document.getElementById('first'));
731         ok( expected == $('#en').text(), "Insert element after" );
732
733         reset();
734         expected = "This is a normal link: YahooTry them out:diveintomark";
735         $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
736         ok( expected == $('#en').text(), "Insert array of elements after" );
737         
738         reset();
739         expected = "This is a normal link: YahooTry them out:diveintomark";
740         $('#yahoo').after($("#first, #mark"));
741         ok( expected == $('#en').text(), "Insert jQuery after" );
742 });
743
744 test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
745         expect(4);
746         var expected = 'This is a normal link: Yahoobuga';
747         $('<b>buga</b>').insertAfter('#yahoo');
748         ok( expected == $('#en').text(), 'Insert String after' );
749         
750         reset();
751         expected = "This is a normal link: YahooTry them out:";
752         $(document.getElementById('first')).insertAfter('#yahoo');
753         ok( expected == $('#en').text(), "Insert element after" );
754
755         reset();
756         expected = "This is a normal link: YahooTry them out:diveintomark";
757         $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
758         ok( expected == $('#en').text(), "Insert array of elements after" );
759         
760         reset();
761         expected = "This is a normal link: YahooTry them out:diveintomark";
762         $("#mark, #first").insertAfter('#yahoo');
763         ok( expected == $('#en').text(), "Insert jQuery after" );
764 });
765
766 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
767         expect(10);
768         $('#yahoo').replaceWith('<b id="replace">buga</b>');
769         ok( $("#replace")[0], 'Replace element with string' );
770         ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
771         
772         reset();
773         $('#yahoo').replaceWith(document.getElementById('first'));
774         ok( $("#first")[0], 'Replace element with element' );
775         ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
776
777         reset();
778         $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
779         ok( $("#first")[0], 'Replace element with array of elements' );
780         ok( $("#mark")[0], 'Replace element with array of elements' );
781         ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
782         
783         reset();
784         $('#yahoo').replaceWith($("#first, #mark"));
785         ok( $("#first")[0], 'Replace element with set of elements' );
786         ok( $("#mark")[0], 'Replace element with set of elements' );
787         ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
788 });
789
790 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
791         expect(10);
792         $('<b id="replace">buga</b>').replaceAll("#yahoo");
793         ok( $("#replace")[0], 'Replace element with string' );
794         ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
795         
796         reset();
797         $(document.getElementById('first')).replaceAll("#yahoo");
798         ok( $("#first")[0], 'Replace element with element' );
799         ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
800
801         reset();
802         $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
803         ok( $("#first")[0], 'Replace element with array of elements' );
804         ok( $("#mark")[0], 'Replace element with array of elements' );
805         ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
806         
807         reset();
808         $("#first, #mark").replaceAll("#yahoo");
809         ok( $("#first")[0], 'Replace element with set of elements' );
810         ok( $("#mark")[0], 'Replace element with set of elements' );
811         ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
812 });
813
814 test("end()", function() {
815         expect(3);
816         ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
817         ok( $('#yahoo').end(), 'Check for end with nothing to end' );
818         
819         var x = $('#yahoo');
820         x.parent();
821         ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
822 });
823
824 test("find(String)", function() {
825         expect(1);
826         ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
827 });
828
829 test("clone()", function() {
830         expect(3);
831         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
832         var clone = $('#yahoo').clone();
833         ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
834         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
835 });
836
837 test("is(String)", function() {
838         expect(26);
839         ok( $('#form').is('form'), 'Check for element: A form must be a form' );
840         ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
841         ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
842         ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
843         ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
844         ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
845         ok( $('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
846         ok( !$('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
847         ok( $('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
848         ok( !$('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
849         ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
850         ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
851         ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
852         ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
853         ok( $('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
854         ok( !$('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
855         ok( $('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
856         ok( !$('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
857         ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
858         ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
859         ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
860         ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
861         
862         // test is() with comma-seperated expressions
863         ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
864         ok( $('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
865         ok( $('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
866         ok( $('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
867 });
868
869 test("$.extend(Object, Object)", function() {
870         expect(17);
871
872         var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
873                 options =     { xnumber2: 1, xstring2: "x", xxx: "newstring" },
874                 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
875                 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
876                 deep1 = { foo: { bar: true } },
877                 deep1copy = { foo: { bar: true } },
878                 deep2 = { foo: { baz: true }, foo2: document },
879                 deep2copy = { foo: { baz: true }, foo2: document },
880                 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
881
882         jQuery.extend(settings, options);
883         isObj( settings, merged, "Check if extended: settings must be extended" );
884         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
885
886         jQuery.extend(settings, null, options);
887         isObj( settings, merged, "Check if extended: settings must be extended" );
888         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
889
890         jQuery.extend(true, deep1, deep2);
891         isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
892         isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
893         equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
894
895         var target = {};
896         var recursive = { foo:target, bar:5 };
897         jQuery.extend(true, target, recursive);
898         isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
899
900         var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
901         ok( ret.foo.length == 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
902
903         var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
904         ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
905
906         var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
907         ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
908
909         var obj = { foo:null };
910         jQuery.extend(true, obj, { foo:"notnull" } );
911         equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
912
913         function func() {}
914         jQuery.extend(func, { key: "value" } );
915         equals( func.key, "value", "Verify a function can be extended" );
916
917         var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
918                 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
919                 options1 =     { xnumber2: 1, xstring2: "x" },
920                 options1Copy = { xnumber2: 1, xstring2: "x" },
921                 options2 =     { xstring2: "xx", xxx: "newstringx" },
922                 options2Copy = { xstring2: "xx", xxx: "newstringx" },
923                 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
924
925         var settings = jQuery.extend({}, defaults, options1, options2);
926         isObj( settings, merged2, "Check if extended: settings must be extended" );
927         isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
928         isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
929         isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
930 });
931
932 test("val()", function() {
933         expect(3);
934         ok( $("#text1").val() == "Test", "Check for value of input element" );
935         ok( !$("#text1").val() == "", "Check for value of input element" );
936         // ticket #1714 this caused a JS error in IE
937         ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" );
938 });
939
940 test("val(String)", function() {
941         expect(3);
942         document.getElementById('text1').value = "bla";
943         ok( $("#text1").val() == "bla", "Check for modified value of input element" );
944         $("#text1").val('test');
945         ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
946         
947         $("#select1").val("3");
948         ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
949 });
950
951 var scriptorder = 0;
952
953 test("html(String)", function() {
954         expect(10);
955         var div = $("#main > div");
956         div.html("<b>test</b>");
957         var pass = true;
958         for ( var i = 0; i < div.size(); i++ ) {
959                 if ( div.get(i).childNodes.length != 1 ) pass = false;
960         }
961         ok( pass, "Set HTML" );
962
963         $("#main").html("<select/>");
964         $("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
965         equals( $("#main select").val(), "O2", "Selected option correct" );
966
967         stop();
968
969         $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
970
971         $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
972
973         $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 0,'Execute before html')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
974
975         setTimeout( start, 100 );
976 });
977
978 test("filter()", function() {
979         expect(4);
980         isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
981         isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
982         isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
983         isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
984 });
985
986 test("not()", function() {
987         expect(3);
988         ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
989         isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
990         isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
991 });
992
993 test("andSelf()", function() {
994         expect(4);
995         isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
996         isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
997         isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
998         isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
999 });
1000
1001 test("siblings([String])", function() {
1002         expect(5);
1003         isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
1004         isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 
1005         isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
1006         isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
1007         isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
1008 });
1009
1010 test("children([String])", function() {
1011         expect(3);
1012         isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
1013         isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
1014         isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
1015 });
1016
1017 test("parent([String])", function() {
1018         expect(5);
1019         ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
1020         ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
1021         ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
1022         ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
1023         isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
1024 });
1025         
1026 test("parents([String])", function() {
1027         expect(5);
1028         ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
1029         ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
1030         ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
1031         isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
1032         isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
1033 });
1034
1035 test("next([String])", function() {
1036         expect(4);
1037         ok( $("#ap").next()[0].id == "foo", "Simple next check" );
1038         ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
1039         ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
1040         ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
1041 });
1042         
1043 test("prev([String])", function() {
1044         expect(4);
1045         ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
1046         ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
1047         ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
1048         ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
1049 });
1050
1051 test("show()", function() {
1052         expect(1);
1053         var pass = true, div = $("div");
1054         div.show().each(function(){
1055           if ( this.style.display == "none" ) pass = false;
1056         });
1057         ok( pass, "Show" );
1058 });
1059
1060 test("addClass(String)", function() {
1061         expect(1);
1062         var div = $("div");
1063         div.addClass("test");
1064         var pass = true;
1065         for ( var i = 0; i < div.size(); i++ ) {
1066          if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
1067         }
1068         ok( pass, "Add Class" );
1069 });
1070
1071 test("removeClass(String) - simple", function() {
1072         expect(3);
1073         var div = $("div").addClass("test").removeClass("test"),
1074                 pass = true;
1075         for ( var i = 0; i < div.size(); i++ ) {
1076                 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
1077         }
1078         ok( pass, "Remove Class" );
1079         
1080         reset();
1081         var div = $("div").addClass("test").addClass("foo").addClass("bar");
1082         div.removeClass("test").removeClass("bar").removeClass("foo");
1083         var pass = true;
1084         for ( var i = 0; i < div.size(); i++ ) {
1085          if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
1086         }
1087         ok( pass, "Remove multiple classes" );
1088         
1089         reset();
1090         var div = $("div:eq(0)").addClass("test").removeClass("");
1091         ok( div.is('.test'), "Empty string passed to removeClass" );
1092         
1093 });
1094
1095 test("toggleClass(String)", function() {
1096         expect(3);
1097         var e = $("#firstp");
1098         ok( !e.is(".test"), "Assert class not present" );
1099         e.toggleClass("test");
1100         ok( e.is(".test"), "Assert class present" ); 
1101         e.toggleClass("test");
1102         ok( !e.is(".test"), "Assert class not present" );
1103 });
1104
1105 test("removeAttr(String", function() {
1106         expect(1);
1107         ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
1108 });
1109
1110 test("text(String)", function() {
1111         expect(1);
1112         ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
1113 });
1114
1115 test("$.each(Object,Function)", function() {
1116         expect(8);
1117         $.each( [0,1,2], function(i, n){
1118                 ok( i == n, "Check array iteration" );
1119         });
1120         
1121         $.each( [5,6,7], function(i, n){
1122                 ok( i == n - 5, "Check array iteration" );
1123         });
1124          
1125         $.each( { name: "name", lang: "lang" }, function(i, n){
1126                 ok( i == n, "Check object iteration" );
1127         });
1128 });
1129
1130 test("$.prop", function() {
1131         expect(2);
1132         var handle = function() { return this.id };
1133         ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
1134         ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
1135 });
1136
1137 test("$.className", function() {
1138         expect(6);
1139         var x = $("<p>Hi</p>")[0];
1140         var c = $.className;
1141         c.add(x, "hi");
1142         ok( x.className == "hi", "Check single added class" );
1143         c.add(x, "foo bar");
1144         ok( x.className == "hi foo bar", "Check more added classes" );
1145         c.remove(x);
1146         ok( x.className == "", "Remove all classes" );
1147         c.add(x, "hi foo bar");
1148         c.remove(x, "foo");
1149         ok( x.className == "hi bar", "Check removal of one class" );
1150         ok( c.has(x, "hi"), "Check has1" );
1151         ok( c.has(x, "bar"), "Check has2" );
1152 });
1153
1154 test("remove()", function() {
1155         expect(4);
1156         $("#ap").children().remove();
1157         ok( $("#ap").text().length > 10, "Check text is not removed" );
1158         ok( $("#ap").children().length == 0, "Check remove" );
1159         
1160         reset();
1161         $("#ap").children().remove("a");
1162         ok( $("#ap").text().length > 10, "Check text is not removed" );
1163         ok( $("#ap").children().length == 1, "Check filtered remove" );
1164 });
1165
1166 test("empty()", function() {
1167         expect(2);
1168         ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
1169         ok( $("#ap").children().length == 4, "Check elements are not removed" );
1170 });
1171
1172 test("slice()", function() {
1173         expect(5);
1174         isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
1175         isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
1176         isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
1177         isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
1178
1179         isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
1180 });
1181
1182 test("map()", function() {
1183         expect(2);
1184
1185         isSet(
1186                 $("#ap").map(function(){
1187                         return $(this).find("a").get();
1188                 }),
1189                 q("google", "groups", "anchor1", "mark"),
1190                 "Array Map"
1191         );
1192
1193         isSet(
1194                 $("#ap > a").map(function(){
1195                         return this.parentNode;
1196                 }),
1197                 q("ap","ap","ap"),
1198                 "Single Map"
1199         );
1200 });
1201
1202 test("contents()", function() {
1203         expect(10);
1204         equals( $("#ap").contents().length, 9, "Check element contents" );
1205         ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
1206         var ibody = $("#loadediframe").contents()[0].body;
1207         ok( ibody, "Check existance of IFrame body" );
1208
1209         equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
1210
1211         $(ibody).append("<div>init text</div>");
1212         equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
1213
1214         equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
1215
1216         $("div:last", ibody).text("div text");
1217         equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
1218
1219         $("div:last", ibody).remove();
1220         equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
1221
1222         equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
1223
1224         $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
1225         $("table", ibody).remove();
1226         equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
1227 });