Skip to content
Snippets Groups Projects
Commit 09e078e2 authored by Marius Dumitru Florea's avatar Marius Dumitru Florea
Browse files

XWIKI-19297: You can set but you cannot get the current display mode

(cherry picked from commit 15663c00)
parent 4958f7cd
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,11 @@
*/
public class Context extends Api
{
/**
* The key used to store the display mode on the context.
*/
private static final String DISPLAY_MODE = "display";
/**
* The Constructor.
*
......@@ -587,7 +592,22 @@ public List<String> getDisplayedFields()
*/
public void setDisplayMode(String mode)
{
getXWikiContext().put("display", mode);
getXWikiContext().put(DISPLAY_MODE, mode);
}
/**
* Returns the default field display mode, when using {@link Document#display(String)} or
* {@link Document#display(String, Object)}.
*
* @return the display mode, one of "view", "edit", "hidden", "search" or "rendered"
* @since 12.10.12
* @since 13.4.7
* @since 13.10.3
* @since 14.0-rc-1
*/
public String getDisplayMode()
{
return (String) getXWikiContext().get(DISPLAY_MODE);
}
/**
......
......@@ -19,8 +19,7 @@
*/
package com.xpn.xwiki.api;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.test.annotation.AllComponents;
......@@ -28,10 +27,12 @@
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;
import com.xpn.xwiki.objects.classes.BaseClass;
import com.xpn.xwiki.test.MockitoOldcoreRule;
import com.xpn.xwiki.test.MockitoOldcore;
import com.xpn.xwiki.test.junit5.mockito.InjectMockitoOldcore;
import com.xpn.xwiki.test.junit5.mockito.OldcoreTest;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doReturn;
/**
* Unit tests for {@link Context}.
......@@ -39,11 +40,12 @@
* @version $Id$
* @since 4.4RC1
*/
@OldcoreTest
@AllComponents
public class ContextTest
class ContextTest
{
@Rule
public MockitoOldcoreRule oldcoreRule = new MockitoOldcoreRule();
@InjectMockitoOldcore
private MockitoOldcore oldCore;
/**
* Tests that pages can override the default property display mode using {@code $xcontext.setDisplayMode}.
......@@ -51,16 +53,16 @@ public class ContextTest
* @see "XWIKI-2436"
*/
@Test
public void setDisplayMode() throws Exception
void setDisplayMode() throws Exception
{
XWikiContext xcontext = this.oldcoreRule.getXWikiContext();
XWikiContext xcontext = this.oldCore.getXWikiContext();
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
XWikiDocument document = new XWikiDocument(documentReference);
BaseClass baseClass = document.getXClass();
doReturn("xwiki/2.1").when(this.oldcoreRule.getSpyXWiki()).getCurrentContentSyntaxId("xwiki/2.1", xcontext);
doReturn(baseClass).when(this.oldcoreRule.getSpyXWiki()).getXClass(documentReference, xcontext);
doReturn("xwiki/2.1").when(this.oldCore.getSpyXWiki()).getCurrentContentSyntaxId("xwiki/2.1", xcontext);
doReturn(baseClass).when(this.oldCore.getSpyXWiki()).getXClass(documentReference, xcontext);
baseClass.addTextField("prop", "prop", 5);
BaseObject obj = (BaseObject) document.getXClass().newObject(xcontext);
......@@ -71,7 +73,9 @@ public void setDisplayMode() throws Exception
context.setDisplayMode("edit");
// We verify that the result contains a form input
assertEquals("<input size='5' id='space.page_0_prop' value='value' name='space.page_0_prop' "
+ "type='text'/>", document.display("prop", xcontext));
assertEquals("<input size='5' id='space.page_0_prop' value='value' name='space.page_0_prop' " + "type='text'/>",
document.display("prop", xcontext));
assertEquals("edit", context.getDisplayMode());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment