2323
2424import org .apache .commons .lang3 .RandomStringUtils ;
2525import org .junit .jupiter .api .BeforeAll ;
26+ import org .junit .jupiter .api .Order ;
2627import org .junit .jupiter .api .Test ;
2728import org .xwiki .appwithinminutes .test .po .ApplicationClassEditPage ;
2829import org .xwiki .appwithinminutes .test .po .ApplicationCreatePage ;
5152 * @since 13.10RC1
5253 */
5354@ UITest (properties = {
54- // Exclude the AppWithinMinutes.ClassEditSheet and AppWithinMinutes.DynamicMessageTool from the PR checker since
55+ // Exclude the AppWithinMinutes.ClassEditSheet and AppWithinMinutes.DynamicMessageTool from the PR checker since
5556 // they use the groovy macro which requires PR rights.
5657 // TODO: Should be removed once XWIKI-20529 is closed.
5758 // Exclude AppWithinMinutes.LiveTableEditSheet because it calls com.xpn.xwiki.api.Document.saveWithProgrammingRights
58- "xwikiPropertiesAdditionalProperties=test.prchecker.excludePattern=.*:AppWithinMinutes\\ .(ClassEditSheet|DynamicMessageTool|LiveTableEditSheet)"
59- })
59+ "xwikiPropertiesAdditionalProperties=test.prchecker.excludePattern=.*:AppWithinMinutes\\ .(ClassEditSheet|DynamicMessageTool|LiveTableEditSheet)" })
6060class DocumentFieldsIT
6161{
62+ private String appName = RandomStringUtils .randomAlphabetic (6 );
63+
6264 @ BeforeAll
6365 static void beforeAll (TestUtils setup )
6466 {
@@ -73,14 +75,12 @@ static void beforeAll(TestUtils setup)
7375 }
7476
7577 @ Test
78+ @ Order (1 )
7679 void titleAndContent (TestUtils setup )
7780 {
78- setup .loginAsAdmin ();
79-
8081 // Create a new application.
81- String appName = RandomStringUtils .randomAlphabetic (6 );
8282 ApplicationCreatePage appCreatePage = ApplicationCreatePage .gotoPage ();
83- appCreatePage .setApplicationName (appName );
83+ appCreatePage .setApplicationName (this . appName );
8484 ApplicationClassEditPage classEditPage = appCreatePage .clickNextStep ();
8585
8686 // Add a standard field.
@@ -126,30 +126,53 @@ void titleAndContent(TestUtils setup)
126126 assertTrue (entryViewPage .getContent ().contains ("Bar" ));
127127
128128 // Verify that we can edit the document fields in-place.
129- String propertyReference = String .format ("%s.Code.%1$sClass[0].title1" , appName );
129+ String propertyReference = String .format ("%s.Code.%1$sClass[0].title1" , this . appName );
130130 EditablePropertyPane <String > titleProperty = new EditablePropertyPane <>(propertyReference );
131131 assertEquals ("Foo" , titleProperty .clickEdit ().getValue ());
132132 titleProperty .setValue ("Book" ).clickSave ();
133133 assertEquals ("Book" , titleProperty .getDisplayValue ());
134134
135135 // Check the entries live table.
136- entryViewPage .clickBreadcrumbLink (appName );
136+ entryViewPage .clickBreadcrumbLink (this . appName );
137137 LiveTableElement liveTable = new ApplicationHomePage ().getEntriesLiveTable ();
138138 liveTable .waitUntilReady ();
139139 assertEquals (1 , liveTable .getRowCount ());
140140 assertTrue (liveTable .hasRow ("My Title" , "Book" ));
141141 assertTrue (liveTable .hasRow ("My Content" , "Bar" ));
142142
143143 // Check that the title and the content of the class have not been changed.
144- setup .gotoPage (new LocalDocumentReference (Arrays .asList (appName , "Code" ), appName + "Class" ), "edit" ,
144+ setup .gotoPage (new LocalDocumentReference (Arrays .asList (this . appName , "Code" ), this . appName + "Class" ), "edit" ,
145145 "editor=wiki" );
146146 WikiEditPage editPage = new WikiEditPage ();
147- assertEquals (appName + " Class" , editPage .getTitle ());
147+ assertEquals (this . appName + " Class" , editPage .getTitle ());
148148 assertEquals ("" , editPage .getContent ());
149149
150150 // Now edit the class and check if the default values for title and content are taken from the template.
151151 editPage .edit ();
152152 assertEquals (defaultTitle , new ClassFieldEditPane ("title1" ).getDefaultValue ());
153153 assertEquals (defaultContent , new ClassFieldEditPane ("content1" ).getDefaultValue ());
154154 }
155+
156+ @ Test
157+ @ Order (2 )
158+ void contentFromSimpleUser (TestUtils setup )
159+ {
160+ // Create an application entry with a simple user that doesn't have script rights.
161+ setup .createUserAndLogin ("Alice" , "pass" );
162+
163+ ApplicationHomePage appHomePage = ApplicationHomePage .gotoPage (this .appName );
164+ appHomePage .getEntriesLiveTable ().waitUntilReady ();
165+
166+ EntryNamePane entryNamePage = appHomePage .clickAddNewEntry ();
167+ entryNamePage .setName ("ByAlice" );
168+
169+ EntryEditPage entryEditPage = entryNamePage .clickAdd ();
170+ entryEditPage .setTitle ("Title by $services.localization.render('Alice')" );
171+ entryEditPage .setContent ("Content by {{velocity}}$services.localization.render('Alice'){{/velocity}}" );
172+
173+ ViewPage entryViewPage = entryEditPage .clickSaveAndView ();
174+ assertEquals ("Title by $services.localization.render('Alice')" , entryViewPage .getDocumentTitle ());
175+ assertTrue (entryViewPage .getContent ().contains ("Content by" ));
176+ assertTrue (entryViewPage .getContent ().contains ("The execution of the [velocity] script macro is not allowed" ));
177+ }
155178}
0 commit comments