| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.doc; |
| 21 |
|
|
| 22 |
|
import java.io.Reader; |
| 23 |
|
import java.io.Writer; |
| 24 |
|
import java.util.ArrayList; |
| 25 |
|
import java.util.Arrays; |
| 26 |
|
import java.util.Locale; |
| 27 |
|
import java.util.Properties; |
| 28 |
|
|
| 29 |
|
import org.apache.velocity.VelocityContext; |
| 30 |
|
import org.jmock.Mock; |
| 31 |
|
import org.jmock.core.Invocation; |
| 32 |
|
import org.jmock.core.stub.CustomStub; |
| 33 |
|
import org.junit.Test; |
| 34 |
|
import org.xwiki.display.internal.DisplayConfiguration; |
| 35 |
|
import org.xwiki.model.reference.DocumentReference; |
| 36 |
|
import org.xwiki.rendering.syntax.Syntax; |
| 37 |
|
import org.xwiki.test.internal.MockConfigurationSource; |
| 38 |
|
import org.xwiki.velocity.VelocityEngine; |
| 39 |
|
import org.xwiki.velocity.VelocityFactory; |
| 40 |
|
import org.xwiki.velocity.VelocityManager; |
| 41 |
|
import org.xwiki.velocity.internal.jmx.JMXVelocityEngine; |
| 42 |
|
import org.xwiki.velocity.internal.jmx.JMXVelocityEngineMBean; |
| 43 |
|
|
| 44 |
|
import com.xpn.xwiki.XWiki; |
| 45 |
|
import com.xpn.xwiki.XWikiException; |
| 46 |
|
import com.xpn.xwiki.api.Document; |
| 47 |
|
import com.xpn.xwiki.objects.BaseObject; |
| 48 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
| 49 |
|
import com.xpn.xwiki.objects.classes.TextAreaClass; |
| 50 |
|
import com.xpn.xwiki.store.XWikiStoreInterface; |
| 51 |
|
import com.xpn.xwiki.store.XWikiVersioningStoreInterface; |
| 52 |
|
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase; |
| 53 |
|
import com.xpn.xwiki.user.api.XWikiRightService; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
@link |
| 57 |
|
|
| 58 |
|
@version |
| 59 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (182) |
Complexity: 16 |
Complexity Density: 0.1 |
|
| 60 |
|
public class XWikiDocumentRenderingTest extends AbstractBridgedXWikiComponentTestCase |
| 61 |
|
{ |
| 62 |
|
private static final String DOCWIKI = "xwiki"; |
| 63 |
|
|
| 64 |
|
private static final String DOCSPACE = "Space"; |
| 65 |
|
|
| 66 |
|
private static final String DOCNAME = "Page"; |
| 67 |
|
|
| 68 |
|
private static final String DOCFULLNAME = DOCSPACE + "." + DOCNAME; |
| 69 |
|
|
| 70 |
|
private static final String CLASSNAME = DOCFULLNAME; |
| 71 |
|
|
| 72 |
|
private XWikiDocument document; |
| 73 |
|
|
| 74 |
|
private XWikiDocument translatedDocument; |
| 75 |
|
|
| 76 |
|
private Mock mockXWiki; |
| 77 |
|
|
| 78 |
|
private Mock mockXWikiVersioningStore; |
| 79 |
|
|
| 80 |
|
private Mock mockXWikiStoreInterface; |
| 81 |
|
|
| 82 |
|
private Mock mockXWikiRightService; |
| 83 |
|
|
| 84 |
|
private Mock mockDisplayConfiguration; |
| 85 |
|
|
| 86 |
|
private BaseClass baseClass; |
| 87 |
|
|
| 88 |
|
private BaseObject baseObject; |
| 89 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (52) |
Complexity: 1 |
Complexity Density: 0.02 |
|
| 90 |
13 |
@Override... |
| 91 |
|
protected void setUp() throws Exception |
| 92 |
|
{ |
| 93 |
13 |
super.setUp(); |
| 94 |
|
|
| 95 |
|
|
| 96 |
13 |
getComponentManager().registerComponent(MockConfigurationSource.getDescriptor("xwikicfg"), |
| 97 |
|
getConfigurationSource()); |
| 98 |
|
|
| 99 |
13 |
this.document = new XWikiDocument(new DocumentReference(DOCWIKI, DOCSPACE, DOCNAME)); |
| 100 |
13 |
this.document.setSyntax(Syntax.XWIKI_2_1); |
| 101 |
13 |
this.document.setLanguage("en"); |
| 102 |
13 |
this.document.setDefaultLanguage("en"); |
| 103 |
13 |
this.document.setNew(false); |
| 104 |
|
|
| 105 |
13 |
getContext().setDoc(this.document); |
| 106 |
|
|
| 107 |
13 |
this.translatedDocument = new XWikiDocument(); |
| 108 |
13 |
this.translatedDocument.setSyntax(Syntax.XWIKI_2_1); |
| 109 |
13 |
this.translatedDocument.setLanguage("fr"); |
| 110 |
13 |
this.translatedDocument.setNew(false); |
| 111 |
|
|
| 112 |
13 |
getContext().put("isInRenderingEngine", true); |
| 113 |
|
|
| 114 |
13 |
this.mockXWiki = mock(XWiki.class); |
| 115 |
13 |
this.mockXWiki.stubs().method("Param").will(returnValue(null)); |
| 116 |
|
|
| 117 |
13 |
this.mockXWikiVersioningStore = mock(XWikiVersioningStoreInterface.class); |
| 118 |
13 |
this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(null)); |
| 119 |
|
|
| 120 |
13 |
this.mockXWikiRightService = mock(XWikiRightService.class); |
| 121 |
13 |
this.mockXWikiRightService.stubs().method("hasProgrammingRights").will(returnValue(true)); |
| 122 |
|
|
| 123 |
13 |
this.mockXWikiStoreInterface = mock(XWikiStoreInterface.class); |
| 124 |
13 |
this.mockXWikiStoreInterface.stubs().method("search").will(returnValue(new ArrayList<XWikiDocument>())); |
| 125 |
|
|
| 126 |
13 |
this.document.setStore((XWikiStoreInterface) this.mockXWikiStoreInterface.proxy()); |
| 127 |
|
|
| 128 |
13 |
this.mockXWiki.stubs().method("getVersioningStore").will(returnValue(this.mockXWikiVersioningStore.proxy())); |
| 129 |
13 |
this.mockXWiki.stubs().method("getStore").will(returnValue(this.mockXWikiStoreInterface.proxy())); |
| 130 |
13 |
this.mockXWiki.stubs().method("getRightService").will(returnValue(this.mockXWikiRightService.proxy())); |
| 131 |
13 |
this.mockXWiki.stubs().method("getDocument").will(returnValue(this.document)); |
| 132 |
13 |
this.mockXWiki.stubs().method("getLanguagePreference").will(returnValue("en")); |
| 133 |
13 |
this.mockXWiki.stubs().method("exists").will(returnValue(false)); |
| 134 |
|
|
| 135 |
13 |
this.mockXWiki.stubs().method("prepareResources"); |
| 136 |
|
|
| 137 |
13 |
this.mockXWiki.stubs().method("getSkin").will(returnValue("default")); |
| 138 |
13 |
this.mockXWiki.stubs().method("getSkinFile").will(returnValue(null)); |
| 139 |
13 |
this.mockXWiki.stubs().method("Param").with(eq("xwiki.render.velocity.macrolist")).will(returnValue("")); |
| 140 |
13 |
this.mockXWiki.stubs().method("exists").will(returnValue(false)); |
| 141 |
13 |
this.mockXWiki.stubs().method("evaluateTemplate").will(returnValue("")); |
| 142 |
|
|
| 143 |
13 |
getContext().setWiki((XWiki) this.mockXWiki.proxy()); |
| 144 |
|
|
| 145 |
13 |
this.baseClass = this.document.getXClass(); |
| 146 |
13 |
this.baseClass.addTextField("string", "String", 30); |
| 147 |
13 |
this.baseClass.addTextAreaField("area", "Area", 10, 10); |
| 148 |
13 |
this.baseClass.addTextAreaField("puretextarea", "Pure text area", 10, 10); |
| 149 |
|
|
| 150 |
13 |
((TextAreaClass) this.baseClass.getField("puretextarea")).setContentType("puretext"); |
| 151 |
13 |
this.baseClass.addPasswordField("passwd", "Password", 30); |
| 152 |
13 |
this.baseClass.addBooleanField("boolean", "Boolean", "yesno"); |
| 153 |
13 |
this.baseClass.addNumberField("int", "Int", 10, "integer"); |
| 154 |
13 |
this.baseClass.addStaticListField("stringlist", "StringList", "value1, value2"); |
| 155 |
|
|
| 156 |
13 |
this.mockXWiki.stubs().method("getXClass").will(returnValue(this.baseClass)); |
| 157 |
|
|
| 158 |
13 |
this.baseObject = this.document.newObject(CLASSNAME, getContext()); |
| 159 |
13 |
this.baseObject.setStringValue("string", "string"); |
| 160 |
13 |
this.baseObject.setLargeStringValue("area", "area"); |
| 161 |
13 |
this.baseObject.setStringValue("passwd", "passwd"); |
| 162 |
13 |
this.baseObject.setIntValue("boolean", 1); |
| 163 |
13 |
this.baseObject.setIntValue("int", 42); |
| 164 |
13 |
this.baseObject.setStringListValue("stringlist", Arrays.asList("VALUE1", "VALUE2")); |
| 165 |
|
} |
| 166 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 167 |
13 |
@Override... |
| 168 |
|
protected void registerComponents() throws Exception |
| 169 |
|
{ |
| 170 |
13 |
super.registerComponents(); |
| 171 |
|
|
| 172 |
|
|
| 173 |
13 |
this.mockDisplayConfiguration = registerMockComponent(DisplayConfiguration.class); |
| 174 |
13 |
this.mockDisplayConfiguration.stubs().method("getDocumentDisplayerHint").will(returnValue("default")); |
| 175 |
13 |
this.mockDisplayConfiguration.stubs().method("getTitleHeadingDepth").will(returnValue(2)); |
| 176 |
|
} |
| 177 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 178 |
1 |
public void testCurrentDocumentVariableIsInjectedBeforeRendering() throws XWikiException... |
| 179 |
|
{ |
| 180 |
|
|
| 181 |
1 |
this.document.setContent("{{groovy}}print(doc);{{/groovy}}"); |
| 182 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 183 |
|
|
| 184 |
1 |
assertEquals("<p>Space.Page</p>", this.document.getRenderedContent(getContext())); |
| 185 |
|
} |
| 186 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 187 |
1 |
public void testGetRenderedTitleWithTitle()... |
| 188 |
|
{ |
| 189 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 190 |
|
|
| 191 |
1 |
this.document.setTitle("title"); |
| 192 |
|
|
| 193 |
1 |
assertEquals("title", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 194 |
|
|
| 195 |
1 |
this.document.setTitle("**title**"); |
| 196 |
|
|
| 197 |
1 |
assertEquals("**title**", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 198 |
|
|
| 199 |
1 |
this.document.setTitle("<strong>ti<em>tle</strong>"); |
| 200 |
|
|
| 201 |
|
|
| 202 |
1 |
assertEquals("<strong>ti<em>tle</strong>", |
| 203 |
|
this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 204 |
1 |
assertEquals("<strong>ti<em>tle</strong>", this.document.getRenderedTitle(Syntax.PLAIN_1_0, getContext())); |
| 205 |
|
|
| 206 |
1 |
this.document.setTitle("#set($key = \"title\")$key"); |
| 207 |
|
|
| 208 |
1 |
assertEquals("title", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 209 |
|
} |
| 210 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 211 |
1 |
public void testGetRenderedTitleWithoutTitleHTML()... |
| 212 |
|
{ |
| 213 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 214 |
|
|
| 215 |
1 |
this.document.setContent( |
| 216 |
|
"content not in section\n" + "= header 1=\nheader 1 content\n" + "== header 2==\nheader 2 content"); |
| 217 |
|
|
| 218 |
1 |
getConfigurationSource().setProperty("xwiki.title.compatibility", "1"); |
| 219 |
|
|
| 220 |
1 |
assertEquals("header 1", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 221 |
|
|
| 222 |
1 |
this.document.setContent( |
| 223 |
|
"content not in section\n" + "= **header 1**=\nheader 1 content\n" + "== header 2==\nheader 2 content"); |
| 224 |
|
|
| 225 |
1 |
assertEquals("<strong>header 1</strong>", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 226 |
|
|
| 227 |
1 |
this.document.setContent( |
| 228 |
|
"content not in section\n" + "= [[Space.Page]]=\nheader 1 content\n" + "== header 2==\nheader 2 content"); |
| 229 |
|
|
| 230 |
1 |
this.mockXWiki.stubs().method("getURL").will(returnValue("/reference")); |
| 231 |
|
|
| 232 |
1 |
assertEquals("<span class=\"wikicreatelink\"><a href=\"/reference\"><span class=\"wikigeneratedlinkcontent\">" |
| 233 |
|
+ "Page" + "</span></a></span>", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 234 |
|
|
| 235 |
1 |
this.document.setContent("content not in section\n" + "= #set($var ~= \"value\")=\nheader 1 content\n" |
| 236 |
|
+ "== header 2==\nheader 2 content"); |
| 237 |
|
|
| 238 |
1 |
assertEquals("#set($var = \"value\")", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 239 |
|
|
| 240 |
1 |
this.document.setContent("content not in section\n" |
| 241 |
|
+ "= {{groovy}}print \"value\"{{/groovy}}=\nheader 1 content\n" + "== header 2==\nheader 2 content"); |
| 242 |
|
|
| 243 |
1 |
assertEquals("value", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 244 |
|
|
| 245 |
1 |
this.document.setContent("content not in section\n=== header 3==="); |
| 246 |
|
|
| 247 |
1 |
assertEquals("Page", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 248 |
|
} |
| 249 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 250 |
1 |
public void testGetRenderedTitleWithoutTitlePLAIN()... |
| 251 |
|
{ |
| 252 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 253 |
|
|
| 254 |
1 |
this.document.setContent( |
| 255 |
|
"content not in section\n" + "= **header 1**=\nheader 1 content\n" + "== header 2==\nheader 2 content"); |
| 256 |
|
|
| 257 |
1 |
assertEquals("Page", this.document.getRenderedTitle(Syntax.PLAIN_1_0, getContext())); |
| 258 |
|
|
| 259 |
1 |
getConfigurationSource().setProperty("xwiki.title.compatibility", "1"); |
| 260 |
|
|
| 261 |
1 |
this.document.setContent( |
| 262 |
|
"content not in section\n" + "= **header 1**=\nheader 1 content\n" + "== header 2==\nheader 2 content"); |
| 263 |
|
|
| 264 |
1 |
assertEquals("header 1", this.document.getRenderedTitle(Syntax.PLAIN_1_0, getContext())); |
| 265 |
|
|
| 266 |
1 |
this.document.setContent("content not in section\n" |
| 267 |
|
+ "= {{groovy}}print \"value\"{{/groovy}}=\nheader 1 content\n" + "== header 2==\nheader 2 content"); |
| 268 |
|
|
| 269 |
1 |
assertEquals("value", this.document.getRenderedTitle(Syntax.PLAIN_1_0, getContext())); |
| 270 |
|
} |
| 271 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 272 |
1 |
public void testGetRenderedTitleNoTitleAndContent()... |
| 273 |
|
{ |
| 274 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 275 |
|
|
| 276 |
1 |
assertEquals("Page", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 277 |
|
} |
| 278 |
|
|
| 279 |
|
|
| 280 |
|
|
| 281 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 282 |
1 |
public void testGetRenderedTitleRecursive()... |
| 283 |
|
{ |
| 284 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 285 |
1 |
this.document.setContent("= {{groovy}}print doc.getDisplayTitle(){{/groovy}}"); |
| 286 |
|
|
| 287 |
1 |
assertEquals("Page", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
|
| 291 |
|
|
| 292 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 293 |
1 |
public void testGetRenderedContentCleansVelocityMacroCache() throws Exception... |
| 294 |
|
{ |
| 295 |
|
|
| 296 |
|
|
| 297 |
1 |
getContext().remove("isInRenderingEngine"); |
| 298 |
|
|
| 299 |
|
|
| 300 |
|
|
| 301 |
|
|
| 302 |
1 |
this.baseObject.setLargeStringValue("area", "{{velocity}}#macro(testmacrocache)ok#end{{/velocity}}"); |
| 303 |
1 |
this.document.setContent("{{velocity}}$doc.display(\"area\")#testmacrocache{{/velocity}}"); |
| 304 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 305 |
|
|
| 306 |
|
|
| 307 |
|
|
| 308 |
1 |
VelocityManager originalVelocityManager = getComponentManager().getInstance(VelocityManager.class); |
| 309 |
1 |
VelocityContext vcontext = originalVelocityManager.getVelocityContext(); |
| 310 |
1 |
vcontext.put("doc", new Document(this.document, getContext())); |
| 311 |
|
|
| 312 |
|
|
| 313 |
1 |
Mock mockVelocityManager = registerMockComponent(VelocityManager.class); |
| 314 |
1 |
mockVelocityManager.stubs().method("getCurrentVelocityContext").will(returnValue(vcontext)); |
| 315 |
|
|
| 316 |
1 |
VelocityFactory velocityFactory = getComponentManager().getInstance(VelocityFactory.class); |
| 317 |
1 |
VelocityEngine vengine = velocityFactory.createVelocityEngine("default", new Properties()); |
| 318 |
|
|
| 319 |
|
|
| 320 |
1 |
JMXVelocityEngineMBean mbean = new JMXVelocityEngine(vengine); |
| 321 |
1 |
int cachedMacroNamespaceSize = mbean.getTemplates().values().size(); |
| 322 |
1 |
assertTrue(cachedMacroNamespaceSize > 0); |
| 323 |
|
|
| 324 |
1 |
mockVelocityManager.stubs().method("getVelocityEngine").will(returnValue(vengine)); |
| 325 |
1 |
mockVelocityManager.stubs().method("evaluate").will(new CustomStub("evaluate") |
| 326 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 327 |
2 |
@Override... |
| 328 |
|
public Object invoke(Invocation invocation) throws Throwable |
| 329 |
|
{ |
| 330 |
2 |
return vengine.evaluate(vcontext, (Writer) invocation.parameterValues.get(0), |
| 331 |
|
(String) invocation.parameterValues.get(1), (Reader) invocation.parameterValues.get(2)); |
| 332 |
|
} |
| 333 |
|
}); |
| 334 |
|
|
| 335 |
|
|
| 336 |
1 |
this.mockXWiki.stubs().method("getCurrentContentSyntaxId").with(eq("xwiki/2.0"), ANYTHING) |
| 337 |
|
.will(returnValue("xwiki/2.0")); |
| 338 |
|
|
| 339 |
|
|
| 340 |
|
|
| 341 |
1 |
assertEquals("<p>ok</p>", this.document.getRenderedContent(getContext())); |
| 342 |
|
|
| 343 |
|
|
| 344 |
|
|
| 345 |
1 |
assertEquals(cachedMacroNamespaceSize, mbean.getTemplates().values().size()); |
| 346 |
|
} |
| 347 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 348 |
1 |
@Test... |
| 349 |
|
public void testGetRenderedTitleWhenMatchingTitleHeaderDepth() |
| 350 |
|
{ |
| 351 |
1 |
this.document.setContent("=== level3"); |
| 352 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 353 |
|
|
| 354 |
1 |
getConfigurationSource().setProperty("xwiki.title.compatibility", "1"); |
| 355 |
|
|
| 356 |
|
|
| 357 |
1 |
this.mockDisplayConfiguration.stubs().method("getTitleHeadingDepth").will(returnValue(3)); |
| 358 |
|
|
| 359 |
1 |
assertEquals("level3", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 360 |
|
} |
| 361 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 362 |
1 |
@Test... |
| 363 |
|
public void testGetRenderedTitleWhenNotMatchingTitleHeaderDepth() |
| 364 |
|
{ |
| 365 |
1 |
this.document.setContent("=== level3"); |
| 366 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 367 |
|
|
| 368 |
1 |
assertEquals("Page", this.document.getRenderedTitle(Syntax.XHTML_1_0, getContext())); |
| 369 |
|
} |
| 370 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 371 |
1 |
public void testGetRenderedContent() throws XWikiException... |
| 372 |
|
{ |
| 373 |
1 |
this.document.setContent("**bold**"); |
| 374 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_0); |
| 375 |
|
|
| 376 |
1 |
assertEquals("<p><strong>bold</strong></p>", this.document.getRenderedContent(getContext())); |
| 377 |
|
|
| 378 |
1 |
this.translatedDocument = new XWikiDocument(this.document.getDocumentReference(), Locale.FRENCH); |
| 379 |
1 |
this.translatedDocument.setContent("//italic//"); |
| 380 |
1 |
this.translatedDocument.setSyntax(Syntax.XWIKI_1_0); |
| 381 |
1 |
this.translatedDocument.setNew(false); |
| 382 |
|
|
| 383 |
1 |
this.mockXWiki.stubs().method("getLanguagePreference").will(returnValue(Locale.FRENCH.toString())); |
| 384 |
1 |
this.mockXWiki.stubs().method("getDocument").with(eq( |
| 385 |
|
new DocumentReference(this.translatedDocument.getDocumentReference(), this.translatedDocument.getLocale())), |
| 386 |
|
ANYTHING).will(returnValue(this.translatedDocument)); |
| 387 |
|
|
| 388 |
1 |
assertEquals("<p><em>italic</em></p>", this.document.getRenderedContent(getContext())); |
| 389 |
|
} |
| 390 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 391 |
1 |
public void testGetRenderedContentRights() throws XWikiException... |
| 392 |
|
{ |
| 393 |
1 |
getContext().remove("sdoc"); |
| 394 |
|
|
| 395 |
1 |
this.document.setContent("{{velocity}}$xcontext.sdoc{{/velocity}}"); |
| 396 |
1 |
this.document.setSyntax(Syntax.XWIKI_2_1); |
| 397 |
|
|
| 398 |
1 |
assertEquals("<p>Space.Page</p>", this.document.getRenderedContent(getContext())); |
| 399 |
|
} |
| 400 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 401 |
1 |
public void testGetRenderedContentTextWithSourceSyntax()... |
| 402 |
|
{ |
| 403 |
1 |
this.document.setSyntax(Syntax.XWIKI_1_0); |
| 404 |
|
|
| 405 |
1 |
assertEquals("<p><strong>bold</strong></p>", |
| 406 |
|
this.document.getRenderedContent("**bold**", "xwiki/2.0", getContext())); |
| 407 |
|
} |
| 408 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
| 409 |
1 |
public void testGetRenderedContentTextRights() throws XWikiException... |
| 410 |
|
{ |
| 411 |
1 |
XWikiDocument otherDocument = new XWikiDocument(new DocumentReference("otherwiki", "otherspace", "otherpage")); |
| 412 |
1 |
otherDocument.setContentAuthorReference(new DocumentReference("otherwiki", "XWiki", "othercontentauthor")); |
| 413 |
1 |
XWikiDocument sdoc = new XWikiDocument(new DocumentReference("callerwiki", "callerspace", "callerpage")); |
| 414 |
1 |
sdoc.setContentAuthorReference(new DocumentReference("callerwiki", "XWiki", "calleruser")); |
| 415 |
1 |
Document apiDocument = this.document.newDocument(getContext()); |
| 416 |
|
|
| 417 |
1 |
getContext().setDoc(null); |
| 418 |
|
|
| 419 |
1 |
String content = |
| 420 |
|
"{{velocity}}" + "$xcontext.sdoc.contentAuthorReference $xcontext.doc $xcontext.doc.contentAuthorReference" |
| 421 |
|
+ "{{/velocity}}"; |
| 422 |
|
|
| 423 |
1 |
this.document.setContentAuthorReference(new DocumentReference("authorwiki", "XWiki", "contentauthor")); |
| 424 |
|
|
| 425 |
1 |
assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", |
| 426 |
|
this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), getContext())); |
| 427 |
|
|
| 428 |
1 |
assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", |
| 429 |
|
apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString())); |
| 430 |
|
|
| 431 |
1 |
assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", |
| 432 |
|
apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), Syntax.XHTML_1_0.toIdString())); |
| 433 |
|
|
| 434 |
1 |
assertEquals("<p>otherwiki:XWiki.othercontentauthor Space.Page authorwiki:XWiki.contentauthor</p>", |
| 435 |
|
this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, otherDocument, |
| 436 |
|
getContext())); |
| 437 |
|
|
| 438 |
1 |
getContext().setDoc(otherDocument); |
| 439 |
|
|
| 440 |
1 |
assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", |
| 441 |
|
this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), getContext())); |
| 442 |
|
|
| 443 |
1 |
assertEquals("<p>otherwiki:XWiki.othercontentauthor Space.Page authorwiki:XWiki.contentauthor</p>", |
| 444 |
|
apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString())); |
| 445 |
|
|
| 446 |
1 |
assertEquals("<p>otherwiki:XWiki.othercontentauthor Space.Page authorwiki:XWiki.contentauthor</p>", |
| 447 |
|
apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), Syntax.XHTML_1_0.toIdString())); |
| 448 |
|
|
| 449 |
1 |
getContext().put("sdoc", sdoc); |
| 450 |
1 |
getContext().setDoc(this.document); |
| 451 |
|
|
| 452 |
1 |
assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", |
| 453 |
|
this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), getContext())); |
| 454 |
|
|
| 455 |
1 |
assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", |
| 456 |
|
apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString())); |
| 457 |
|
|
| 458 |
1 |
assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", |
| 459 |
|
apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), Syntax.XHTML_1_0.toIdString())); |
| 460 |
|
|
| 461 |
1 |
getContext().setDoc(otherDocument); |
| 462 |
|
|
| 463 |
1 |
assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", |
| 464 |
|
this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), getContext())); |
| 465 |
|
|
| 466 |
1 |
assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", |
| 467 |
|
apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString())); |
| 468 |
|
|
| 469 |
1 |
assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", |
| 470 |
|
apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), Syntax.XHTML_1_0.toIdString())); |
| 471 |
|
|
| 472 |
|
} |
| 473 |
|
} |