Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.localize.js |
— | — | @@ -8,66 +8,58 @@ |
9 | 9 | test( 'Handle basic replacements', function() { |
10 | 10 | expect(4); |
11 | 11 | |
12 | | - var html, $lc, expected; |
| 12 | + var html, $lc; |
13 | 13 | mw.messages.set( 'basic', 'Basic stuff' ); |
14 | 14 | |
15 | 15 | // Tag: html:msg |
16 | | - html = '<div><span class="foobar"><html:msg key="basic"></span></div>'; |
| 16 | + html = '<span><html:msg key="basic"></span>'; |
17 | 17 | $lc = $( html ).localize(); |
18 | | - expected = '<span class="foobar">Basic stuff</span>'; |
19 | 18 | |
20 | | - strictEqual( $lc.html(), expected, 'Tag: html:msg' ); |
| 19 | + strictEqual( $lc.html(), 'Basic stuff', 'Tag: html:msg' ); |
21 | 20 | |
22 | 21 | // Tag: msg (deprecated) |
23 | | - html = '<div><span class="foobar"><msg key="basic"></span></div>'; |
| 22 | + html = '<span><msg key="basic"></span>'; |
24 | 23 | $lc = $( html ).localize(); |
25 | | - expected = '<span class="foobar">Basic stuff</span>'; |
26 | 24 | |
27 | | - strictEqual( $lc.html(), expected, 'Tag: msg' ); |
| 25 | + strictEqual( $lc.html(), 'Basic stuff', 'Tag: msg' ); |
28 | 26 | |
29 | 27 | // Attribute: title-msg |
30 | | - html = '<div><span class="foobar" title-msg="basic"></span></div>'; |
31 | | - $lc = $( html ).localize(); |
32 | | - expected = '<span class="foobar" title="Basic stuff"></span>'; |
| 28 | + html = '<div><span title-msg="basic"></span></div>'; |
| 29 | + $lc = $( html ).localize().find( 'span' ); |
33 | 30 | |
34 | | - strictEqual( $lc.html(), expected, 'Attribute: title-msg' ); |
| 31 | + strictEqual( $lc.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' ); |
35 | 32 | |
36 | 33 | // Attribute: alt-msg |
37 | | - html = '<div><span class="foobar" alt-msg="basic"></span></div>'; |
38 | | - $lc = $( html ).localize(); |
39 | | - expected = '<span class="foobar" alt="Basic stuff"></span>'; |
| 34 | + html = '<div><span alt-msg="basic"></span></div>'; |
| 35 | + $lc = $( html ).localize().find( 'span' ); |
40 | 36 | |
41 | | - strictEqual( $lc.html(), expected, 'Attribute: alt-msg' ); |
| 37 | + strictEqual( $lc.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' ); |
42 | 38 | } ); |
43 | 39 | |
44 | 40 | test( 'Proper escaping', function() { |
45 | 41 | expect(2); |
46 | 42 | |
47 | | - var html, $lc, expected; |
| 43 | + var html, $lc; |
48 | 44 | mw.messages.set( 'properfoo', '<proper esc="test">' ); |
49 | 45 | |
50 | 46 | // This is handled by jQuery inside $.fn.localize, just a simple sanity checked |
51 | 47 | // making sure it is actually using text() and attr() (or something with the same effect) |
52 | 48 | |
53 | 49 | // Text escaping |
54 | | - html = '<div><span class="foobar"><html:msg key="properfoo"></span></div>'; |
| 50 | + html = '<span><html:msg key="properfoo"></span>'; |
55 | 51 | $lc = $( html ).localize(); |
56 | | - expected = '<span class="foobar"><proper esc="test"></span>'; |
57 | 52 | |
58 | | - strictEqual( $lc.html(), expected, 'Content is inserted as text, not as html.' ); |
| 53 | + strictEqual( $lc.text(), mw.msg( 'properfoo' ), 'Content is inserted as text, not as html.' ); |
59 | 54 | |
60 | 55 | // Attribute escaping |
61 | | - html = '<div><span class="foobar" title-msg="properbar"></span></div>'; |
62 | | - $lc = $( html ).localize(); |
63 | | - expected = '<span class="foobar" title="<properbar>"></span>'; |
| 56 | + html = '<div><span title-msg="properfoo"></span></div>'; |
| 57 | + $lc = $( html ).localize().find( 'span' ); |
64 | 58 | |
65 | | - strictEqual( $lc.html(), expected, 'Attributes are not inserted raw.' ); |
66 | | - |
67 | | - |
| 59 | + strictEqual( $lc.attr( 'title' ), mw.msg( 'properfoo' ), 'Attributes are not inserted raw.' ); |
68 | 60 | } ); |
69 | 61 | |
70 | 62 | test( 'Options', function() { |
71 | | - expect(4); |
| 63 | + expect(7); |
72 | 64 | |
73 | 65 | mw.messages.set( { |
74 | 66 | 'foo-lorem': 'Lorem', |
— | — | @@ -78,16 +70,16 @@ |
79 | 71 | 'foo-bazz-label': 'The Bazz ($1)', |
80 | 72 | 'foo-welcome': 'Welcome to $1! (last visit: $2)' |
81 | 73 | } ); |
82 | | - var html, $lc, expected, x, sitename = 'Wikipedia'; |
| 74 | + var html, $lc, attrs, x, sitename = 'Wikipedia'; |
83 | 75 | |
84 | 76 | // Message key prefix |
85 | 77 | html = '<div><span title-msg="lorem"><html:msg key="ipsum" /></span></div>'; |
86 | 78 | $lc = $( html ).localize( { |
87 | 79 | prefix: 'foo-' |
88 | | - } ); |
89 | | - expected = '<span title="Lorem">Ipsum</span>'; |
| 80 | + } ).find( 'span' ); |
90 | 81 | |
91 | | - strictEqual( $lc.html(), expected, 'Message key prefix' ); |
| 82 | + strictEqual( $lc.attr( 'title' ), 'Lorem', 'Message key prefix - attr' ); |
| 83 | + strictEqual( $lc.text(), 'Ipsum', 'Message key prefix - text' ); |
92 | 84 | |
93 | 85 | // Variable keys mapping |
94 | 86 | x = 'bar'; |
— | — | @@ -97,21 +89,20 @@ |
98 | 90 | 'title': 'foo-' + x + '-title', |
99 | 91 | 'label': 'foo-' + x + '-label' |
100 | 92 | } |
101 | | - } ); |
102 | | - expected = '<span title="Read more about bars">The Bars</span>'; |
| 93 | + } ).find( 'span' ); |
103 | 94 | |
104 | | - strictEqual( $lc.html(), expected, 'Message prefix' ); |
| 95 | + strictEqual( $lc.attr( 'title' ), 'Read more about bars', 'Variable keys mapping - attr' ); |
| 96 | + strictEqual( $lc.text(), 'The Bars', 'Variable keys mapping - text' ); |
105 | 97 | |
106 | 98 | // Passing parameteters to mw.msg |
107 | | - html = '<div><span><html:msg key="foo-welcome" /></span></div>'; |
| 99 | + html = '<span><html:msg key="foo-welcome" /></span>'; |
108 | 100 | $lc = $( html ).localize( { |
109 | 101 | params: { |
110 | 102 | 'foo-welcome': [sitename, 'yesterday'] |
111 | 103 | } |
112 | 104 | } ); |
113 | | - expected = '<span>Welcome to Wikipedia! (last visit: yesterday)</span>'; |
114 | 105 | |
115 | | - strictEqual( $lc.html(), expected, 'Message prefix' ); |
| 106 | + strictEqual( $lc.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' ); |
116 | 107 | |
117 | 108 | // Combination of options prefix, params and keys |
118 | 109 | x = 'bazz'; |
— | — | @@ -127,8 +118,8 @@ |
128 | 119 | 'label': [sitename, '3 minutes ago'] |
129 | 120 | |
130 | 121 | } |
131 | | - } ); |
132 | | - expected = '<span title="Read more about bazz at Wikipedia (last modified: 3 minutes ago)">The Bazz (Wikipedia)</span>'; |
| 122 | + } ).find( 'span' ); |
133 | 123 | |
134 | | - strictEqual( $lc.html(), expected, 'Message prefix' ); |
| 124 | + strictEqual( $lc.text(), 'The Bazz (Wikipedia)', 'Combination of options prefix, params and keys - text' ); |
| 125 | + strictEqual( $lc.attr( 'title' ), 'Read more about bazz at Wikipedia (last modified: 3 minutes ago)', 'Combination of options prefix, params and keys - attr' ); |
135 | 126 | } ); |