1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.ui.appwithinminutes

File DocumentFieldsTest.java

 

Code metrics

0
44
1
1
127
74
1
0.02
44
1
1

Classes

Class Line # Actions
DocumentFieldsTest 49 44 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 org.xwiki.test.ui.appwithinminutes;
21   
22    import java.util.Arrays;
23   
24    import org.apache.commons.lang.RandomStringUtils;
25    import org.junit.Assert;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage;
29    import org.xwiki.appwithinminutes.test.po.ApplicationCreatePage;
30    import org.xwiki.appwithinminutes.test.po.ApplicationHomeEditPage;
31    import org.xwiki.appwithinminutes.test.po.ApplicationHomePage;
32    import org.xwiki.appwithinminutes.test.po.ClassFieldEditPane;
33    import org.xwiki.appwithinminutes.test.po.EntryEditPage;
34    import org.xwiki.appwithinminutes.test.po.EntryNamePane;
35    import org.xwiki.model.reference.LocalDocumentReference;
36    import org.xwiki.test.ui.AbstractTest;
37    import org.xwiki.test.ui.AdminAuthenticationRule;
38    import org.xwiki.test.ui.po.LiveTableElement;
39    import org.xwiki.test.ui.po.ViewPage;
40    import org.xwiki.test.ui.po.editor.WikiEditPage;
41    import org.xwiki.test.ui.po.editor.wysiwyg.RichTextAreaElement;
42   
43    /**
44    * Tests the special document fields available in the class editor, such as Title and Content.
45    *
46    * @version $Id: 5208eb0a94d720a2febe8e166f40eb53d33d40de $
47    * @since 4.5RC1
48    */
 
49    public class DocumentFieldsTest extends AbstractTest
50    {
51    @Rule
52    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
53   
 
54  1 toggle @Test
55    public void titleAndContent()
56    {
57    // Create a new application.
58  1 String appName = RandomStringUtils.randomAlphabetic(6);
59  1 ApplicationCreatePage appCreatePage = ApplicationCreatePage.gotoPage();
60  1 appCreatePage.setApplicationName(appName);
61  1 appCreatePage.waitForApplicationNamePreview();
62  1 ApplicationClassEditPage classEditPage = appCreatePage.clickNextStep();
63   
64    // Add a standard field.
65  1 ClassFieldEditPane numberField = classEditPage.addField("Number");
66   
67    // Add the Title and Content fields.
68  1 ClassFieldEditPane titleField = classEditPage.addField("Title");
69  1 ClassFieldEditPane contentField = classEditPage.addField("Content");
70   
71    // Change the default field pretty names.
72    // See XWIKI-9154: The application live table uses the standard 'Page title' heading instead of the pretty name
73    // set for the Title field
74  1 titleField.setPrettyName("My Title");
75  1 contentField.setPrettyName("My Content");
76   
77    // Set the default values that will be saved in the template.
78  1 numberField.setDefaultValue("13");
79  1 String defaultTitle = "Enter title here";
80  1 titleField.setDefaultValue(defaultTitle);
81  1 String defaultContent = "Enter content here";
82  1 contentField.setDefaultValue(defaultContent);
83   
84    // Add live table columns for Title and Content.
85  1 ApplicationHomeEditPage homeEditPage = classEditPage.clickNextStep().clickNextStep().waitUntilPageIsLoaded();
86  1 homeEditPage.addLiveTableColumn("My Title");
87  1 homeEditPage.addLiveTableColumn("My Content");
88   
89    // Add an application entry.
90  1 EntryNamePane entryNamePane = homeEditPage.clickFinish().clickAddNewEntry();
91  1 entryNamePane.setName("Test");
92  1 EntryEditPage entryEditPage = entryNamePane.clickAdd();
93  1 RichTextAreaElement contentTextArea = entryEditPage.getContentEditor().waitToLoad().getRichTextArea();
94  1 Assert.assertEquals("13", entryEditPage.getValue("number1"));
95    // The page name is used as the default value for the title field.
96  1 Assert.assertEquals("Test", entryEditPage.getDocumentTitle());
97  1 Assert.assertEquals("Test", entryEditPage.getTitle());
98  1 entryEditPage.setTitle("Foo");
99  1 Assert.assertEquals(defaultContent, contentTextArea.getText());
100  1 contentTextArea.setContent("Bar");
101   
102    // Check that the title and the content of the entry have been updated.
103  1 ViewPage entryViewPage = entryEditPage.clickSaveAndView();
104  1 Assert.assertEquals("Foo", entryViewPage.getDocumentTitle());
105  1 Assert.assertTrue(entryViewPage.getContent().contains("Bar"));
106  1 entryViewPage.clickBreadcrumbLink(appName);
107   
108    // Check the entries live table.
109  1 LiveTableElement liveTable = new ApplicationHomePage().getEntriesLiveTable();
110  1 liveTable.waitUntilReady();
111  1 Assert.assertEquals(1, liveTable.getRowCount());
112  1 Assert.assertTrue(liveTable.hasRow("My Title", "Foo"));
113  1 Assert.assertTrue(liveTable.hasRow("My Content", "Bar"));
114   
115    // Check that the title and the content of the class have not been changed.
116  1 getUtil().gotoPage(new LocalDocumentReference(Arrays.asList(appName, "Code"), appName + "Class"), "edit",
117    "editor=wiki");
118  1 WikiEditPage editPage = new WikiEditPage();
119  1 Assert.assertEquals(appName + " Class", editPage.getTitle());
120  1 Assert.assertEquals("", editPage.getContent());
121   
122    // Now edit the class and check if the default values for title and content are taken from the template.
123  1 editPage.editInline();
124  1 Assert.assertEquals(defaultTitle, new ClassFieldEditPane("title1").getDefaultValue());
125  1 Assert.assertEquals(defaultContent, new ClassFieldEditPane("content1").getDefaultValue());
126    }
127    }