1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.web; |
21 |
|
|
22 |
|
import java.lang.reflect.Type; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.Collections; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Locale; |
28 |
|
|
29 |
|
import javax.inject.Provider; |
30 |
|
|
31 |
|
import org.junit.Before; |
32 |
|
import org.junit.Rule; |
33 |
|
import org.junit.Test; |
34 |
|
import org.xwiki.model.reference.DocumentReference; |
35 |
|
import org.xwiki.model.reference.EntityReference; |
36 |
|
import org.xwiki.model.reference.SpaceReference; |
37 |
|
import org.xwiki.model.reference.WikiReference; |
38 |
|
import org.xwiki.query.Query; |
39 |
|
import org.xwiki.query.QueryManager; |
40 |
|
import org.xwiki.security.authorization.Right; |
41 |
|
import org.xwiki.test.annotation.ComponentList; |
42 |
|
|
43 |
|
import com.xpn.xwiki.XWikiContext; |
44 |
|
import com.xpn.xwiki.XWikiException; |
45 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
46 |
|
import com.xpn.xwiki.objects.BaseObject; |
47 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
48 |
|
import com.xpn.xwiki.test.reference.ReferenceComponentList; |
49 |
|
|
50 |
|
import static org.junit.Assert.assertEquals; |
51 |
|
import static org.junit.Assert.assertNotNull; |
52 |
|
import static org.junit.Assert.assertNull; |
53 |
|
import static org.mockito.ArgumentMatchers.any; |
54 |
|
import static org.mockito.Mockito.mock; |
55 |
|
import static org.mockito.Mockito.never; |
56 |
|
import static org.mockito.Mockito.verify; |
57 |
|
import static org.mockito.Mockito.when; |
58 |
|
|
59 |
|
|
60 |
|
@link |
61 |
|
|
62 |
|
@version |
63 |
|
@since |
64 |
|
|
65 |
|
@ComponentList |
66 |
|
@ReferenceComponentList |
|
|
| 100% |
Uncovered Elements: 0 (540) |
Complexity: 47 |
Complexity Density: 0.1 |
|
67 |
|
public class CreateActionTest |
68 |
|
{ |
69 |
|
@Rule |
70 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
71 |
|
|
72 |
|
XWikiURLFactory mockURLFactory; |
73 |
|
|
74 |
|
CreateAction action; |
75 |
|
|
76 |
|
XWikiContext context; |
77 |
|
|
78 |
|
XWikiRequest mockRequest; |
79 |
|
|
80 |
|
XWikiResponse mockResponse; |
81 |
|
|
82 |
|
Query mockTemplateProvidersQuery; |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
|
84 |
39 |
@Before... |
85 |
|
public void setUp() throws Exception |
86 |
|
{ |
87 |
39 |
context = oldcore.getXWikiContext(); |
88 |
|
|
89 |
39 |
Utils.setComponentManager(oldcore.getMocker()); |
90 |
|
|
91 |
39 |
QueryManager mockSecureQueryManager = |
92 |
|
oldcore.getMocker().registerMockComponent((Type) QueryManager.class, "secure"); |
93 |
|
|
94 |
39 |
mockTemplateProvidersQuery = mock(Query.class); |
95 |
39 |
when(mockSecureQueryManager.createQuery(any(), any())).thenReturn(mockTemplateProvidersQuery); |
96 |
39 |
when(mockTemplateProvidersQuery.execute()).thenReturn(Collections.emptyList()); |
97 |
|
|
98 |
39 |
when(oldcore.getMockContextualAuthorizationManager().hasAccess(any(Right.class), any(EntityReference.class))) |
99 |
|
.thenReturn(true); |
100 |
|
|
101 |
39 |
Provider<DocumentReference> mockDocumentReferenceProvider = |
102 |
|
oldcore.getMocker().registerMockComponent(DocumentReference.TYPE_PROVIDER); |
103 |
39 |
when(mockDocumentReferenceProvider.get()) |
104 |
|
.thenReturn(new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome")); |
105 |
|
|
106 |
39 |
mockURLFactory = mock(XWikiURLFactory.class); |
107 |
39 |
context.setURLFactory(mockURLFactory); |
108 |
|
|
109 |
39 |
action = new CreateAction(); |
110 |
|
|
111 |
39 |
mockRequest = mock(XWikiRequest.class); |
112 |
39 |
context.setRequest(mockRequest); |
113 |
|
|
114 |
39 |
mockResponse = mock(XWikiResponse.class); |
115 |
39 |
context.setResponse(mockResponse); |
116 |
|
|
117 |
39 |
when(mockRequest.get("type")).thenReturn("plain"); |
118 |
|
} |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
120 |
1 |
@Test... |
121 |
|
public void newDocumentFromURL() throws Exception |
122 |
|
{ |
123 |
|
|
124 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X"), "Y"); |
125 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
126 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
127 |
1 |
when(document.isNew()).thenReturn(true); |
128 |
|
|
129 |
1 |
context.setDoc(document); |
130 |
|
|
131 |
|
|
132 |
1 |
String result = action.render(context); |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
1 |
assertNull(result); |
138 |
|
|
139 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=&parent=Main.WebHome&title=Y", null, "xwiki", |
140 |
|
context); |
141 |
|
} |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
143 |
1 |
@Test... |
144 |
|
public void newDocumentButNonTerminalFromURL() throws Exception |
145 |
|
{ |
146 |
|
|
147 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X"), "Y"); |
148 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
149 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
150 |
1 |
when(document.isNew()).thenReturn(true); |
151 |
|
|
152 |
1 |
context.setDoc(document); |
153 |
|
|
154 |
|
|
155 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("nonterminal"); |
156 |
|
|
157 |
|
|
158 |
1 |
String result = action.render(context); |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
1 |
assertNull(result); |
164 |
|
|
165 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", "template=&parent=Main.WebHome&title=Y", null, |
166 |
|
"xwiki", context); |
167 |
|
} |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
169 |
1 |
@Test... |
170 |
|
public void newDocumentFromURLWhenNoType() throws Exception |
171 |
|
{ |
172 |
|
|
173 |
1 |
when(mockRequest.get("type")).thenReturn(null); |
174 |
|
|
175 |
|
|
176 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X"), "Y"); |
177 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
178 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
179 |
1 |
when(document.isNew()).thenReturn(true); |
180 |
|
|
181 |
1 |
context.setDoc(document); |
182 |
|
|
183 |
|
|
184 |
1 |
String result = action.render(context); |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
1 |
assertEquals("create", result); |
190 |
|
} |
191 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
192 |
1 |
@Test... |
193 |
|
public void newDocumentWebHomeTopLevelFromURL() throws Exception |
194 |
|
{ |
195 |
|
|
196 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X"), "WebHome"); |
197 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
198 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
199 |
1 |
when(document.isNew()).thenReturn(true); |
200 |
|
|
201 |
1 |
context.setDoc(document); |
202 |
|
|
203 |
|
|
204 |
1 |
String result = action.render(context); |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
1 |
assertNull(result); |
210 |
|
|
211 |
|
|
212 |
1 |
verify(mockURLFactory).createURL("X", "WebHome", "edit", "template=&parent=Main.WebHome&title=X", null, "xwiki", |
213 |
|
context); |
214 |
|
} |
215 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
216 |
1 |
@Test... |
217 |
|
public void newDocumentWebHomeFromURL() throws Exception |
218 |
|
{ |
219 |
|
|
220 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X", "Y"), "WebHome"); |
221 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
222 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
223 |
1 |
when(document.isNew()).thenReturn(true); |
224 |
|
|
225 |
1 |
context.setDoc(document); |
226 |
|
|
227 |
|
|
228 |
1 |
String result = action.render(context); |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
1 |
assertNull(result); |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", "template=&parent=Main.WebHome&title=Y", null, |
238 |
|
"xwiki", context); |
239 |
|
} |
240 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
241 |
1 |
@Test... |
242 |
|
public void newDocumentWebHomeButTerminalFromURL() throws Exception |
243 |
|
{ |
244 |
|
|
245 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X", "Y"), "WebHome"); |
246 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
247 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
248 |
1 |
when(document.isNew()).thenReturn(true); |
249 |
|
|
250 |
1 |
context.setDoc(document); |
251 |
|
|
252 |
|
|
253 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("terminal"); |
254 |
|
|
255 |
|
|
256 |
1 |
String result = action.render(context); |
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
1 |
assertNull(result); |
262 |
|
|
263 |
|
|
264 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=&parent=Main.WebHome&title=Y", null, "xwiki", |
265 |
|
context); |
266 |
|
} |
267 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
268 |
1 |
@Test... |
269 |
|
public void newDocumentWebHomeTopLevelSpaceButTerminalFromURL() throws Exception |
270 |
|
{ |
271 |
|
|
272 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X"), "WebHome"); |
273 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
274 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
275 |
1 |
when(document.isNew()).thenReturn(true); |
276 |
|
|
277 |
1 |
context.setDoc(document); |
278 |
|
|
279 |
|
|
280 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("terminal"); |
281 |
|
|
282 |
|
|
283 |
1 |
String result = action.render(context); |
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
1 |
assertEquals("create", result); |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
1 |
verify(mockURLFactory, never()).createURL(any(), any(), any(), any(), any(), |
295 |
|
any(), any(XWikiContext.class)); |
296 |
|
} |
297 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
298 |
1 |
@Test... |
299 |
|
public void existingDocumentFromUINoName() throws Exception |
300 |
|
{ |
301 |
|
|
302 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
303 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
304 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
305 |
1 |
when(document.isNew()).thenReturn(false); |
306 |
1 |
context.setDoc(document); |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
1 |
String result = action.render(context); |
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
1 |
assertEquals("create", result); |
317 |
|
|
318 |
|
|
319 |
1 |
verify(mockURLFactory, never()).createURL(any(), any(), any(), any(), any(), |
320 |
|
any(), any(XWikiContext.class)); |
321 |
|
} |
322 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
323 |
1 |
@Test... |
324 |
|
public void existingDocumentFromUI() throws Exception |
325 |
|
{ |
326 |
|
|
327 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
328 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
329 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
330 |
1 |
when(document.isNew()).thenReturn(false); |
331 |
1 |
context.setDoc(document); |
332 |
|
|
333 |
|
|
334 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X"); |
335 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
336 |
|
|
337 |
|
|
338 |
1 |
String result = action.render(context); |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
1 |
assertNull(result); |
344 |
|
|
345 |
|
|
346 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", "template=&parent=Main.WebHome&title=Y", null, |
347 |
|
"xwiki", context); |
348 |
|
} |
349 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
350 |
1 |
@Test... |
351 |
|
public void existingDocumentFromUICheckEscaping() throws Exception |
352 |
|
{ |
353 |
|
|
354 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
355 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
356 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
357 |
1 |
when(document.isNew()).thenReturn(false); |
358 |
1 |
context.setDoc(document); |
359 |
|
|
360 |
|
|
361 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X.Y"); |
362 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Z"); |
363 |
|
|
364 |
|
|
365 |
1 |
String result = action.render(context); |
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
1 |
assertNull(result); |
371 |
|
|
372 |
|
|
373 |
1 |
verify(mockURLFactory).createURL("X.Y.Z", "WebHome", "edit", "template=&parent=Main.WebHome&title=Z", null, |
374 |
|
"xwiki", context); |
375 |
|
} |
376 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
377 |
1 |
@Test... |
378 |
|
public void existingDocumentTerminalFromUI() throws Exception |
379 |
|
{ |
380 |
|
|
381 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
382 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
383 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
384 |
1 |
when(document.isNew()).thenReturn(false); |
385 |
1 |
context.setDoc(document); |
386 |
|
|
387 |
|
|
388 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X"); |
389 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
390 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("terminal"); |
391 |
|
|
392 |
|
|
393 |
1 |
String result = action.render(context); |
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
1 |
assertNull(result); |
399 |
|
|
400 |
|
|
401 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=&parent=Main.WebHome&title=Y", null, "xwiki", |
402 |
|
context); |
403 |
|
} |
404 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
405 |
1 |
@Test... |
406 |
|
public void existingDocumentTerminalFromUICheckEscaping() throws Exception |
407 |
|
{ |
408 |
|
|
409 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
410 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
411 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
412 |
1 |
when(document.isNew()).thenReturn(false); |
413 |
1 |
context.setDoc(document); |
414 |
|
|
415 |
|
|
416 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X.Y"); |
417 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Z"); |
418 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("terminal"); |
419 |
|
|
420 |
|
|
421 |
1 |
String result = action.render(context); |
422 |
|
|
423 |
|
|
424 |
|
|
425 |
|
|
426 |
1 |
assertNull(result); |
427 |
|
|
428 |
|
|
429 |
1 |
verify(mockURLFactory).createURL("X.Y", "Z", "edit", "template=&parent=Main.WebHome&title=Z", null, "xwiki", |
430 |
|
context); |
431 |
|
} |
432 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
433 |
1 |
@Test... |
434 |
|
public void existingDocumentTerminalFromUIButAlreadyExisting() throws Exception |
435 |
|
{ |
436 |
|
|
437 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
438 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
439 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
440 |
1 |
when(document.isNew()).thenReturn(false); |
441 |
1 |
context.setDoc(document); |
442 |
|
|
443 |
1 |
oldcore.getDocuments().put(new DocumentReference(documentReference, Locale.ROOT), document); |
444 |
1 |
when(document.getContent()).thenReturn("Some non-empty content"); |
445 |
|
|
446 |
|
|
447 |
|
|
448 |
|
|
449 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("Main"); |
450 |
1 |
when(mockRequest.getParameter("name")).thenReturn("WebHome"); |
451 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("terminal"); |
452 |
|
|
453 |
|
|
454 |
1 |
String result = action.render(context); |
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
|
459 |
1 |
assertEquals("create", result); |
460 |
|
|
461 |
|
|
462 |
1 |
XWikiException exception = (XWikiException) this.oldcore.getScriptContext().getAttribute("createException"); |
463 |
1 |
assertNotNull(exception); |
464 |
1 |
assertEquals(XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY, exception.getCode()); |
465 |
|
|
466 |
|
|
467 |
1 |
verify(mockURLFactory, never()).createURL(any(), any(), any(), any(), any(), |
468 |
|
any(), any(XWikiContext.class)); |
469 |
|
} |
470 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
471 |
1 |
@Test... |
472 |
|
public void existingDocumentFromUITopLevelDocument() throws Exception |
473 |
|
{ |
474 |
|
|
475 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
476 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
477 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
478 |
1 |
when(document.isNew()).thenReturn(false); |
479 |
1 |
context.setDoc(document); |
480 |
|
|
481 |
|
|
482 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
483 |
|
|
484 |
|
|
485 |
1 |
String result = action.render(context); |
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
|
490 |
1 |
assertNull(result); |
491 |
|
|
492 |
|
|
493 |
1 |
verify(mockURLFactory).createURL("Y", "WebHome", "edit", "template=&parent=Main.WebHome&title=Y", null, "xwiki", |
494 |
|
context); |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
501 |
1 |
@Test... |
502 |
|
public void existingDocumentFromUIDeprecated() throws Exception |
503 |
|
{ |
504 |
|
|
505 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
506 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
507 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
508 |
1 |
when(document.isNew()).thenReturn(false); |
509 |
1 |
context.setDoc(document); |
510 |
|
|
511 |
|
|
512 |
1 |
when(mockRequest.getParameter("space")).thenReturn("X"); |
513 |
1 |
when(mockRequest.getParameter("page")).thenReturn("Y"); |
514 |
|
|
515 |
|
|
516 |
1 |
String result = action.render(context); |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
1 |
assertNull(result); |
522 |
|
|
523 |
|
|
524 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=&parent=Main.WebHome&title=Y", null, "xwiki", |
525 |
|
context); |
526 |
|
} |
527 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
528 |
1 |
@Test... |
529 |
|
public void existingDocumentFromUIDeprecatedCheckEscaping() throws Exception |
530 |
|
{ |
531 |
|
|
532 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
533 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
534 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
535 |
1 |
when(document.isNew()).thenReturn(false); |
536 |
1 |
context.setDoc(document); |
537 |
|
|
538 |
|
|
539 |
1 |
when(mockRequest.getParameter("space")).thenReturn("X.Y"); |
540 |
1 |
when(mockRequest.getParameter("page")).thenReturn("Z"); |
541 |
|
|
542 |
|
|
543 |
1 |
String result = action.render(context); |
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
|
548 |
1 |
assertNull(result); |
549 |
|
|
550 |
|
|
551 |
|
|
552 |
1 |
verify(mockURLFactory).createURL("X\\.Y", "Z", "edit", "template=&parent=Main.WebHome&title=Z", null, "xwiki", |
553 |
|
context); |
554 |
|
} |
555 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
556 |
1 |
@Test... |
557 |
|
public void existingDocumentNonTerminalFromUIDeprecated() throws Exception |
558 |
|
{ |
559 |
|
|
560 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
561 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
562 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
563 |
1 |
when(document.isNew()).thenReturn(false); |
564 |
1 |
context.setDoc(document); |
565 |
|
|
566 |
|
|
567 |
1 |
when(mockRequest.getParameter("space")).thenReturn("X"); |
568 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("space"); |
569 |
|
|
570 |
|
|
571 |
1 |
String result = action.render(context); |
572 |
|
|
573 |
|
|
574 |
|
|
575 |
|
|
576 |
1 |
assertNull(result); |
577 |
|
|
578 |
|
|
579 |
1 |
verify(mockURLFactory).createURL("X", "WebHome", "edit", "template=&parent=Main.WebHome&title=X", null, "xwiki", |
580 |
|
context); |
581 |
|
} |
582 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
583 |
1 |
@Test... |
584 |
|
public void existingDocumentNonTerminalFromUIDeprecatedIgnoringPage() throws Exception |
585 |
|
{ |
586 |
|
|
587 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
588 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
589 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
590 |
1 |
when(document.isNew()).thenReturn(false); |
591 |
1 |
context.setDoc(document); |
592 |
|
|
593 |
|
|
594 |
1 |
when(mockRequest.getParameter("space")).thenReturn("X"); |
595 |
1 |
when(mockRequest.getParameter("page")).thenReturn("Y"); |
596 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("space"); |
597 |
|
|
598 |
|
|
599 |
1 |
String result = action.render(context); |
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
|
604 |
1 |
assertNull(result); |
605 |
|
|
606 |
|
|
607 |
|
|
608 |
1 |
verify(mockURLFactory).createURL("X", "WebHome", "edit", "template=&parent=Main.WebHome&title=X", null, "xwiki", |
609 |
|
context); |
610 |
|
} |
611 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
612 |
1 |
@Test... |
613 |
|
public void existingDocumentNonTerminalFromUIDeprecatedCheckEscaping() throws Exception |
614 |
|
{ |
615 |
|
|
616 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
617 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
618 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
619 |
1 |
when(document.isNew()).thenReturn(false); |
620 |
1 |
context.setDoc(document); |
621 |
|
|
622 |
|
|
623 |
1 |
when(mockRequest.getParameter("space")).thenReturn("X.Y"); |
624 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("space"); |
625 |
|
|
626 |
|
|
627 |
1 |
String result = action.render(context); |
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
1 |
assertNull(result); |
633 |
|
|
634 |
|
|
635 |
|
|
636 |
1 |
verify(mockURLFactory).createURL("X\\.Y", "WebHome", "edit", "template=&parent=Main.WebHome&title=X.Y", null, |
637 |
|
"xwiki", context); |
638 |
|
} |
639 |
|
|
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
644 |
1 |
@Test... |
645 |
|
public void existingDocumentFromUITemplateProviderExistingButNoneSelected() throws Exception |
646 |
|
{ |
647 |
|
|
648 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
649 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
650 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
651 |
1 |
when(document.isNew()).thenReturn(false); |
652 |
1 |
context.setDoc(document); |
653 |
|
|
654 |
|
|
655 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X"); |
656 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
657 |
|
|
658 |
|
|
659 |
1 |
mockExistingTemplateProviders("XWiki.MyTemplateProvider", |
660 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST); |
661 |
|
|
662 |
|
|
663 |
1 |
String result = action.render(context); |
664 |
|
|
665 |
|
|
666 |
|
|
667 |
|
|
668 |
1 |
assertEquals("create", result); |
669 |
|
|
670 |
|
|
671 |
1 |
verify(mockURLFactory, never()).createURL(any(), any(), any(), any(), any(), |
672 |
|
any(), any(XWikiContext.class)); |
673 |
|
} |
674 |
|
|
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
680 |
7 |
private void mockExistingTemplateProviders(String fullName, DocumentReference resolvedDocumentReference,... |
681 |
|
List<String> allowedSpaces) throws Exception |
682 |
|
{ |
683 |
7 |
mockExistingTemplateProviders(fullName, resolvedDocumentReference, allowedSpaces, false); |
684 |
|
} |
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
691 |
15 |
private void mockExistingTemplateProviders(String fullName, DocumentReference resolvedDocumentReference,... |
692 |
|
List<String> allowedSpaces, Boolean terminal) throws Exception |
693 |
|
{ |
694 |
15 |
mockExistingTemplateProviders(fullName, resolvedDocumentReference, allowedSpaces, terminal, null); |
695 |
|
} |
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 4 |
Complexity Density: 0.22 |
|
702 |
19 |
private void mockExistingTemplateProviders(String fullName, DocumentReference resolvedDocumentReference,... |
703 |
|
List<String> allowedSpaces, Boolean terminal, String type) throws Exception |
704 |
|
{ |
705 |
19 |
DocumentReference templateProviderClassReference = |
706 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "TemplateProviderClass"); |
707 |
|
|
708 |
|
|
709 |
19 |
when(mockTemplateProvidersQuery.execute()).thenReturn(new ArrayList<Object>(Arrays.asList(fullName))); |
710 |
|
|
711 |
|
|
712 |
19 |
XWikiDocument templateProviderDocument = mock(XWikiDocument.class); |
713 |
19 |
when(templateProviderDocument.getDocumentReference()).thenReturn(resolvedDocumentReference); |
714 |
19 |
oldcore.getDocuments().put(new DocumentReference(resolvedDocumentReference, Locale.ROOT), |
715 |
|
templateProviderDocument); |
716 |
|
|
717 |
19 |
BaseObject templateProviderObject = mock(BaseObject.class); |
718 |
19 |
when(templateProviderObject.getListValue("creationRestrictions")).thenReturn(allowedSpaces); |
719 |
19 |
String templateDocumentFullName = fullName.substring(0, fullName.indexOf("Provider")); |
720 |
19 |
when(templateProviderObject.getStringValue("template")).thenReturn(templateDocumentFullName); |
721 |
19 |
if (terminal != null) { |
722 |
15 |
when(templateProviderObject.getIntValue("terminal", -1)).thenReturn(terminal ? 1 : 0); |
723 |
|
} else { |
724 |
4 |
when(templateProviderObject.getIntValue("terminal", -1)).thenReturn(-1); |
725 |
|
} |
726 |
19 |
if (type != null) { |
727 |
4 |
when(templateProviderObject.getStringValue("type")).thenReturn(type); |
728 |
|
} |
729 |
19 |
when(templateProviderDocument.getXObject(templateProviderClassReference)).thenReturn(templateProviderObject); |
730 |
|
|
731 |
|
|
732 |
19 |
String templateDocumentName = |
733 |
|
resolvedDocumentReference.getName().substring(0, resolvedDocumentReference.getName().indexOf("Provider")); |
734 |
19 |
DocumentReference templateDocumentReference = |
735 |
|
new DocumentReference(templateDocumentName, new SpaceReference(resolvedDocumentReference.getParent())); |
736 |
19 |
mockTemplateDocumentExisting(templateDocumentFullName, templateDocumentReference); |
737 |
|
} |
738 |
|
|
739 |
|
|
740 |
|
@param |
741 |
|
@param |
742 |
|
@throws |
743 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
744 |
20 |
private void mockTemplateDocumentExisting(String templateDocumentFullName,... |
745 |
|
DocumentReference templateDocumentReference) throws XWikiException |
746 |
|
{ |
747 |
20 |
XWikiDocument templateDocument = mock(XWikiDocument.class); |
748 |
20 |
when(templateDocument.getDocumentReference()).thenReturn(templateDocumentReference); |
749 |
20 |
when(templateDocument.getDefaultEditMode(context)).thenReturn("edit"); |
750 |
20 |
oldcore.getDocuments().put(new DocumentReference(templateDocumentReference, Locale.ROOT), templateDocument); |
751 |
|
} |
752 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
753 |
1 |
@Test... |
754 |
|
public void existingDocumentFromUITemplateProviderSpecified() throws Exception |
755 |
|
{ |
756 |
|
|
757 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
758 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
759 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
760 |
1 |
when(document.isNew()).thenReturn(false); |
761 |
1 |
context.setDoc(document); |
762 |
|
|
763 |
|
|
764 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
765 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X"); |
766 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
767 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
768 |
|
|
769 |
|
|
770 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
771 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST); |
772 |
|
|
773 |
|
|
774 |
1 |
String result = action.render(context); |
775 |
|
|
776 |
|
|
777 |
|
|
778 |
|
|
779 |
1 |
assertNull(result); |
780 |
|
|
781 |
|
|
782 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
783 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
784 |
|
} |
785 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
786 |
1 |
@Test... |
787 |
|
public void existingDocumentFromUITemplateProviderSpecifiedRestrictionExists() throws Exception |
788 |
|
{ |
789 |
|
|
790 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
791 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
792 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
793 |
1 |
when(document.isNew()).thenReturn(false); |
794 |
1 |
context.setDoc(document); |
795 |
|
|
796 |
|
|
797 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
798 |
1 |
String spaceReferenceString = "X"; |
799 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn(spaceReferenceString); |
800 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
801 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
802 |
|
|
803 |
|
|
804 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
805 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Arrays.asList("X")); |
806 |
|
|
807 |
|
|
808 |
1 |
String result = action.render(context); |
809 |
|
|
810 |
|
|
811 |
|
|
812 |
|
|
813 |
1 |
assertNull(result); |
814 |
|
|
815 |
|
|
816 |
|
|
817 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
818 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
819 |
|
} |
820 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
821 |
1 |
@Test... |
822 |
|
public void existingDocumentFromUITemplateProviderSpecifiedRestrictionExistsOnParentSpace() throws Exception |
823 |
|
{ |
824 |
|
|
825 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
826 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
827 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
828 |
1 |
when(document.isNew()).thenReturn(false); |
829 |
1 |
context.setDoc(document); |
830 |
|
|
831 |
|
|
832 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
833 |
1 |
String spaceReferenceString = "X.Y.Z"; |
834 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn(spaceReferenceString); |
835 |
1 |
when(mockRequest.getParameter("name")).thenReturn("W"); |
836 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
837 |
|
|
838 |
|
|
839 |
|
|
840 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
841 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Arrays.asList("X")); |
842 |
|
|
843 |
|
|
844 |
1 |
String result = action.render(context); |
845 |
|
|
846 |
|
|
847 |
|
|
848 |
|
|
849 |
1 |
assertNull(result); |
850 |
|
|
851 |
|
|
852 |
|
|
853 |
|
|
854 |
1 |
verify(mockURLFactory).createURL("X.Y.Z.W", "WebHome", "edit", |
855 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=W", null, "xwiki", context); |
856 |
|
} |
857 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
858 |
1 |
@Test... |
859 |
|
public void existingDocumentFromUITemplateProviderSpecifiedButNotAllowed() throws Exception |
860 |
|
{ |
861 |
|
|
862 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
863 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
864 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
865 |
1 |
when(document.isNew()).thenReturn(false); |
866 |
1 |
context.setDoc(document); |
867 |
|
|
868 |
|
|
869 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
870 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X"); |
871 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
872 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
873 |
|
|
874 |
|
|
875 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
876 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), |
877 |
|
Arrays.asList("AnythingButX")); |
878 |
|
|
879 |
|
|
880 |
1 |
String result = action.render(context); |
881 |
|
|
882 |
|
|
883 |
|
|
884 |
|
|
885 |
1 |
assertEquals("create", result); |
886 |
|
|
887 |
|
|
888 |
1 |
XWikiException exception = (XWikiException) this.oldcore.getScriptContext().getAttribute("createException"); |
889 |
1 |
assertNotNull(exception); |
890 |
1 |
assertEquals(XWikiException.ERROR_XWIKI_APP_TEMPLATE_NOT_AVAILABLE, exception.getCode()); |
891 |
|
|
892 |
|
|
893 |
1 |
verify(mockURLFactory, never()).createURL(any(), any(), any(), any(), any(), |
894 |
|
any(), any(XWikiContext.class)); |
895 |
|
} |
896 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
897 |
1 |
@Test... |
898 |
|
public void newDocumentFromURLTemplateProviderSpecifiedButNotAllowed() throws Exception |
899 |
|
{ |
900 |
|
|
901 |
1 |
DocumentReference documentReference = |
902 |
|
new DocumentReference("Y", new SpaceReference("X", new WikiReference("xwiki"))); |
903 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
904 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
905 |
1 |
when(document.isNew()).thenReturn(true); |
906 |
|
|
907 |
1 |
context.setDoc(document); |
908 |
|
|
909 |
|
|
910 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
911 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
912 |
|
|
913 |
|
|
914 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
915 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), |
916 |
|
Arrays.asList("AnythingButX")); |
917 |
|
|
918 |
|
|
919 |
1 |
String result = action.render(context); |
920 |
|
|
921 |
|
|
922 |
|
|
923 |
|
|
924 |
1 |
assertEquals("create", result); |
925 |
|
|
926 |
|
|
927 |
1 |
XWikiException exception = (XWikiException) this.oldcore.getScriptContext().getAttribute("createException"); |
928 |
1 |
assertNotNull(exception); |
929 |
1 |
assertEquals(XWikiException.ERROR_XWIKI_APP_TEMPLATE_NOT_AVAILABLE, exception.getCode()); |
930 |
|
|
931 |
|
|
932 |
1 |
verify(mockURLFactory, never()).createURL(any(), any(), any(), any(), any(), |
933 |
|
any(), any(XWikiContext.class)); |
934 |
|
} |
935 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
936 |
1 |
@Test... |
937 |
|
public void newDocumentWebHomeFromURLTemplateProviderSpecifiedButNotAllowed() throws Exception |
938 |
|
{ |
939 |
|
|
940 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X", "Y"), "WebHome"); |
941 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
942 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
943 |
1 |
when(document.isNew()).thenReturn(true); |
944 |
|
|
945 |
1 |
context.setDoc(document); |
946 |
|
|
947 |
|
|
948 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
949 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
950 |
|
|
951 |
|
|
952 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
953 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), |
954 |
|
Arrays.asList("AnythingButX")); |
955 |
|
|
956 |
|
|
957 |
1 |
String result = action.render(context); |
958 |
|
|
959 |
|
|
960 |
|
|
961 |
|
|
962 |
1 |
assertEquals("create", result); |
963 |
|
|
964 |
|
|
965 |
1 |
XWikiException exception = (XWikiException) this.oldcore.getScriptContext().getAttribute("createException"); |
966 |
1 |
assertNotNull(exception); |
967 |
1 |
assertEquals(XWikiException.ERROR_XWIKI_APP_TEMPLATE_NOT_AVAILABLE, exception.getCode()); |
968 |
|
|
969 |
|
|
970 |
1 |
verify(mockURLFactory, never()).createURL(any(), any(), any(), any(), any(), |
971 |
|
any(), any(XWikiContext.class)); |
972 |
|
} |
973 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
974 |
1 |
@Test... |
975 |
|
public void newDocumentWebHomeFromURLTemplateProviderSpecifiedTerminal() throws Exception |
976 |
|
{ |
977 |
|
|
978 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X", "Y"), "WebHome"); |
979 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
980 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
981 |
1 |
when(document.isNew()).thenReturn(true); |
982 |
|
|
983 |
1 |
context.setDoc(document); |
984 |
|
|
985 |
|
|
986 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
987 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
988 |
|
|
989 |
|
|
990 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
991 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, true); |
992 |
|
|
993 |
|
|
994 |
1 |
String result = action.render(context); |
995 |
|
|
996 |
|
|
997 |
|
|
998 |
|
|
999 |
1 |
assertNull(result); |
1000 |
|
|
1001 |
|
|
1002 |
|
|
1003 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", |
1004 |
|
null, "xwiki", context); |
1005 |
|
} |
1006 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
1007 |
1 |
@Test... |
1008 |
|
public void newDocumentWebHomeFromURLTemplateProviderSpecifiedTerminalOverriddenFromUIToNonTerminal() |
1009 |
|
throws Exception |
1010 |
|
{ |
1011 |
|
|
1012 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X", "Y"), "WebHome"); |
1013 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1014 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1015 |
1 |
when(document.isNew()).thenReturn(true); |
1016 |
|
|
1017 |
1 |
context.setDoc(document); |
1018 |
|
|
1019 |
|
|
1020 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1021 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1022 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("nonterminal"); |
1023 |
|
|
1024 |
|
|
1025 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1026 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, true); |
1027 |
|
|
1028 |
|
|
1029 |
1 |
String result = action.render(context); |
1030 |
|
|
1031 |
|
|
1032 |
|
|
1033 |
|
|
1034 |
1 |
assertNull(result); |
1035 |
|
|
1036 |
|
|
1037 |
|
|
1038 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
1039 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
1040 |
|
} |
1041 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
1042 |
1 |
@Test... |
1043 |
|
public void newDocumentFromURLTemplateProviderSpecifiedNonTerminal() throws Exception |
1044 |
|
{ |
1045 |
|
|
1046 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", "X", "Y"); |
1047 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1048 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1049 |
1 |
when(document.isNew()).thenReturn(true); |
1050 |
|
|
1051 |
1 |
context.setDoc(document); |
1052 |
|
|
1053 |
|
|
1054 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1055 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1056 |
|
|
1057 |
|
|
1058 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1059 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, |
1060 |
|
false); |
1061 |
|
|
1062 |
|
|
1063 |
1 |
String result = action.render(context); |
1064 |
|
|
1065 |
|
|
1066 |
|
|
1067 |
|
|
1068 |
1 |
assertNull(result); |
1069 |
|
|
1070 |
|
|
1071 |
|
|
1072 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
1073 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
1074 |
|
} |
1075 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
1076 |
1 |
@Test... |
1077 |
|
public void newDocumentFromURLTemplateProviderSpecifiedNonTerminalButOverriddenFromUITerminal() throws Exception |
1078 |
|
{ |
1079 |
|
|
1080 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", "X", "Y"); |
1081 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1082 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1083 |
1 |
when(document.isNew()).thenReturn(true); |
1084 |
|
|
1085 |
1 |
context.setDoc(document); |
1086 |
|
|
1087 |
|
|
1088 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1089 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1090 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("terminal"); |
1091 |
|
|
1092 |
|
|
1093 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1094 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, |
1095 |
|
false); |
1096 |
|
|
1097 |
|
|
1098 |
1 |
String result = action.render(context); |
1099 |
|
|
1100 |
|
|
1101 |
|
|
1102 |
|
|
1103 |
1 |
assertNull(result); |
1104 |
|
|
1105 |
|
|
1106 |
|
|
1107 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", |
1108 |
|
null, "xwiki", context); |
1109 |
|
} |
1110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
1111 |
1 |
@Test... |
1112 |
|
public void existingDocumentFromUITemplateSpecified() throws Exception |
1113 |
|
{ |
1114 |
|
|
1115 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
1116 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1117 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1118 |
1 |
when(document.isNew()).thenReturn(false); |
1119 |
|
|
1120 |
1 |
context.setDoc(document); |
1121 |
|
|
1122 |
|
|
1123 |
1 |
String templateDocumentFullName = "XWiki.MyTemplate"; |
1124 |
1 |
DocumentReference templateDocumentReference = |
1125 |
|
new DocumentReference("MyTemplate", Arrays.asList("XWiki"), "xwiki"); |
1126 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X"); |
1127 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
1128 |
1 |
when(mockRequest.getParameter("template")).thenReturn("XWiki.MyTemplate"); |
1129 |
|
|
1130 |
|
|
1131 |
1 |
mockTemplateDocumentExisting(templateDocumentFullName, templateDocumentReference); |
1132 |
|
|
1133 |
|
|
1134 |
1 |
String result = action.render(context); |
1135 |
|
|
1136 |
|
|
1137 |
|
|
1138 |
|
|
1139 |
1 |
assertNull(result); |
1140 |
|
|
1141 |
|
|
1142 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
1143 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
1144 |
|
} |
1145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
1146 |
1 |
@Test... |
1147 |
|
public void existingDocumentFromUITemplateProviderSpecifiedTerminal() throws Exception |
1148 |
|
{ |
1149 |
|
|
1150 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
1151 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1152 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1153 |
1 |
when(document.isNew()).thenReturn(false); |
1154 |
1 |
context.setDoc(document); |
1155 |
|
|
1156 |
|
|
1157 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1158 |
1 |
String spaceReferenceString = "X"; |
1159 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn(spaceReferenceString); |
1160 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
1161 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1162 |
|
|
1163 |
|
|
1164 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1165 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, true); |
1166 |
|
|
1167 |
|
|
1168 |
1 |
String result = action.render(context); |
1169 |
|
|
1170 |
|
|
1171 |
|
|
1172 |
|
|
1173 |
1 |
assertNull(result); |
1174 |
|
|
1175 |
|
|
1176 |
|
|
1177 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", |
1178 |
|
null, "xwiki", context); |
1179 |
|
} |
1180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
1181 |
1 |
@Test... |
1182 |
|
public void existingDocumentFromUITemplateProviderSpecifiedTerminalOverridenFromUIToNonTerminal() throws Exception |
1183 |
|
{ |
1184 |
|
|
1185 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
1186 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1187 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1188 |
1 |
when(document.isNew()).thenReturn(false); |
1189 |
1 |
context.setDoc(document); |
1190 |
|
|
1191 |
|
|
1192 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1193 |
1 |
String spaceReferenceString = "X"; |
1194 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn(spaceReferenceString); |
1195 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
1196 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1197 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("nonterminal"); |
1198 |
|
|
1199 |
|
|
1200 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1201 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, true); |
1202 |
|
|
1203 |
|
|
1204 |
1 |
String result = action.render(context); |
1205 |
|
|
1206 |
|
|
1207 |
|
|
1208 |
|
|
1209 |
1 |
assertNull(result); |
1210 |
|
|
1211 |
|
|
1212 |
|
|
1213 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
1214 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
1215 |
|
} |
1216 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
1217 |
1 |
@Test... |
1218 |
|
public void existingDocumentFromUITemplateProviderSpecifiedNonTerminal() throws Exception |
1219 |
|
{ |
1220 |
|
|
1221 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
1222 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1223 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1224 |
1 |
when(document.isNew()).thenReturn(false); |
1225 |
1 |
context.setDoc(document); |
1226 |
|
|
1227 |
|
|
1228 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1229 |
1 |
String spaceReferenceString = "X"; |
1230 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn(spaceReferenceString); |
1231 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
1232 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1233 |
|
|
1234 |
|
|
1235 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1236 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, |
1237 |
|
false); |
1238 |
|
|
1239 |
|
|
1240 |
1 |
String result = action.render(context); |
1241 |
|
|
1242 |
|
|
1243 |
|
|
1244 |
|
|
1245 |
1 |
assertNull(result); |
1246 |
|
|
1247 |
|
|
1248 |
|
|
1249 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
1250 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
1251 |
|
} |
1252 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
1253 |
1 |
@Test... |
1254 |
|
public void existingDocumentFromUITemplateProviderSpecifiedNonTerminalOverridenFromUIToTerminal() throws Exception |
1255 |
|
{ |
1256 |
|
|
1257 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
1258 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1259 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1260 |
1 |
when(document.isNew()).thenReturn(false); |
1261 |
1 |
context.setDoc(document); |
1262 |
|
|
1263 |
|
|
1264 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1265 |
1 |
String spaceReferenceString = "X"; |
1266 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn(spaceReferenceString); |
1267 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
1268 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1269 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("terminal"); |
1270 |
|
|
1271 |
|
|
1272 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1273 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, |
1274 |
|
false); |
1275 |
|
|
1276 |
|
|
1277 |
1 |
String result = action.render(context); |
1278 |
|
|
1279 |
|
|
1280 |
|
|
1281 |
|
|
1282 |
1 |
assertNull(result); |
1283 |
|
|
1284 |
|
|
1285 |
|
|
1286 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", |
1287 |
|
null, "xwiki", context); |
1288 |
|
} |
1289 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
1290 |
1 |
@Test... |
1291 |
|
public void newDocumentWebHomeFromURLTemplateProviderSpecifiedButOldPageType() throws Exception |
1292 |
|
{ |
1293 |
|
|
1294 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X", "Y"), "WebHome"); |
1295 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1296 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1297 |
1 |
when(document.isNew()).thenReturn(true); |
1298 |
|
|
1299 |
1 |
context.setDoc(document); |
1300 |
|
|
1301 |
|
|
1302 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1303 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1304 |
|
|
1305 |
|
|
1306 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1307 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, null, |
1308 |
|
"page"); |
1309 |
|
|
1310 |
|
|
1311 |
1 |
String result = action.render(context); |
1312 |
|
|
1313 |
|
|
1314 |
|
|
1315 |
|
|
1316 |
1 |
assertNull(result); |
1317 |
|
|
1318 |
|
|
1319 |
|
|
1320 |
|
|
1321 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", |
1322 |
|
null, "xwiki", context); |
1323 |
|
} |
1324 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
1325 |
1 |
@Test... |
1326 |
|
public void newDocumentWebHomeFromURLTemplateProviderSpecifiedButOldPageTypeButOverriddenFromUIToNonTerminal() |
1327 |
|
throws Exception |
1328 |
|
{ |
1329 |
|
|
1330 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("X", "Y"), "WebHome"); |
1331 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1332 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1333 |
1 |
when(document.isNew()).thenReturn(true); |
1334 |
|
|
1335 |
1 |
context.setDoc(document); |
1336 |
|
|
1337 |
|
|
1338 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1339 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1340 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("nonterminal"); |
1341 |
|
|
1342 |
|
|
1343 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1344 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, null, |
1345 |
|
"page"); |
1346 |
|
|
1347 |
|
|
1348 |
1 |
String result = action.render(context); |
1349 |
|
|
1350 |
|
|
1351 |
|
|
1352 |
|
|
1353 |
1 |
assertNull(result); |
1354 |
|
|
1355 |
|
|
1356 |
|
|
1357 |
|
|
1358 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
1359 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
1360 |
|
} |
1361 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
1362 |
1 |
@Test... |
1363 |
|
public void existingDocumentFromUITemplateProviderSpecifiedButOldSpaceType() throws Exception |
1364 |
|
{ |
1365 |
|
|
1366 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
1367 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1368 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1369 |
1 |
when(document.isNew()).thenReturn(false); |
1370 |
1 |
context.setDoc(document); |
1371 |
|
|
1372 |
|
|
1373 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1374 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X"); |
1375 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
1376 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1377 |
|
|
1378 |
|
|
1379 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1380 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, null, |
1381 |
|
"space"); |
1382 |
|
|
1383 |
|
|
1384 |
1 |
String result = action.render(context); |
1385 |
|
|
1386 |
|
|
1387 |
|
|
1388 |
|
|
1389 |
1 |
assertNull(result); |
1390 |
|
|
1391 |
|
|
1392 |
|
|
1393 |
|
|
1394 |
1 |
verify(mockURLFactory).createURL("X.Y", "WebHome", "edit", |
1395 |
|
"template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", null, "xwiki", context); |
1396 |
|
} |
1397 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
1398 |
1 |
@Test... |
1399 |
|
public void existingDocumentFromUITemplateProviderSpecifiedButOldSpaceTypeButOverridenFromUIToTerminal() |
1400 |
|
throws Exception |
1401 |
|
{ |
1402 |
|
|
1403 |
1 |
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); |
1404 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
1405 |
1 |
when(document.getDocumentReference()).thenReturn(documentReference); |
1406 |
1 |
when(document.isNew()).thenReturn(false); |
1407 |
1 |
context.setDoc(document); |
1408 |
|
|
1409 |
|
|
1410 |
1 |
String templateProviderFullName = "XWiki.MyTemplateProvider"; |
1411 |
1 |
when(mockRequest.getParameter("spaceReference")).thenReturn("X"); |
1412 |
1 |
when(mockRequest.getParameter("name")).thenReturn("Y"); |
1413 |
1 |
when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); |
1414 |
1 |
when(mockRequest.getParameter("tocreate")).thenReturn("terminal"); |
1415 |
|
|
1416 |
|
|
1417 |
1 |
mockExistingTemplateProviders(templateProviderFullName, |
1418 |
|
new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.EMPTY_LIST, null, |
1419 |
|
"space"); |
1420 |
|
|
1421 |
|
|
1422 |
1 |
String result = action.render(context); |
1423 |
|
|
1424 |
|
|
1425 |
|
|
1426 |
|
|
1427 |
1 |
assertNull(result); |
1428 |
|
|
1429 |
|
|
1430 |
|
|
1431 |
1 |
verify(mockURLFactory).createURL("X", "Y", "edit", "template=XWiki.MyTemplate&parent=Main.WebHome&title=Y", |
1432 |
|
null, "xwiki", context); |
1433 |
|
} |
1434 |
|
} |