| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.api; |
| 21 |
|
|
| 22 |
|
import java.util.Locale; |
| 23 |
|
|
| 24 |
|
import org.apache.velocity.VelocityContext; |
| 25 |
|
import org.hamcrest.Description; |
| 26 |
|
import org.hamcrest.Factory; |
| 27 |
|
import org.hamcrest.Matcher; |
| 28 |
|
import org.hamcrest.TypeSafeMatcher; |
| 29 |
|
import org.jmock.Expectations; |
| 30 |
|
import org.jmock.lib.legacy.ClassImposteriser; |
| 31 |
|
import org.junit.Assert; |
| 32 |
|
import org.junit.Before; |
| 33 |
|
import org.junit.Test; |
| 34 |
|
import org.xwiki.context.Execution; |
| 35 |
|
import org.xwiki.model.reference.DocumentReference; |
| 36 |
|
import org.xwiki.rendering.syntax.Syntax; |
| 37 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
| 38 |
|
import org.xwiki.velocity.VelocityManager; |
| 39 |
|
|
| 40 |
|
import com.xpn.xwiki.CoreConfiguration; |
| 41 |
|
import com.xpn.xwiki.XWikiContext; |
| 42 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 43 |
|
import com.xpn.xwiki.objects.BaseObject; |
| 44 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
| 45 |
|
import com.xpn.xwiki.web.Utils; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@link |
| 49 |
|
|
| 50 |
|
@version |
| 51 |
|
@since |
| 52 |
|
|
| |
|
| 95.3% |
Uncovered Elements: 2 (43) |
Complexity: 4 |
Complexity Density: 0.1 |
|
| 53 |
|
public class ContextTest extends AbstractComponentTestCase |
| 54 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 1 |
|
| 55 |
|
public static class XWikiDocumentMatcher extends TypeSafeMatcher<XWikiDocument> |
| 56 |
|
{ |
| 57 |
|
private DocumentReference documentReference; |
| 58 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 59 |
0 |
public XWikiDocumentMatcher(DocumentReference documentReference)... |
| 60 |
|
{ |
| 61 |
0 |
this.documentReference = documentReference; |
| 62 |
|
} |
| 63 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
0 |
@Override... |
| 65 |
|
protected boolean matchesSafely(XWikiDocument document) |
| 66 |
|
{ |
| 67 |
0 |
return documentReference.equals(document.getDocumentReference()); |
| 68 |
|
} |
| 69 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
0 |
@Override... |
| 71 |
|
public void describeTo(Description description) |
| 72 |
|
{ |
| 73 |
0 |
description.appendText("a document with a reference equal to [") |
| 74 |
|
.appendValue(this.documentReference) |
| 75 |
|
.appendText("]"); |
| 76 |
|
} |
| 77 |
|
} |
| 78 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 79 |
0 |
@Factory... |
| 80 |
|
public static Matcher<XWikiDocument> anXWikiDocumentWithReference(DocumentReference documentReference) |
| 81 |
|
{ |
| 82 |
0 |
return new XWikiDocumentMatcher(documentReference); |
| 83 |
|
} |
| 84 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 85 |
1 |
@Before... |
| 86 |
|
public void configure() throws Exception |
| 87 |
|
{ |
| 88 |
1 |
getMockery().setImposteriser(ClassImposteriser.INSTANCE); |
| 89 |
1 |
Utils.setComponentManager(getComponentManager()); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
@see |
| 96 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 97 |
1 |
@Test... |
| 98 |
|
public void setDisplayMode() throws Exception |
| 99 |
|
{ |
| 100 |
|
|
| 101 |
1 |
final XWikiContext xcontext = new XWikiContext(); |
| 102 |
1 |
xcontext.setMainXWiki("testwiki"); |
| 103 |
1 |
xcontext.setWikiId("testwiki"); |
| 104 |
|
|
| 105 |
1 |
final com.xpn.xwiki.XWiki xwiki = getMockery().mock(com.xpn.xwiki.XWiki.class); |
| 106 |
1 |
xcontext.setWiki(xwiki); |
| 107 |
|
|
| 108 |
1 |
final CoreConfiguration coreConfiguration = registerMockComponent(CoreConfiguration.class); |
| 109 |
1 |
final VelocityManager velocityManager = registerMockComponent(VelocityManager.class); |
| 110 |
|
|
| 111 |
1 |
final DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); |
| 112 |
1 |
final XWikiDocument document = new XWikiDocument(documentReference); |
| 113 |
1 |
final BaseClass baseClass = document.getXClass(); |
| 114 |
|
|
| 115 |
1 |
getMockery().checking(new Expectations() |
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
|
| 116 |
1 |
{{... |
| 117 |
1 |
allowing(xwiki).getCurrentContentSyntaxId("xwiki/2.1", xcontext); |
| 118 |
1 |
will(returnValue("xwiki/2.1")); |
| 119 |
1 |
allowing(coreConfiguration).getDefaultDocumentSyntax(); |
| 120 |
1 |
will(returnValue(Syntax.XWIKI_2_1)); |
| 121 |
1 |
allowing(velocityManager).getVelocityContext(); |
| 122 |
1 |
will(returnValue(new VelocityContext())); |
| 123 |
1 |
allowing(xwiki).getLanguagePreference(xcontext); |
| 124 |
1 |
will(returnValue("en")); |
| 125 |
|
|
| 126 |
1 |
allowing(xwiki).getDocument(with(equal(new DocumentReference(documentReference, Locale.ENGLISH))), with(same(xcontext))); |
| 127 |
1 |
will(returnValue(document)); |
| 128 |
1 |
allowing(xwiki).getXClass(documentReference, xcontext); |
| 129 |
1 |
will(returnValue(baseClass)); |
| 130 |
|
|
| 131 |
1 |
allowing(xwiki).exists(new DocumentReference("testwiki", "XWiki", "StringDisplayer"), xcontext); |
| 132 |
1 |
will(returnValue(false)); |
| 133 |
1 |
allowing(xwiki).evaluateTemplate("displayer_string.vm", xcontext); |
| 134 |
1 |
will(returnValue("")); |
| 135 |
|
}}); |
| 136 |
|
|
| 137 |
1 |
baseClass.addTextField("prop", "prop", 5); |
| 138 |
1 |
BaseObject obj = (BaseObject) document.getXClass().newObject(xcontext); |
| 139 |
1 |
obj.setStringValue("prop", "value"); |
| 140 |
1 |
document.addXObject(obj); |
| 141 |
|
|
| 142 |
|
|
| 143 |
1 |
Execution execution = getComponentManager().getInstance(Execution.class); |
| 144 |
1 |
execution.getContext().setProperty("xwikicontext", xcontext); |
| 145 |
|
|
| 146 |
1 |
Context context = new Context(xcontext); |
| 147 |
1 |
context.setDisplayMode("edit"); |
| 148 |
|
|
| 149 |
|
|
| 150 |
1 |
Assert.assertEquals("<input size='5' id='space.page_0_prop' value='value' name='space.page_0_prop' " |
| 151 |
|
+ "type='text'/>", document.display("prop", xcontext)); |
| 152 |
|
} |
| 153 |
|
} |