|
| 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.flamingo; |
| 21 | + |
| 22 | +import java.util.Locale; |
| 23 | + |
| 24 | +import org.jsoup.nodes.Document; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | +import org.xwiki.localization.Translation; |
| 27 | +import org.xwiki.localization.TranslationBundle; |
| 28 | +import org.xwiki.localization.TranslationBundleContext; |
| 29 | +import org.xwiki.localization.macro.internal.TranslationMacro; |
| 30 | +import org.xwiki.model.reference.DocumentReference; |
| 31 | +import org.xwiki.rendering.RenderingScriptServiceComponentList; |
| 32 | +import org.xwiki.rendering.block.WordBlock; |
| 33 | +import org.xwiki.rendering.internal.configuration.DefaultExtendedRenderingConfiguration; |
| 34 | +import org.xwiki.rendering.internal.configuration.RenderingConfigClassDocumentConfigurationSource; |
| 35 | +import org.xwiki.rendering.internal.macro.message.ErrorMessageMacro; |
| 36 | +import org.xwiki.test.annotation.ComponentList; |
| 37 | +import org.xwiki.test.page.HTML50ComponentList; |
| 38 | +import org.xwiki.test.page.PageTest; |
| 39 | +import org.xwiki.test.page.XWikiSyntax21ComponentList; |
| 40 | + |
| 41 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 42 | +import static org.mockito.ArgumentMatchers.eq; |
| 43 | +import static org.mockito.Mockito.any; |
| 44 | +import static org.mockito.Mockito.mock; |
| 45 | +import static org.mockito.Mockito.when; |
| 46 | + |
| 47 | +/** |
| 48 | + * Test of the {@code FlamingoThemesCode.WebHomeSheet} page. |
| 49 | + * |
| 50 | + * @version $Id$ |
| 51 | + * @since 13.10.10 |
| 52 | + * @since 14.4.6 |
| 53 | + * @since 14.9RC1 |
| 54 | + */ |
| 55 | +@HTML50ComponentList |
| 56 | +@XWikiSyntax21ComponentList |
| 57 | +@RenderingScriptServiceComponentList |
| 58 | +@ComponentList({ |
| 59 | + ErrorMessageMacro.class, |
| 60 | + TranslationMacro.class, |
| 61 | + TestNoScriptMacro.class, |
| 62 | + DefaultExtendedRenderingConfiguration.class, |
| 63 | + RenderingConfigClassDocumentConfigurationSource.class |
| 64 | +}) |
| 65 | +class WebHomeSheetPageTest extends PageTest |
| 66 | +{ |
| 67 | + @Test |
| 68 | + void createAction() throws Exception |
| 69 | + { |
| 70 | + this.request.put("newThemeName", "some content\"/}}{{noscript/}}"); |
| 71 | + this.request.put("form_token", "1"); |
| 72 | + this.request.put("action", "create"); |
| 73 | + |
| 74 | + TranslationBundleContext translationBundleContext = this.componentManager |
| 75 | + .getInstance(TranslationBundleContext.class); |
| 76 | + TranslationBundle translationBundle = mock(TranslationBundle.class); |
| 77 | + Translation translation = mock(Translation.class); |
| 78 | + when(translation.getLocale()).thenReturn(Locale.ENGLISH); |
| 79 | + when(translation.render(any(), any())).thenAnswer(invocationOnMock -> new WordBlock( |
| 80 | + "platform.flamingo.themes.home.create.csrf " + invocationOnMock.getArgument(1))); |
| 81 | + when(translationBundle.getTranslation(eq("platform.flamingo.themes.home.create.csrf"), any())) |
| 82 | + .thenReturn(translation); |
| 83 | + translationBundleContext.addBundle(translationBundle); |
| 84 | + |
| 85 | + Document document = this.renderHTMLPage(new DocumentReference("xwiki", "FlamingoThemesCode", "WebHomeSheet")); |
| 86 | + |
| 87 | + assertEquals("platform.flamingo.themes.home.create.csrf some content\"/}}{{noscript/}}", |
| 88 | + document.select(".box.errormessage").text()); |
| 89 | + } |
| 90 | +} |
0 commit comments