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