[483] | 1 | dojo.provide("dojox.html.tests.entities"); |
---|
| 2 | dojo.require("dojox.html.entities"); |
---|
| 3 | |
---|
| 4 | doh.register("dojox.html.tests.entities", |
---|
| 5 | [ |
---|
| 6 | { |
---|
| 7 | name: "Encode: Basic HTML Entities", |
---|
| 8 | runTest: function(t) { |
---|
| 9 | // summary: |
---|
| 10 | // Simple test of basic encoding of characters considered HTML entities |
---|
| 11 | // description: |
---|
| 12 | // Simple test of basic encoding of characters considered HTML entities |
---|
| 13 | var txt = "This is some \" text \" with & entities inside it that <need to be escaped>"; |
---|
| 14 | var expected = "This is some " text " with & entities inside it that <need to be escaped>"; |
---|
| 15 | var encodedTxt = dojox.html.entities.encode(txt); |
---|
| 16 | doh.assertEqual(expected, encodedTxt); |
---|
| 17 | } |
---|
| 18 | }, |
---|
| 19 | { |
---|
| 20 | name: "Decode: Basic HTML Entities", |
---|
| 21 | runTest: function(t) { |
---|
| 22 | // summary: |
---|
| 23 | // Simple test of basic encoding of characters considered HTML entities |
---|
| 24 | // description: |
---|
| 25 | // Simple test of basic encoding of characters considered HTML entities |
---|
| 26 | var txt = "This is some " text " with & entities inside it that <need to be escaped>"; |
---|
| 27 | var expected = "This is some \" text \" with & entities inside it that <need to be escaped>"; |
---|
| 28 | var decodedTxt = dojox.html.entities.decode(txt); |
---|
| 29 | doh.assertEqual(expected, decodedTxt); |
---|
| 30 | } |
---|
| 31 | }, |
---|
| 32 | { |
---|
| 33 | name: "Encode: Basic Latin Entities", |
---|
| 34 | runTest: function(t) { |
---|
| 35 | // summary: |
---|
| 36 | // Simple test of basic encoding of characters considered Latin type entities |
---|
| 37 | // description: |
---|
| 38 | // Simple test of basic encoding of characters considered Latin type entities |
---|
| 39 | var txt = ""; |
---|
| 40 | var expected = ""; |
---|
| 41 | var map = dojox.html.entities.latin; |
---|
| 42 | var i; |
---|
| 43 | for(i = 0; i < map.length; i++){ |
---|
| 44 | txt += map[i][0]; |
---|
| 45 | expected += "&" + map[i][1] + ";"; |
---|
| 46 | } |
---|
| 47 | var encodedTxt = dojox.html.entities.encode(txt); |
---|
| 48 | doh.assertEqual(expected, encodedTxt); |
---|
| 49 | } |
---|
| 50 | }, |
---|
| 51 | { |
---|
| 52 | name: "Decode: Basic Latin Entities", |
---|
| 53 | runTest: function(t) { |
---|
| 54 | // summary: |
---|
| 55 | // Simple test of basic decoding of characters considered Latin type entities |
---|
| 56 | // description: |
---|
| 57 | // Simple test of basic decoding of characters considered Latin type entities |
---|
| 58 | var txt = ""; |
---|
| 59 | var expected = ""; |
---|
| 60 | var map = dojox.html.entities.latin; |
---|
| 61 | var i; |
---|
| 62 | for(i = 0; i < map.length; i++){ |
---|
| 63 | txt += "&" + map[i][1] + ";"; |
---|
| 64 | expected += map[i][0]; |
---|
| 65 | } |
---|
| 66 | var decodedTxt = dojox.html.entities.decode(txt); |
---|
| 67 | doh.assertEqual(expected, decodedTxt); |
---|
| 68 | } |
---|
| 69 | }, |
---|
| 70 | { |
---|
| 71 | name: "Encode: Custom entity map", |
---|
| 72 | runTest: function(t) { |
---|
| 73 | // summary: |
---|
| 74 | // Simple test of basic encoding using a custom map instead of the default ones. |
---|
| 75 | // description: |
---|
| 76 | // Simple test of basic encoding using a custom map instead of the default ones. |
---|
| 77 | var txt = "This is some \" text with & entities inside it that <need to be escaped>"; |
---|
| 78 | var expected = "This is some " text with & entities inside it that <need to be escaped>"; |
---|
| 79 | var encodedTxt = dojox.html.entities.encode(txt, [["\"", "quot"]]); |
---|
| 80 | doh.assertEqual(expected, encodedTxt); |
---|
| 81 | } |
---|
| 82 | }, |
---|
| 83 | { |
---|
| 84 | name: "Decode: Custom entity map", |
---|
| 85 | runTest: function(t) { |
---|
| 86 | // summary: |
---|
| 87 | // Simple test of basic decoding using a custom map instead of the default ones. |
---|
| 88 | // description: |
---|
| 89 | // Simple test of basic decoding using a custom map instead of the default ones. |
---|
| 90 | var txt = "This is some " text with & entities inside it that <need to be escaped>"; |
---|
| 91 | var expected = "This is some \" text with & entities inside it that <need to be escaped>"; |
---|
| 92 | var decodedTxt = dojox.html.entities.decode(txt, [["\"", "quot"]]); |
---|
| 93 | doh.assertEqual(expected, decodedTxt); |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | ] |
---|
| 97 | ); |
---|