1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.api

File ContextTest.java

 

Code metrics

0
13
1
1
77
36
1
0.08
13
1
1

Classes

Class Line # Actions
ContextTest 43 13 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.api;
21   
22    import org.junit.Rule;
23    import org.junit.Test;
24    import org.xwiki.model.reference.DocumentReference;
25    import org.xwiki.test.annotation.AllComponents;
26   
27    import com.xpn.xwiki.XWikiContext;
28    import com.xpn.xwiki.doc.XWikiDocument;
29    import com.xpn.xwiki.objects.BaseObject;
30    import com.xpn.xwiki.objects.classes.BaseClass;
31    import com.xpn.xwiki.test.MockitoOldcoreRule;
32   
33    import static org.junit.Assert.assertEquals;
34    import static org.mockito.Mockito.*;
35   
36    /**
37    * Unit tests for {@link Context}.
38    *
39    * @version $Id: 069516d1d6167fe508efc0ebaa064857905eff08 $
40    * @since 4.4RC1
41    */
42    @AllComponents
 
43    public class ContextTest
44    {
45    @Rule
46    public MockitoOldcoreRule oldcoreRule = new MockitoOldcoreRule();
47   
48    /**
49    * Tests that pages can override the default property display mode using {@code $xcontext.setDisplayMode}.
50    *
51    * @see "XWIKI-2436"
52    */
 
53  1 toggle @Test
54    public void setDisplayMode() throws Exception
55    {
56  1 XWikiContext xcontext = this.oldcoreRule.getXWikiContext();
57   
58  1 DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
59  1 XWikiDocument document = new XWikiDocument(documentReference);
60  1 BaseClass baseClass = document.getXClass();
61   
62  1 doReturn("xwiki/2.1").when(this.oldcoreRule.getSpyXWiki()).getCurrentContentSyntaxId("xwiki/2.1", xcontext);
63  1 doReturn(baseClass).when(this.oldcoreRule.getSpyXWiki()).getXClass(documentReference, xcontext);
64   
65  1 baseClass.addTextField("prop", "prop", 5);
66  1 BaseObject obj = (BaseObject) document.getXClass().newObject(xcontext);
67  1 obj.setStringValue("prop", "value");
68  1 document.addXObject(obj);
69   
70  1 Context context = new Context(xcontext);
71  1 context.setDisplayMode("edit");
72   
73    // We verify that the result contains a form input
74  1 assertEquals("<input size='5' id='space.page_0_prop' value='value' name='space.page_0_prop' "
75    + "type='text'/>", document.display("prop", xcontext));
76    }
77    }