Skip to content

Commit aca42c5

Browse files
mfloreaclaude
andcommitted
XWIKI-24803: Upgrade to Syntax highlighting 4.11.2
XWIKI-24802: Syntax highlighting doesn't work anymore * Upgrade to Syntax Highlighting 4.11.2, which depends on the repackaged CodeMirror WebJar (org.webjars.npm:codemirror:5.65.21-xwiki-2) * Add a functional test checking that the wiki editor content is highlighted, that the highlighted editor is editable and that its content is saved back Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 9c9d970 commit aca42c5

3 files changed

Lines changed: 113 additions & 1 deletion

File tree

  • xwiki-platform-distribution/xwiki-platform-distribution-flavor

xwiki-platform-distribution/xwiki-platform-distribution-flavor/xwiki-platform-distribution-flavor-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
<dependency>
261261
<groupId>org.xwiki.contrib.editortool</groupId>
262262
<artifactId>editor-tool-highlighting-ui</artifactId>
263-
<version>4.11.1</version>
263+
<version>4.11.2</version>
264264
<type>xar</type>
265265
<optional>true</optional>
266266
</dependency>

xwiki-platform-distribution/xwiki-platform-distribution-flavor/xwiki-platform-distribution-flavor-test/xwiki-platform-distribution-flavor-test-docker/src/test/it/org/xwiki/test/ui/docker/AllIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ public class AllIT
3535
class NestedNameStrategiesDefaultConfigurationIT extends NameStrategiesDefaultConfigurationIT
3636
{
3737
}
38+
39+
@Nested
40+
class NestedSyntaxHighlightingIT extends SyntaxHighlightingIT
41+
{
42+
}
3843
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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.docker;
21+
22+
import java.util.List;
23+
import java.util.stream.Collectors;
24+
25+
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.Test;
27+
import org.openqa.selenium.By;
28+
import org.openqa.selenium.Keys;
29+
import org.openqa.selenium.WebElement;
30+
import org.xwiki.rest.model.jaxb.Page;
31+
import org.xwiki.test.docker.junit5.TestReference;
32+
import org.xwiki.test.docker.junit5.UITest;
33+
import org.xwiki.test.ui.TestUtils;
34+
import org.xwiki.test.ui.XWikiWebDriver;
35+
import org.xwiki.test.ui.po.ViewPage;
36+
import org.xwiki.test.ui.po.editor.WikiEditPage;
37+
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
39+
40+
/**
41+
* Validate the syntax highlighting of the wiki editor, provided by the Syntax Highlighting application shipped with
42+
* the standard flavor. The application wraps the content text area in a CodeMirror editor whose resources are loaded
43+
* from the CodeMirror WebJar, so this test also covers the packaging of that WebJar and the way its URL is computed.
44+
*
45+
* @version $Id$
46+
* @since 18.8.0RC1
47+
*/
48+
// standardFlavor = true because the Syntax Highlighting application is a contributed extension that reaches the users
49+
// only through the standard flavor, which installs it along with the CodeMirror WebJar it depends on.
50+
@UITest(standardFlavor = true)
51+
class SyntaxHighlightingIT
52+
{
53+
private static final String CONTENT = "{{html}}test{{/html}}";
54+
55+
private static final String ADDED_CONTENT = "{{html}}new{{/html}}";
56+
57+
// The Syntax Highlighting application doesn't provide page objects for its CodeMirror based editor, so we have to
58+
// locate its DOM here. The application should provide them instead, so that the tests don't have to depend on the
59+
// internal markup of CodeMirror. Note that CodeMirror hides the content text area and inserts its own widget
60+
// right after it.
61+
private static final By LINE = By.cssSelector("#content ~ .CodeMirror .CodeMirror-code pre.CodeMirror-line");
62+
63+
// The XWiki syntax mode reports the macro markers as "tag" tokens, that CodeMirror renders using the cm-tag class.
64+
private static final By MACRO_MARKER = By.cssSelector("#content ~ .CodeMirror .CodeMirror-code .cm-tag");
65+
66+
@BeforeAll
67+
void beforeAll(TestUtils setup)
68+
{
69+
setup.loginAsSuperAdmin();
70+
}
71+
72+
@Test
73+
void highlightContent(TestUtils setup, TestReference testReference, XWikiWebDriver driver) throws Exception
74+
{
75+
setup.createPage(testReference, CONTENT, "Syntax Highlighting");
76+
77+
WikiEditPage editPage = WikiEditPage.gotoPage(testReference);
78+
79+
// The macro markers are highlighted only after CodeMirror, the XWiki syntax mode and the WebJar resources they
80+
// are loaded from have all been fetched successfully.
81+
driver.waitUntilElementIsVisible(MACRO_MARKER);
82+
assertEquals(List.of(CONTENT), getLines(driver));
83+
assertEquals("{{html}}{{/html}}", getMacroMarkers(driver));
84+
85+
// Type on a new line, to check that the editor is editable and that the typed content is highlighted too.
86+
driver.findElement(LINE).click();
87+
driver.createActions().sendKeys(Keys.END).sendKeys(Keys.ENTER).sendKeys(ADDED_CONTENT).perform();
88+
assertEquals(List.of(CONTENT, ADDED_CONTENT), getLines(driver));
89+
assertEquals("{{html}}{{/html}}{{html}}{{/html}}", getMacroMarkers(driver));
90+
91+
// Saving has to push the content of the editor back into the content text area.
92+
ViewPage viewPage = editPage.clickSaveAndView();
93+
assertEquals("test\nnew", viewPage.getContent());
94+
assertEquals(CONTENT + "\n" + ADDED_CONTENT, setup.rest().<Page>get(testReference).getContent());
95+
}
96+
97+
private List<String> getLines(XWikiWebDriver driver)
98+
{
99+
return driver.findElementsWithoutWaiting(LINE).stream().map(WebElement::getText).toList();
100+
}
101+
102+
private String getMacroMarkers(XWikiWebDriver driver)
103+
{
104+
return driver.findElementsWithoutWaiting(MACRO_MARKER).stream().map(WebElement::getText)
105+
.collect(Collectors.joining());
106+
}
107+
}

0 commit comments

Comments
 (0)