Fixed a bug with $("body") in dynamic documents, refactored $(...), stopped the test...
[jquery.git] / src / jquery / coreTest.js
index d1035cf..4b29c8f 100644 (file)
@@ -67,6 +67,15 @@ test("attr(String)", function() {
        ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );\r
 });\r
 \r
+test("attr(String, Function|String)", function() {\r
+       ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );\r
+       ok( $('#text2').attr('value', "${this.id}")[0].value == "text2", "Set value from id" );\r
+       reset();\r
+       $('#text1, #text2').attr({value: "${this.id + 'foobar'}"});\r
+       ok( $('#text1')[0].value == "text1foobar", "Set value from id" );\r
+       ok( $('#text2')[0].value == "text2foobar", "Set value from id" );\r
+});\r
+\r
 test("attr(Hash)", function() {\r
        expect(1);\r
        var pass = true;\r
@@ -87,7 +96,7 @@ test("attr(String, Object)", function() {
        ok( pass, "Set Attribute" );\r
        \r
        $("#name").attr('name', 'something');\r
-       ok( $("#name").name() == 'something', 'Set name attribute' );\r
+       ok( $("#name").attr('name') == 'something', 'Set name attribute' );\r
        $("#check2").attr('checked', true);\r
        ok( document.getElementById('check2').checked == true, 'Set checked attribute' );\r
        $("#check2").attr('checked', false);\r
@@ -98,19 +107,21 @@ test("attr(String, Object)", function() {
        ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );\r
 });\r
 \r
-test("attr(String, Object)x", function() {\r
-       expect(2);\r
-       stop();\r
-       $.get('data/dashboard.xml', function(xml) { \r
-         var titles = [];\r
-         $('tab', xml).each(function() {\r
-           titles.push($(this).attr('title'));\r
-         });\r
-         ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );\r
-         ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );\r
-         start();\r
+if ( location.protocol != "file:" ) {\r
+       test("attr(String, Object)x", function() {\r
+               expect(2);\r
+               stop();\r
+               $.get('data/dashboard.xml', function(xml) { \r
+               var titles = [];\r
+               $('tab', xml).each(function() {\r
+               titles.push($(this).attr('title'));\r
+               });\r
+               ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );\r
+               ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );\r
+               start();\r
+               });\r
        });\r
-});\r
+}\r
 \r
 test("css(String|Hash)", function() {\r
        expect(8);\r
@@ -170,8 +181,8 @@ test("wrap(String|Element)", function() {
        ok( result.text() == defaultText, 'Check for element wrapping' );\r
 });\r
 \r
-test("append(String|Element|Array<Element>)", function() {\r
-       expect(4);\r
+test("append(String|Element|Array<Element>|jQuery)", function() {\r
+       expect(5);\r
        var defaultText = 'Try them out:'\r
        var result = $('#first').append('<b>buga</b>');\r
        ok( result.text() == defaultText + 'buga', 'Check if text appending works' );\r
@@ -186,10 +197,15 @@ test("append(String|Element|Array&lt;Element&gt;)", function() {
        expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
        $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);\r
        ok( expected == $('#sap').text(), "Check for appending of array of elements" );\r
+       \r
+       reset();\r
+       expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
+       $('#sap').append($("#first, #yahoo"));\r
+       ok( expected == $('#sap').text(), "Check for appending of jQuery object" );\r
 });\r
 \r
-test("prepend(String|Element|Array&lt;Element&gt;)", function() {\r
-       expect(4);\r
+test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {\r
+       expect(5);\r
        var defaultText = 'Try them out:'\r
        var result = $('#first').prepend('<b>buga</b>');\r
        ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );\r
@@ -204,10 +220,15 @@ test("prepend(String|Element|Array&lt;Element&gt;)", function() {
        expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
        $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);\r
        ok( expected == $('#sap').text(), "Check for prepending of array of elements" );\r
+       \r
+       reset();\r
+       expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
+       $('#sap').prepend($("#first, #yahoo"));\r
+       ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );\r
 });\r
 \r
-test("before(String|Element|Array&lt;Element&gt;)", function() {\r
-       expect(3);\r
+test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {\r
+       expect(4);\r
        var expected = 'This is a normal link: bugaYahoo';\r
        $('#yahoo').before('<b>buga</b>');\r
        ok( expected == $('#en').text(), 'Insert String before' );\r
@@ -221,10 +242,15 @@ test("before(String|Element|Array&lt;Element&gt;)", function() {
        expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
        $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);\r
        ok( expected == $('#en').text(), "Insert array of elements before" );\r
+       \r
+       reset();\r
+       expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
+       $('#yahoo').before($("#first, #mark"));\r
+       ok( expected == $('#en').text(), "Insert jQuery before" );\r
 });\r
 \r
-test("after(String|Element|Array&lt;Element&gt;)", function() {\r
-       expect(3);\r
+test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {\r
+       expect(4);\r
        var expected = 'This is a normal link: Yahoobuga';\r
        $('#yahoo').after('<b>buga</b>');\r
        ok( expected == $('#en').text(), 'Insert String after' );\r
@@ -238,6 +264,11 @@ test("after(String|Element|Array&lt;Element&gt;)", function() {
        expected = "This is a normal link: YahooTry them out:diveintomark";\r
        $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);\r
        ok( expected == $('#en').text(), "Insert array of elements after" );\r
+       \r
+       reset();\r
+       expected = "This is a normal link: YahooTry them out:diveintomark";\r
+       $('#yahoo').after($("#first, #mark"));\r
+       ok( expected == $('#en').text(), "Insert jQuery after" );\r
 });\r
 \r
 test("end()", function() {\r
@@ -261,7 +292,7 @@ test("clone()", function() {
 test("filter()", function() {\r
        isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );\r
        isSet( $("p").filter(["#ap", "#sndp"]).get(), q("ap", "sndp"), "filter(Array&lt;String&gt;)" );\r
-       isSet( $("p").filter(function(el) { return !$("a", el).length }).get(), q("sndp", "first"), "filter(Function)" );\r
+       isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );\r
 });\r
 \r
 test("not(String)", function() {\r
@@ -348,27 +379,6 @@ test("html(String)", function() {
        ok( pass, "Set HTML" );\r
 });\r
 \r
-test("id()", function() {\r
-       expect(3);\r
-       ok( $(document.getElementById('main')).id() == "main", "Check for id" );\r
-       ok( $("#foo").id() == "foo", "Check for id" );\r
-       ok( !$("head").id(), "Check for id" );\r
-});\r
-\r
-test("title()", function() {\r
-       expect(2);\r
-       ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );\r
-       ok( !$("#yahoo").title(), "Check for title" );\r
-});\r
-\r
-test("name()", function() {\r
-       expect(3);\r
-       ok( $(document.getElementById('text1')).name() == "action", "Check for name" );\r
-       ok( $("#hidden1").name() == "hidden", "Check for name" );\r
-       ok( !$("#area1").name(), "Check for name" );\r
-});\r
-\r
-\r
 test("siblings([String])", function() {\r
        expect(3);\r
        isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );\r
@@ -427,3 +437,7 @@ test("removeAttr(String", function() {
        ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );\r
 });\r
 \r
+test("text(String, Boolean)", function() {\r
+       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" );\r
+       ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>", true)[0].innerHTML == "Hello cruel world!", "Check stripped text" );\r
+});
\ No newline at end of file