|
| 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.administration; |
| 21 | + |
| 22 | +import java.util.Map; |
| 23 | + |
| 24 | +import javax.script.ScriptContext; |
| 25 | + |
| 26 | +import org.jsoup.nodes.Document; |
| 27 | +import org.jsoup.nodes.Element; |
| 28 | +import org.junit.jupiter.api.BeforeEach; |
| 29 | +import org.junit.jupiter.api.Test; |
| 30 | +import org.xwiki.model.reference.DocumentReference; |
| 31 | +import org.xwiki.rendering.RenderingScriptServiceComponentList; |
| 32 | +import org.xwiki.rendering.internal.configuration.DefaultExtendedRenderingConfiguration; |
| 33 | +import org.xwiki.rendering.internal.configuration.RenderingConfigClassDocumentConfigurationSource; |
| 34 | +import org.xwiki.script.ScriptContextManager; |
| 35 | +import org.xwiki.test.annotation.ComponentList; |
| 36 | +import org.xwiki.test.page.HTML50ComponentList; |
| 37 | +import org.xwiki.test.page.PageTest; |
| 38 | +import org.xwiki.test.page.TestNoScriptMacro; |
| 39 | +import org.xwiki.test.page.XWikiSyntax21ComponentList; |
| 40 | + |
| 41 | +import static java.util.Collections.emptyList; |
| 42 | +import static java.util.Collections.singletonMap; |
| 43 | +import static javax.script.ScriptContext.ENGINE_SCOPE; |
| 44 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 45 | + |
| 46 | +/** |
| 47 | + * Page test of {@code XWiki.AdminFieldsDisplaySheet}. |
| 48 | + * |
| 49 | + * @version $Id$ |
| 50 | + * @since 15.0RC1 |
| 51 | + * @since 14.10.1 |
| 52 | + * @since 14.4.8 |
| 53 | + * @since 13.10.11 |
| 54 | + */ |
| 55 | +@HTML50ComponentList |
| 56 | +@XWikiSyntax21ComponentList |
| 57 | +@RenderingScriptServiceComponentList |
| 58 | +@ComponentList({ |
| 59 | + TestNoScriptMacro.class, |
| 60 | + DefaultExtendedRenderingConfiguration.class, |
| 61 | + RenderingConfigClassDocumentConfigurationSource.class |
| 62 | +}) |
| 63 | +class AdminFieldsDisplaySheetPageTest extends PageTest |
| 64 | +{ |
| 65 | + private ScriptContext scriptContext; |
| 66 | + |
| 67 | + @BeforeEach |
| 68 | + void setUp() throws Exception |
| 69 | + { |
| 70 | + this.scriptContext = |
| 71 | + this.oldcore.getMocker().<ScriptContextManager>getInstance(ScriptContextManager.class).getScriptContext(); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + void escaping() throws Exception |
| 76 | + { |
| 77 | + String paramsInput = "\"/><script>console.log('params');</script>{{/html}}{{noscript/}}"; |
| 78 | + String sectionInput = "\"/><strong>console.log('section');</script>{{/html}}{{noscript/}}"; |
| 79 | + String paramClassInput = "\"/><script>console.log('paramClass');</script>{{/html}}{{noscript/}}"; |
| 80 | + Map<Object, Object> params = singletonMap(paramsInput, emptyList()); |
| 81 | + DocumentReference otherDocumentReference = new DocumentReference("xwiki", "Space", "Page"); |
| 82 | + com.xpn.xwiki.api.Document otherDocument = |
| 83 | + new com.xpn.xwiki.api.Document(this.xwiki.getDocument(otherDocumentReference, this.context), this.context); |
| 84 | + |
| 85 | + this.scriptContext.setAttribute("section", sectionInput, ENGINE_SCOPE); |
| 86 | + this.scriptContext.setAttribute("paramDoc", otherDocument, ENGINE_SCOPE); |
| 87 | + this.scriptContext.setAttribute("params", params, ENGINE_SCOPE); |
| 88 | + this.scriptContext.setAttribute("paramClass", paramClassInput, ENGINE_SCOPE); |
| 89 | + |
| 90 | + Document document = renderHTMLPage(new DocumentReference("xwiki", "XWiki", "AdminFieldsDisplaySheet")); |
| 91 | + |
| 92 | + Element form = document.selectFirst("form"); |
| 93 | + assertEquals(String.format("%s_%s", sectionInput, paramClassInput), form.attr("id")); |
| 94 | + assertEquals("/xwiki/bin/saveandcontinue/Space/Page", form.attr("action")); |
| 95 | + Element fieldset = form.selectFirst("fieldset"); |
| 96 | + assertEquals(paramsInput, fieldset.attr("class")); |
| 97 | + assertEquals(paramClassInput, document.selectFirst(".hidden input[name='classname']").val()); |
| 98 | + } |
| 99 | +} |
0 commit comments