| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki; |
| 21 |
|
|
| 22 |
|
import java.io.ByteArrayInputStream; |
| 23 |
|
import java.net.URL; |
| 24 |
|
import java.util.ArrayList; |
| 25 |
|
import java.util.Arrays; |
| 26 |
|
import java.util.Collections; |
| 27 |
|
import java.util.Date; |
| 28 |
|
import java.util.Enumeration; |
| 29 |
|
import java.util.HashMap; |
| 30 |
|
import java.util.Locale; |
| 31 |
|
import java.util.Map; |
| 32 |
|
|
| 33 |
|
import javax.servlet.http.Cookie; |
| 34 |
|
|
| 35 |
|
import org.apache.commons.collections4.IteratorUtils; |
| 36 |
|
import org.jmock.Mock; |
| 37 |
|
import org.jmock.core.Invocation; |
| 38 |
|
import org.jmock.core.stub.CustomStub; |
| 39 |
|
import org.junit.Assert; |
| 40 |
|
import org.xwiki.bridge.event.DocumentCreatedEvent; |
| 41 |
|
import org.xwiki.bridge.event.DocumentCreatingEvent; |
| 42 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
| 43 |
|
import org.xwiki.bridge.event.DocumentDeletingEvent; |
| 44 |
|
import org.xwiki.localization.LocalizationContext; |
| 45 |
|
import org.xwiki.model.reference.DocumentReference; |
| 46 |
|
import org.xwiki.model.reference.ObjectReference; |
| 47 |
|
import org.xwiki.model.reference.WikiReference; |
| 48 |
|
import org.xwiki.observation.EventListener; |
| 49 |
|
import org.xwiki.observation.ObservationManager; |
| 50 |
|
import org.xwiki.rendering.syntax.Syntax; |
| 51 |
|
import org.xwiki.wiki.descriptor.WikiDescriptor; |
| 52 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
| 53 |
|
|
| 54 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
| 55 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 56 |
|
import com.xpn.xwiki.objects.BaseObject; |
| 57 |
|
import com.xpn.xwiki.objects.BaseProperty; |
| 58 |
|
import com.xpn.xwiki.objects.StringProperty; |
| 59 |
|
import com.xpn.xwiki.objects.classes.PropertyClass; |
| 60 |
|
import com.xpn.xwiki.store.XWikiHibernateStore; |
| 61 |
|
import com.xpn.xwiki.store.XWikiHibernateVersioningStore; |
| 62 |
|
import com.xpn.xwiki.store.XWikiStoreInterface; |
| 63 |
|
import com.xpn.xwiki.store.XWikiVersioningStoreInterface; |
| 64 |
|
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase; |
| 65 |
|
import com.xpn.xwiki.user.api.XWikiAuthService; |
| 66 |
|
import com.xpn.xwiki.user.api.XWikiRightService; |
| 67 |
|
import com.xpn.xwiki.web.XWikiRequest; |
| 68 |
|
import com.xpn.xwiki.web.XWikiServletRequest; |
| 69 |
|
import com.xpn.xwiki.web.XWikiServletRequestStub; |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
@link |
| 73 |
|
|
| 74 |
|
@version |
| 75 |
|
|
| |
|
| 98.4% |
Uncovered Elements: 4 (250) |
Complexity: 35 |
Complexity Density: 0.17 |
|
| 76 |
|
public class XWikiTest extends AbstractBridgedXWikiComponentTestCase |
| 77 |
|
{ |
| 78 |
|
private XWikiDocument document; |
| 79 |
|
|
| 80 |
|
private XWiki xwiki; |
| 81 |
|
|
| 82 |
|
private Mock mockXWikiStore; |
| 83 |
|
|
| 84 |
|
private Mock mockXWikiVersioningStore; |
| 85 |
|
|
| 86 |
|
private Mock mockWikiDescriptorManager; |
| 87 |
|
|
| 88 |
|
private Map<String, XWikiDocument> docs = new HashMap<String, XWikiDocument>(); |
| 89 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
|
| 90 |
19 |
@Override... |
| 91 |
|
protected void setUp() throws Exception |
| 92 |
|
{ |
| 93 |
19 |
super.setUp(); |
| 94 |
|
|
| 95 |
19 |
this.document = new XWikiDocument(new DocumentReference("Wiki", "MilkyWay", "Fidis")); |
| 96 |
19 |
getContext().setRequest(new XWikiServletRequestStub()); |
| 97 |
19 |
getContext().setURL(new URL("http://localhost:8080/xwiki/bin/view/MilkyWay/Fidis")); |
| 98 |
|
|
| 99 |
19 |
Mock mockLocalizationContext = registerMockComponent(LocalizationContext.class); |
| 100 |
19 |
mockLocalizationContext.stubs().method("getCurrentLocale").will(returnValue(Locale.ROOT)); |
| 101 |
|
|
| 102 |
19 |
this.mockWikiDescriptorManager = registerMockComponent(WikiDescriptorManager.class); |
| 103 |
19 |
this.mockWikiDescriptorManager.stubs().method("getCurrentWikiId").will( |
| 104 |
|
new CustomStub("Implements WikiDescriptorManager.getCurrentWikiId") |
| 105 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 106 |
702 |
@Override... |
| 107 |
|
public Object invoke(Invocation invocation) throws Throwable |
| 108 |
|
{ |
| 109 |
702 |
return getContext().getWikiId(); |
| 110 |
|
} |
| 111 |
|
}); |
| 112 |
|
|
| 113 |
19 |
this.xwiki = new XWiki(new XWikiConfig(), getContext()) |
| 114 |
|
{ |
| 115 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
| 116 |
31 |
@Override... |
| 117 |
|
public String getXWikiPreference(String prefname, String defaultValue, XWikiContext context) |
| 118 |
|
{ |
| 119 |
31 |
if (prefname.equals("plugins") || prefname.startsWith("macros_")) { |
| 120 |
19 |
return defaultValue; |
| 121 |
|
} else { |
| 122 |
12 |
return super.getXWikiPreference(prefname, defaultValue, context); |
| 123 |
|
} |
| 124 |
|
} |
| 125 |
|
}; |
| 126 |
19 |
getContext().setWiki(this.xwiki); |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
19 |
getConfigurationSource().setProperty("xwiki.render.velocity.macrolist", ""); |
| 132 |
|
|
| 133 |
19 |
this.mockXWikiStore = |
| 134 |
|
mock(XWikiHibernateStore.class, new Class[] {XWiki.class, XWikiContext.class}, new Object[] {this.xwiki, |
| 135 |
|
getContext()}); |
| 136 |
19 |
this.mockXWikiStore.stubs().method("loadXWikiDoc").will( |
| 137 |
|
new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") |
| 138 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 139 |
116 |
@Override... |
| 140 |
|
public Object invoke(Invocation invocation) throws Throwable |
| 141 |
|
{ |
| 142 |
116 |
XWikiDocument shallowDoc = (XWikiDocument) invocation.parameterValues.get(0); |
| 143 |
116 |
if (XWikiTest.this.docs.containsKey(shallowDoc.getName())) { |
| 144 |
78 |
return XWikiTest.this.docs.get(shallowDoc.getName()); |
| 145 |
|
} else { |
| 146 |
38 |
return shallowDoc; |
| 147 |
|
} |
| 148 |
|
} |
| 149 |
|
}); |
| 150 |
19 |
this.mockXWikiStore.stubs().method("saveXWikiDoc").will( |
| 151 |
|
new CustomStub("Implements XWikiStoreInterface.saveXWikiDoc") |
| 152 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 153 |
52 |
@Override... |
| 154 |
|
public Object invoke(Invocation invocation) throws Throwable |
| 155 |
|
{ |
| 156 |
52 |
XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0); |
| 157 |
52 |
document.setNew(false); |
| 158 |
52 |
document.setStore((XWikiStoreInterface) XWikiTest.this.mockXWikiStore.proxy()); |
| 159 |
52 |
XWikiTest.this.docs.put(document.getName(), document); |
| 160 |
52 |
return null; |
| 161 |
|
} |
| 162 |
|
}); |
| 163 |
19 |
this.mockXWikiStore.stubs().method("deleteXWikiDoc").will( |
| 164 |
|
new CustomStub("Implements XWikiStoreInterface.deleteXWikiDoc") |
| 165 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 166 |
1 |
@Override... |
| 167 |
|
public Object invoke(Invocation invocation) throws Throwable |
| 168 |
|
{ |
| 169 |
1 |
XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0); |
| 170 |
1 |
XWikiTest.this.docs.remove(document.getName()); |
| 171 |
1 |
return null; |
| 172 |
|
} |
| 173 |
|
}); |
| 174 |
19 |
this.mockXWikiStore.stubs().method("getTranslationList").will(returnValue(Collections.EMPTY_LIST)); |
| 175 |
19 |
this.mockXWikiStore.stubs().method("exists").will(returnValue(true)); |
| 176 |
|
|
| 177 |
19 |
this.mockXWikiVersioningStore = |
| 178 |
|
mock(XWikiHibernateVersioningStore.class, new Class[] {XWiki.class, XWikiContext.class}, new Object[] { |
| 179 |
|
this.xwiki, getContext()}); |
| 180 |
19 |
this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(null)); |
| 181 |
19 |
this.mockXWikiVersioningStore.stubs().method("resetRCSArchive").will(returnValue(null)); |
| 182 |
|
|
| 183 |
19 |
this.xwiki.setStore((XWikiStoreInterface) this.mockXWikiStore.proxy()); |
| 184 |
19 |
this.xwiki.setVersioningStore((XWikiVersioningStoreInterface) this.mockXWikiVersioningStore.proxy()); |
| 185 |
19 |
this.xwiki.saveDocument(this.document, getContext()); |
| 186 |
|
|
| 187 |
19 |
this.document.setCreator("Condor"); |
| 188 |
19 |
this.document.setAuthor("Albatross"); |
| 189 |
|
|
| 190 |
19 |
this.xwiki.saveDocument(this.document, getContext()); |
| 191 |
|
} |
| 192 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 193 |
1 |
public void testAuthorAfterDocumentCopy() throws XWikiException... |
| 194 |
|
{ |
| 195 |
1 |
DocumentReference copyReference = |
| 196 |
|
new DocumentReference("Lyre", this.document.getDocumentReference().getLastSpaceReference()); |
| 197 |
1 |
DocumentReference author = this.document.getAuthorReference(); |
| 198 |
1 |
this.xwiki.copyDocument(this.document.getDocumentReference(), copyReference, getContext()); |
| 199 |
1 |
XWikiDocument copy = this.xwiki.getDocument(copyReference, getContext()); |
| 200 |
|
|
| 201 |
1 |
assertEquals(author, copy.getAuthorReference()); |
| 202 |
|
} |
| 203 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 204 |
1 |
public void testCreatorAfterDocumentCopy() throws XWikiException... |
| 205 |
|
{ |
| 206 |
1 |
DocumentReference copyReference = |
| 207 |
|
new DocumentReference("Sirius", this.document.getDocumentReference().getLastSpaceReference()); |
| 208 |
1 |
DocumentReference creator = this.document.getCreatorReference(); |
| 209 |
1 |
this.xwiki.copyDocument(this.document.getDocumentReference(), copyReference, getContext()); |
| 210 |
1 |
XWikiDocument copy = this.xwiki.getDocument(copyReference, getContext()); |
| 211 |
|
|
| 212 |
1 |
assertEquals(creator, copy.getCreatorReference()); |
| 213 |
|
} |
| 214 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 215 |
1 |
public void testCreationDateAfterDocumentCopy() throws XWikiException, InterruptedException... |
| 216 |
|
{ |
| 217 |
1 |
Date sourceCreationDate = this.document.getCreationDate(); |
| 218 |
1 |
Thread.sleep(1000); |
| 219 |
1 |
DocumentReference copyReference = |
| 220 |
|
new DocumentReference(this.document.getDocumentReference().getName() + "Copy", this.document |
| 221 |
|
.getDocumentReference().getLastSpaceReference()); |
| 222 |
1 |
this.xwiki.copyDocument(this.document.getDocumentReference(), copyReference, getContext()); |
| 223 |
1 |
XWikiDocument copy = this.xwiki.getDocument(copyReference, getContext()); |
| 224 |
|
|
| 225 |
1 |
assertTrue(copy.getCreationDate().equals(sourceCreationDate)); |
| 226 |
|
} |
| 227 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 228 |
1 |
public void testParseTemplateConsidersObjectField() throws XWikiException... |
| 229 |
|
{ |
| 230 |
1 |
DocumentReference skinReference = new DocumentReference("xwiki", "XWiki", "XWikiSkins"); |
| 231 |
1 |
XWikiDocument skinClass = new XWikiDocument(skinReference); |
| 232 |
1 |
skinClass.getXClass().addTextAreaField("template.vm", "template", 80, 20); |
| 233 |
1 |
this.xwiki.saveDocument(skinClass, getContext()); |
| 234 |
|
|
| 235 |
1 |
DocumentReference mySkinReference = new DocumentReference("xwiki", "XWiki", "Skin"); |
| 236 |
1 |
XWikiDocument skinDocument = new XWikiDocument(mySkinReference); |
| 237 |
1 |
BaseObject obj = skinDocument.newXObject(skinReference, getContext()); |
| 238 |
1 |
obj.setLargeStringValue("template.vm", "parsing a field"); |
| 239 |
1 |
this.xwiki.saveDocument(skinDocument, getContext()); |
| 240 |
|
|
| 241 |
1 |
getContext().put("skin", "XWiki.Skin"); |
| 242 |
1 |
assertEquals("XWiki.Skin", this.xwiki.getSkin(getContext())); |
| 243 |
1 |
assertFalse(this.xwiki.getDocument(mySkinReference, getContext()).isNew()); |
| 244 |
1 |
assertEquals(skinDocument, this.xwiki.getDocument(mySkinReference, getContext())); |
| 245 |
1 |
assertEquals("parsing a field", this.xwiki.parseTemplate("template.vm", getContext())); |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 251 |
1 |
public void testParseTemplateConsidersAttachment() throws XWikiException... |
| 252 |
|
{ |
| 253 |
1 |
XWikiDocument skin = new XWikiDocument(new DocumentReference("Wiki", "XWiki", "Skin")); |
| 254 |
1 |
XWikiAttachment attachment = new XWikiAttachment(); |
| 255 |
1 |
skin.getAttachmentList().add(attachment); |
| 256 |
1 |
attachment.setContent("parsing an attachment".getBytes()); |
| 257 |
1 |
attachment.setFilename("template.vm"); |
| 258 |
1 |
attachment.setDoc(skin); |
| 259 |
1 |
this.xwiki.saveDocument(skin, getContext()); |
| 260 |
1 |
getContext().put("skin", "XWiki.Skin"); |
| 261 |
|
|
| 262 |
1 |
assertEquals("XWiki.Skin", this.xwiki.getSkin(getContext())); |
| 263 |
1 |
assertFalse(this.xwiki.getDocument("XWiki.Skin", getContext()).isNew()); |
| 264 |
1 |
assertEquals(skin, this.xwiki.getDocument("XWiki.Skin", getContext())); |
| 265 |
1 |
assertEquals("parsing an attachment", this.xwiki.parseTemplate("template.vm", getContext())); |
| 266 |
|
} |
| 267 |
|
|
| 268 |
|
|
| 269 |
|
|
| 270 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 271 |
1 |
public void testParseTemplateConsidersObjectFieldBeforeAttachment() throws Exception... |
| 272 |
|
{ |
| 273 |
1 |
DocumentReference skinReference = new DocumentReference("xwiki", "XWiki", "XWikiSkins"); |
| 274 |
1 |
XWikiDocument skinClass = new XWikiDocument(skinReference); |
| 275 |
1 |
skinClass.getXClass().addTextAreaField("template.vm", "template", 80, 20); |
| 276 |
1 |
this.xwiki.saveDocument(skinClass, getContext()); |
| 277 |
|
|
| 278 |
1 |
DocumentReference mySkinReference = new DocumentReference("xwiki", "XWiki", "Skin"); |
| 279 |
1 |
XWikiDocument skinDocument = new XWikiDocument(mySkinReference); |
| 280 |
1 |
BaseObject obj = skinDocument.newXObject(skinReference, getContext()); |
| 281 |
1 |
obj.setLargeStringValue("template.vm", "parsing a field"); |
| 282 |
1 |
XWikiAttachment attachment = new XWikiAttachment(); |
| 283 |
1 |
skinDocument.getAttachmentList().add(attachment); |
| 284 |
1 |
attachment.setContent(new ByteArrayInputStream("parsing an attachment".getBytes())); |
| 285 |
1 |
attachment.setFilename("template.vm"); |
| 286 |
1 |
attachment.setDoc(skinDocument); |
| 287 |
1 |
this.xwiki.saveDocument(skinDocument, getContext()); |
| 288 |
1 |
getContext().put("skin", "XWiki.Skin"); |
| 289 |
1 |
assertEquals("XWiki.Skin", this.xwiki.getSkin(getContext())); |
| 290 |
1 |
assertFalse(this.xwiki.getDocument(mySkinReference, getContext()).isNew()); |
| 291 |
1 |
assertEquals(skinDocument, this.xwiki.getDocument(mySkinReference, getContext())); |
| 292 |
1 |
assertEquals("parsing a field", this.xwiki.parseTemplate("template.vm", getContext())); |
| 293 |
|
} |
| 294 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 295 |
1 |
public void testClearNameWithoutStripDotsWithoutAscii()... |
| 296 |
|
{ |
| 297 |
1 |
assertEquals("ee{&.txt", this.xwiki.clearName("\u00E9\u00EA{&.txt", false, false, getContext())); |
| 298 |
|
} |
| 299 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 300 |
1 |
public void testClearNameWithoutStripDotsWithAscii()... |
| 301 |
|
{ |
| 302 |
1 |
assertEquals("ee.txt", this.xwiki.clearName("\u00E9\u00EA{&.txt", false, true, getContext())); |
| 303 |
|
} |
| 304 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 305 |
1 |
public void testClearNameWithStripDotsWithoutAscii()... |
| 306 |
|
{ |
| 307 |
1 |
assertEquals("ee{&txt", this.xwiki.clearName("\u00E9\u00EA{&.txt", true, false, getContext())); |
| 308 |
|
} |
| 309 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 310 |
1 |
public void testClearNameWithStripDotsWithAscii()... |
| 311 |
|
{ |
| 312 |
1 |
assertEquals("eetxt", this.xwiki.clearName("\u00E9\u00EA{&.txt", true, true, getContext())); |
| 313 |
|
} |
| 314 |
|
|
| 315 |
|
|
| 316 |
|
|
| 317 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 318 |
1 |
public void testSaveDocumentSendsObservationEvents() throws Exception... |
| 319 |
|
{ |
| 320 |
1 |
Mock mockListener = mock(EventListener.class); |
| 321 |
1 |
mockListener.stubs().method("getName").will(returnValue("testlistener")); |
| 322 |
1 |
DocumentReference ref = new DocumentReference("xwikitest", "Some", "Document"); |
| 323 |
1 |
mockListener.expects(once()).method("getEvents") |
| 324 |
|
.will(returnValue(Arrays.asList(new DocumentCreatedEvent(ref), new DocumentCreatingEvent(ref)))); |
| 325 |
|
|
| 326 |
1 |
ObservationManager om = getComponentManager().getInstance(ObservationManager.class); |
| 327 |
1 |
om.addListener((EventListener) mockListener.proxy()); |
| 328 |
|
|
| 329 |
1 |
XWikiDocument document = new XWikiDocument(new DocumentReference("xwikitest", "Some", "Document")); |
| 330 |
1 |
document.setContent("the content"); |
| 331 |
|
|
| 332 |
|
|
| 333 |
1 |
mockListener.expects(once()).method("onEvent").with(isA(DocumentCreatingEvent.class), same(document), |
| 334 |
|
isA(XWikiContext.class)); |
| 335 |
1 |
mockListener.expects(once()).method("onEvent").with(isA(DocumentCreatedEvent.class), same(document), |
| 336 |
|
isA(XWikiContext.class)); |
| 337 |
|
|
| 338 |
1 |
this.xwiki.saveDocument(document, getContext()); |
| 339 |
|
} |
| 340 |
|
|
| 341 |
|
|
| 342 |
|
|
| 343 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 344 |
1 |
public void testDeleteDocumentSendsObservationEvents() throws Exception... |
| 345 |
|
{ |
| 346 |
1 |
Mock mockListener = mock(EventListener.class); |
| 347 |
1 |
mockListener.stubs().method("getName").will(returnValue("testlistener")); |
| 348 |
1 |
DocumentReference ref = new DocumentReference("xwikitest", "Another", "Document"); |
| 349 |
1 |
mockListener.expects(once()).method("getEvents") |
| 350 |
|
.will(returnValue(Arrays.asList(new DocumentDeletedEvent(ref), new DocumentDeletingEvent(ref)))); |
| 351 |
|
|
| 352 |
1 |
ObservationManager om = getComponentManager().getInstance(ObservationManager.class); |
| 353 |
1 |
om.addListener((EventListener) mockListener.proxy()); |
| 354 |
|
|
| 355 |
1 |
XWikiDocument document = new XWikiDocument(new DocumentReference("xwikitest", "Another", "Document")); |
| 356 |
1 |
document.setContent("the content"); |
| 357 |
|
|
| 358 |
|
|
| 359 |
|
|
| 360 |
1 |
this.xwiki.saveDocument(document, getContext()); |
| 361 |
|
|
| 362 |
|
|
| 363 |
1 |
mockListener.expects(once()).method("onEvent") |
| 364 |
|
.with(isA(DocumentDeletingEvent.class), isA(XWikiDocument.class), isA(XWikiContext.class)); |
| 365 |
1 |
mockListener.expects(once()).method("onEvent") |
| 366 |
|
.with(isA(DocumentDeletedEvent.class), isA(XWikiDocument.class), isA(XWikiContext.class)); |
| 367 |
|
|
| 368 |
1 |
this.xwiki.deleteDocument(document, false, getContext()); |
| 369 |
|
} |
| 370 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 371 |
1 |
public void testLanguageSelection() throws Exception... |
| 372 |
|
{ |
| 373 |
1 |
getContext().setRequest(new XWikiServletRequest(null) |
| 374 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 375 |
1 |
@SuppressWarnings("unchecked")... |
| 376 |
|
@Override |
| 377 |
|
public Enumeration getLocales() |
| 378 |
|
{ |
| 379 |
1 |
ArrayList<Locale> locales = new ArrayList<Locale>(); |
| 380 |
1 |
locales.add(new Locale("*")); |
| 381 |
1 |
locales.add(new Locale("en_US")); |
| 382 |
1 |
locales.add(new Locale("fr")); |
| 383 |
1 |
locales.add(new Locale("de")); |
| 384 |
1 |
return IteratorUtils.asEnumeration(locales.iterator()); |
| 385 |
|
} |
| 386 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 387 |
1 |
@Override... |
| 388 |
|
public String getHeader(String s) |
| 389 |
|
{ |
| 390 |
1 |
if ("language".equals(s)) { |
| 391 |
0 |
return null; |
| 392 |
|
} |
| 393 |
1 |
return "en"; |
| 394 |
|
} |
| 395 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 396 |
0 |
@Override... |
| 397 |
|
public Cookie getCookie(String cookieName) |
| 398 |
|
{ |
| 399 |
0 |
return null; |
| 400 |
|
} |
| 401 |
|
}); |
| 402 |
|
|
| 403 |
|
|
| 404 |
1 |
getConfigurationSource().setProperty("multilingual", "1"); |
| 405 |
|
|
| 406 |
1 |
assertEquals("fr", this.xwiki.getLanguagePreference(getContext())); |
| 407 |
|
} |
| 408 |
|
|
| 409 |
|
|
| 410 |
|
|
| 411 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 412 |
1 |
public void testIsMultilingualDefaultFalse() throws Exception... |
| 413 |
|
{ |
| 414 |
1 |
assertFalse(this.xwiki.isMultiLingual(getContext())); |
| 415 |
|
} |
| 416 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 417 |
1 |
public void testGetCurrentContentSyntaxId()... |
| 418 |
|
{ |
| 419 |
1 |
XWikiDocument doc1 = new XWikiDocument(); |
| 420 |
1 |
doc1.setSyntax(Syntax.CREOLE_1_0); |
| 421 |
1 |
XWikiDocument doc2 = new XWikiDocument(); |
| 422 |
1 |
doc2.setSyntax(Syntax.PLAIN_1_0); |
| 423 |
|
|
| 424 |
1 |
assertNull(this.xwiki.getCurrentContentSyntaxId(null, getContext())); |
| 425 |
1 |
assertEquals("syntaxId", this.xwiki.getCurrentContentSyntaxId("syntaxId", getContext())); |
| 426 |
|
|
| 427 |
1 |
getContext().setDoc(doc1); |
| 428 |
|
|
| 429 |
1 |
assertEquals(Syntax.CREOLE_1_0.toIdString(), this.xwiki.getCurrentContentSyntaxId(null, getContext())); |
| 430 |
|
|
| 431 |
1 |
getContext().put("sdoc", doc2); |
| 432 |
|
|
| 433 |
1 |
assertEquals(Syntax.PLAIN_1_0.toIdString(), this.xwiki.getCurrentContentSyntaxId(null, getContext())); |
| 434 |
|
} |
| 435 |
|
|
| 436 |
|
|
| 437 |
|
|
| 438 |
|
|
| 439 |
|
|
| 440 |
|
@throws |
| 441 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
| 442 |
1 |
public void testValidationKeyStorage() throws Exception... |
| 443 |
|
{ |
| 444 |
1 |
XWikiContext context = getContext(); |
| 445 |
1 |
context.setLanguage("en"); |
| 446 |
|
|
| 447 |
|
|
| 448 |
1 |
Mock request = mock(XWikiRequest.class); |
| 449 |
1 |
request.stubs().method("getParameter").with(eq("xwikiname")).will(returnValue("TestUser")); |
| 450 |
1 |
request.stubs().method("getParameter").with(eq("validkey")).will(returnValue("plaintextkey")); |
| 451 |
1 |
context.setRequest((XWikiRequest) request.proxy()); |
| 452 |
|
|
| 453 |
|
|
| 454 |
1 |
XWikiDocument testUser = new XWikiDocument(new DocumentReference("Wiki", "XWiki", "TestUser")); |
| 455 |
1 |
BaseObject userObject = (BaseObject) this.xwiki.getUserClass(context).newObject(context); |
| 456 |
1 |
testUser.addObject("XWiki.XWikiUsers", userObject); |
| 457 |
1 |
this.xwiki.saveDocument(testUser, context); |
| 458 |
|
|
| 459 |
|
|
| 460 |
1 |
BaseProperty validationKey = new StringProperty(); |
| 461 |
1 |
validationKey.setValue("plaintextkey"); |
| 462 |
1 |
userObject.safeput("validkey", validationKey); |
| 463 |
|
|
| 464 |
1 |
assertEquals(0, this.xwiki.validateUser(false, getContext())); |
| 465 |
|
|
| 466 |
|
|
| 467 |
1 |
validationKey.setValue("wrong key"); |
| 468 |
|
|
| 469 |
1 |
assertEquals(-1, this.xwiki.validateUser(false, getContext())); |
| 470 |
|
|
| 471 |
|
|
| 472 |
1 |
validationKey = ((PropertyClass) this.xwiki.getUserClass(context).get("validkey")).fromString("plaintextkey"); |
| 473 |
1 |
assertTrue(validationKey.getValue().toString().startsWith("hash:")); |
| 474 |
1 |
userObject.safeput("validkey", validationKey); |
| 475 |
|
|
| 476 |
1 |
assertEquals(0, this.xwiki.validateUser(false, getContext())); |
| 477 |
|
|
| 478 |
|
|
| 479 |
1 |
validationKey = ((PropertyClass) this.xwiki.getUserClass(context).get("validkey")).fromString("wrong key"); |
| 480 |
1 |
assertTrue(validationKey.getValue().toString().startsWith("hash:")); |
| 481 |
1 |
userObject.safeput("validkey", validationKey); |
| 482 |
|
|
| 483 |
1 |
assertEquals(-1, this.xwiki.validateUser(false, getContext())); |
| 484 |
|
} |
| 485 |
|
|
| 486 |
|
|
| 487 |
|
|
| 488 |
|
|
| 489 |
|
@throws |
| 490 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 491 |
1 |
public void testGetPrefsClass() throws Exception... |
| 492 |
|
{ |
| 493 |
1 |
Mock mockStore = registerMockComponent(XWikiStoreInterface.class); |
| 494 |
1 |
this.xwiki.setStore((XWikiStoreInterface) mockStore.proxy()); |
| 495 |
|
|
| 496 |
1 |
XWikiDocument prefsDoc = new XWikiDocument(new DocumentReference("xwiki", "XWiki", "XWikiPreferences")); |
| 497 |
1 |
final Map<DocumentReference, XWikiDocument> documents = new HashMap<DocumentReference, XWikiDocument>(); |
| 498 |
1 |
documents.put(prefsDoc.getDocumentReference(), prefsDoc); |
| 499 |
|
|
| 500 |
1 |
mockStore.expects(atLeastOnce()).method("loadXWikiDoc").with(NOT_NULL, same(getContext())) |
| 501 |
|
.will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") |
| 502 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 503 |
6 |
@Override... |
| 504 |
|
public Object invoke(Invocation invocation) throws Throwable |
| 505 |
|
{ |
| 506 |
6 |
XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0); |
| 507 |
6 |
if (!documents.containsKey(document.getDocumentReference())) { |
| 508 |
2 |
documents.put(document.getDocumentReference(), document); |
| 509 |
|
} else { |
| 510 |
4 |
document = documents.get(document.getDocumentReference()); |
| 511 |
|
} |
| 512 |
6 |
return document; |
| 513 |
|
} |
| 514 |
|
}); |
| 515 |
1 |
mockStore.expects(once()).method("saveXWikiDoc").with(same(prefsDoc), same(getContext())); |
| 516 |
|
|
| 517 |
1 |
this.xwiki.getPrefsClass(getContext()); |
| 518 |
1 |
this.xwiki.getPrefsClass(getContext()); |
| 519 |
|
} |
| 520 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 521 |
1 |
public void testGetDocumentWithEntityReference() throws Exception... |
| 522 |
|
{ |
| 523 |
1 |
Mock mockStore = registerMockComponent(XWikiStoreInterface.class); |
| 524 |
1 |
this.xwiki.setStore((XWikiStoreInterface) mockStore.proxy()); |
| 525 |
|
|
| 526 |
1 |
mockStore.expects(atLeastOnce()).method("loadXWikiDoc").with(NOT_NULL, same(getContext())) |
| 527 |
|
.will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") |
| 528 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 529 |
2 |
@Override... |
| 530 |
|
public Object invoke(Invocation invocation) throws Throwable |
| 531 |
|
{ |
| 532 |
2 |
return invocation.parameterValues.get(0); |
| 533 |
|
} |
| 534 |
|
}); |
| 535 |
|
|
| 536 |
1 |
DocumentReference documentReference = new DocumentReference("wiki", "Main", "WebHome"); |
| 537 |
|
|
| 538 |
1 |
WikiDescriptor mockWikiDescriptor = new WikiDescriptor("wiki", "wiki"); |
| 539 |
1 |
mockWikiDescriptor.setMainPageReference(documentReference); |
| 540 |
|
|
| 541 |
1 |
this.mockWikiDescriptorManager.stubs().method("getById").with(same("wiki")) |
| 542 |
|
.will(returnValue(mockWikiDescriptor)); |
| 543 |
|
|
| 544 |
1 |
assertEquals(documentReference, this.xwiki.getDocument(new WikiReference("wiki"), getContext()) |
| 545 |
|
.getDocumentReference()); |
| 546 |
|
|
| 547 |
1 |
assertEquals(documentReference, |
| 548 |
|
this.xwiki.getDocument(new ObjectReference("object", documentReference), getContext()) |
| 549 |
|
.getDocumentReference()); |
| 550 |
|
} |
| 551 |
|
|
| 552 |
|
|
| 553 |
|
|
| 554 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 555 |
1 |
public void testSkinResourcesAreAlwaysAllowed() throws XWikiException... |
| 556 |
|
{ |
| 557 |
|
|
| 558 |
1 |
XWikiDocument doc1 = |
| 559 |
|
new XWikiDocument(new DocumentReference("xwiki", Arrays.asList("resources", "icons", "xwiki"), |
| 560 |
|
"noavatar.png")); |
| 561 |
|
|
| 562 |
1 |
XWikiDocument doc2 = |
| 563 |
|
new XWikiDocument(new DocumentReference("xwiki", Arrays.asList("skins", "flamingo", "xwiki"), "style.css")); |
| 564 |
|
|
| 565 |
|
|
| 566 |
1 |
Mock mockAuthService = mock(XWikiAuthService.class); |
| 567 |
1 |
mockAuthService.expects(exactly(2)).method("checkAuth").with(same(getContext())).will(returnValue(null)); |
| 568 |
1 |
this.xwiki.setAuthService((XWikiAuthService) mockAuthService.proxy()); |
| 569 |
|
|
| 570 |
|
|
| 571 |
1 |
Mock mockRightService = mock(XWikiRightService.class); |
| 572 |
1 |
mockRightService.expects( |
| 573 |
|
never("Skin action resources inside the 'skins' and 'resources' folders" |
| 574 |
|
+ " should never be checked for rights.")).method("checkAccess"); |
| 575 |
1 |
this.xwiki.setRightService((XWikiRightService) mockRightService.proxy()); |
| 576 |
|
|
| 577 |
|
|
| 578 |
1 |
Assert.assertTrue(this.xwiki.checkAccess("skin", doc1, getContext())); |
| 579 |
1 |
Assert.assertTrue(this.xwiki.checkAccess("skin", doc2, getContext())); |
| 580 |
|
} |
| 581 |
|
} |