1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects.classes; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.codehaus.plexus.util.StringUtils; |
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
|
30 |
|
import com.xpn.xwiki.objects.BaseObject; |
31 |
|
import com.xpn.xwiki.objects.ListProperty; |
32 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
33 |
|
import com.xpn.xwiki.test.reference.ReferenceComponentList; |
34 |
|
|
35 |
|
import static org.junit.Assert.assertEquals; |
36 |
|
import static org.junit.Assert.assertTrue; |
37 |
|
import static org.mockito.Mockito.doReturn; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
|
44 |
|
@ReferenceComponentList |
|
|
| 100% |
Uncovered Elements: 0 (104) |
Complexity: 11 |
Complexity Density: 0.12 |
|
45 |
|
public class StaticListClassTest |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
private static final List<String> VALUES_WITH_HTML_SPECIAL_CHARS = Arrays.asList("a<b>c", "1\"2'3", "x{y&z"); |
51 |
|
|
52 |
|
@Rule |
53 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
54 |
|
|
55 |
|
@link |
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
56 |
1 |
@Test... |
57 |
|
public void testGetListIsSorted() |
58 |
|
{ |
59 |
1 |
StaticListClass listClass = new StaticListClass(); |
60 |
1 |
listClass.setValues("a=A|c=D|d=C|b"); |
61 |
|
|
62 |
1 |
assertEquals("Default order was not preserved.", "[a, c, d, b]", |
63 |
|
listClass.getList(this.oldcore.getXWikiContext()).toString()); |
64 |
1 |
listClass.setSort("none"); |
65 |
1 |
assertEquals("Default order was not preserved.", "[a, c, d, b]", |
66 |
|
listClass.getList(this.oldcore.getXWikiContext()).toString()); |
67 |
1 |
listClass.setSort("id"); |
68 |
1 |
assertEquals("Items were not ordered by ID.", "[a, b, c, d]", |
69 |
|
listClass.getList(this.oldcore.getXWikiContext()).toString()); |
70 |
1 |
listClass.setSort("value"); |
71 |
1 |
assertEquals("Items were not ordered by value.", "[a, b, d, c]", |
72 |
|
listClass.getList(this.oldcore.getXWikiContext()).toString()); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@see |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void testDisplayView() |
82 |
|
{ |
83 |
1 |
ListProperty listProperty = new ListProperty(); |
84 |
1 |
listProperty.setValue(VALUES_WITH_HTML_SPECIAL_CHARS); |
85 |
|
|
86 |
1 |
String propertyName = "foo"; |
87 |
1 |
BaseObject object = new BaseObject(); |
88 |
1 |
object.addField(propertyName, listProperty); |
89 |
|
|
90 |
1 |
StaticListClass staticListClass = new StaticListClass(); |
91 |
1 |
staticListClass.setSeparator(" * "); |
92 |
1 |
staticListClass.setValues(VALUES_WITH_HTML_SPECIAL_CHARS.get(0) + '|' + VALUES_WITH_HTML_SPECIAL_CHARS.get(1) |
93 |
|
+ '=' + StringUtils.reverse(VALUES_WITH_HTML_SPECIAL_CHARS.get(1)) + '|' |
94 |
|
+ VALUES_WITH_HTML_SPECIAL_CHARS.get(2)); |
95 |
1 |
assertEquals("a<b>c * 3'2\"1 * x{y&z", staticListClass.displayView(propertyName, "", object, null)); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
@param |
103 |
|
@param |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 2 |
Complexity Density: 0.12 |
|
105 |
4 |
private void testDisplayEdit(String displayType, List<String> selectedValues, String expectedHTML)... |
106 |
|
{ |
107 |
4 |
ListProperty listProperty = new ListProperty(); |
108 |
4 |
listProperty.setValue(selectedValues); |
109 |
|
|
110 |
|
|
111 |
4 |
String propertyName = "b&a<r"; |
112 |
4 |
String prefix = "w>v"; |
113 |
4 |
BaseObject object = new BaseObject(); |
114 |
4 |
object.addField(propertyName, listProperty); |
115 |
|
|
116 |
4 |
StaticListClass staticListClass = new StaticListClass(); |
117 |
4 |
staticListClass.setSize(7); |
118 |
4 |
StringBuilder values = new StringBuilder(); |
119 |
4 |
for (String value : VALUES_WITH_HTML_SPECIAL_CHARS) { |
120 |
12 |
if (values.length() > 0) { |
121 |
8 |
values.append('|'); |
122 |
|
} |
123 |
12 |
values.append(value).append('=').append(StringUtils.reverse(value)); |
124 |
|
} |
125 |
4 |
staticListClass.setValues(values.toString()); |
126 |
|
|
127 |
4 |
staticListClass.setDisplayType(displayType); |
128 |
4 |
assertEquals(expectedHTML, staticListClass.displayEdit(propertyName, prefix, object, null)); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
134 |
1 |
@Test... |
135 |
|
public void testDisplayEditInput() |
136 |
|
{ |
137 |
1 |
testDisplayEdit("input", VALUES_WITH_HTML_SPECIAL_CHARS, "<input size='7' id='w>vb&a<r' " |
138 |
|
+ "value='a<b>c|1"2'3|x{y&z' name='w>vb&a<r' type='text'/>"); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
144 |
1 |
@Test... |
145 |
|
public void testDisplayEditSelect() |
146 |
|
{ |
147 |
1 |
String expectedHTML = "<select id='w>vb&a<r' name='w>vb&a<r' size='7'>" |
148 |
|
+ "<option value='a<b>c' label='c>b<a'>c>b<a</option>" |
149 |
|
+ "<option selected='selected' value='1"2'3' label='3'2"1'>3'2"1</option>" |
150 |
|
+ "<option value='x{y&z' label='z&y{x'>z&y{x</option>" |
151 |
|
+ "</select><input name='w>vb&a<r' type='hidden' value=''/>"; |
152 |
1 |
testDisplayEdit("select", Arrays.asList(VALUES_WITH_HTML_SPECIAL_CHARS.get(1)), expectedHTML); |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
158 |
1 |
@Test... |
159 |
|
public void testDisplayEditRadio() |
160 |
|
{ |
161 |
1 |
StringBuilder expectedHTML = new StringBuilder(); |
162 |
1 |
expectedHTML.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-b&a<r-0-0\">"); |
163 |
1 |
expectedHTML.append("<input id='xwiki-form-b&a<r-0-0' value='a<b>c'"); |
164 |
1 |
expectedHTML.append(" name='w>vb&a<r' type='radio'/>c>b<a</label>"); |
165 |
1 |
expectedHTML.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-b&a<r-0-1\">"); |
166 |
1 |
expectedHTML.append("<input id='xwiki-form-b&a<r-0-1' checked='checked' value='1"2'3' "); |
167 |
1 |
expectedHTML.append("name='w>vb&a<r' type='radio'/>3'2"1</label>"); |
168 |
1 |
expectedHTML.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-b&a<r-0-2\">"); |
169 |
1 |
expectedHTML.append("<input id='xwiki-form-b&a<r-0-2' value='x{y&z'"); |
170 |
1 |
expectedHTML.append(" name='w>vb&a<r' type='radio'/>z&y{x</label>"); |
171 |
1 |
expectedHTML.append("<input name='w>vb&a<r' type='hidden' value=''/>"); |
172 |
1 |
testDisplayEdit("radio", Arrays.asList(VALUES_WITH_HTML_SPECIAL_CHARS.get(1)), expectedHTML.toString()); |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
178 |
1 |
@Test... |
179 |
|
public void testDisplayEditCheckbox() |
180 |
|
{ |
181 |
1 |
StringBuilder expectedHTML = new StringBuilder(); |
182 |
1 |
expectedHTML.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-b&a<r-0-0\">"); |
183 |
1 |
expectedHTML.append("<input id='xwiki-form-b&a<r-0-0' value='a<b>c'"); |
184 |
1 |
expectedHTML.append(" name='w>vb&a<r' type='checkbox'/>c>b<a</label>"); |
185 |
1 |
expectedHTML.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-b&a<r-0-1\">"); |
186 |
1 |
expectedHTML.append("<input id='xwiki-form-b&a<r-0-1' checked='checked' value='1"2'3' "); |
187 |
1 |
expectedHTML.append("name='w>vb&a<r' type='checkbox'/>3'2"1</label>"); |
188 |
1 |
expectedHTML.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-b&a<r-0-2\">"); |
189 |
1 |
expectedHTML.append("<input id='xwiki-form-b&a<r-0-2' value='x{y&z'"); |
190 |
1 |
expectedHTML.append(" name='w>vb&a<r' type='checkbox'/>z&y{x</label>"); |
191 |
1 |
expectedHTML.append("<input name='w>vb&a<r' type='hidden' value=''/>"); |
192 |
1 |
testDisplayEdit("checkbox", Arrays.asList(VALUES_WITH_HTML_SPECIAL_CHARS.get(1)), expectedHTML.toString()); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
198 |
1 |
@Test... |
199 |
|
public void testDisplayHidden() |
200 |
|
{ |
201 |
1 |
ListProperty listProperty = new ListProperty(); |
202 |
1 |
listProperty.setValue(VALUES_WITH_HTML_SPECIAL_CHARS); |
203 |
|
|
204 |
|
|
205 |
1 |
String propertyName = "f<o&o"; |
206 |
1 |
BaseObject object = new BaseObject(); |
207 |
1 |
object.addField(propertyName, listProperty); |
208 |
|
|
209 |
1 |
assertEquals( |
210 |
|
"<input id='f<o&o' value='a<b>c|1"2'3|x{y&z' " |
211 |
|
+ "name='f<o&o' type='hidden'/>", |
212 |
|
new StaticListClass().displayHidden(propertyName, "", object, null)); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 2 |
Complexity Density: 0.08 |
1PASS
|
|
218 |
1 |
@Test... |
219 |
|
public void testDisplayEditWithSuggest() throws Exception |
220 |
|
{ |
221 |
1 |
ListProperty listProperty = new ListProperty(); |
222 |
1 |
listProperty.setValue(VALUES_WITH_HTML_SPECIAL_CHARS); |
223 |
|
|
224 |
|
|
225 |
1 |
String propertyName = "b&a<r"; |
226 |
1 |
String prefix = "w>v"; |
227 |
1 |
BaseObject object = new BaseObject(); |
228 |
1 |
object.addField(propertyName, listProperty); |
229 |
|
|
230 |
1 |
StaticListClass staticListClass = new StaticListClass(); |
231 |
1 |
BaseClass ownerClass = new BaseClass(); |
232 |
1 |
ownerClass.setDocumentReference(new DocumentReference("xwiki", "ClassSpace", "ClassName")); |
233 |
1 |
staticListClass.setName(propertyName); |
234 |
1 |
staticListClass.setObject(ownerClass); |
235 |
1 |
staticListClass.setSize(7); |
236 |
1 |
StringBuilder values = new StringBuilder(); |
237 |
1 |
for (String value : VALUES_WITH_HTML_SPECIAL_CHARS) { |
238 |
3 |
if (values.length() > 0) { |
239 |
2 |
values.append('|'); |
240 |
|
} |
241 |
3 |
values.append(value).append('=').append(StringUtils.reverse(value)); |
242 |
|
} |
243 |
1 |
staticListClass.setValues(values.toString()); |
244 |
|
|
245 |
1 |
staticListClass.setDisplayType("input"); |
246 |
1 |
staticListClass.setPicker(true); |
247 |
1 |
doReturn("/xwiki/bin/view/Main/WebHome").when(this.oldcore.getSpyXWiki()).getURL("Main.WebHome", "view", |
248 |
|
this.oldcore.getXWikiContext()); |
249 |
1 |
String output = staticListClass.displayEdit(propertyName, prefix, object, this.oldcore.getXWikiContext()); |
250 |
1 |
System.err.println(output); |
251 |
1 |
assertTrue( |
252 |
|
output.contains("new ajaxSuggest(this, {script:"/xwiki/bin/view/Main/WebHome?xpage=suggest&" |
253 |
|
+ "classname=ClassSpace.ClassName&fieldname=b&a<r&firCol=-&" |
254 |
|
+ "secCol=-&", varname:"input"} )")); |
255 |
|
} |
256 |
|
} |