|
| 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.search.ui; |
| 21 | + |
| 22 | +import java.io.PrintWriter; |
| 23 | +import java.io.StringWriter; |
| 24 | + |
| 25 | +import org.junit.jupiter.api.BeforeEach; |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | +import org.xwiki.model.reference.DocumentReference; |
| 28 | +import org.xwiki.rendering.RenderingScriptServiceComponentList; |
| 29 | +import org.xwiki.rendering.internal.configuration.DefaultRenderingConfigurationComponentList; |
| 30 | +import org.xwiki.rendering.syntax.Syntax; |
| 31 | +import org.xwiki.test.annotation.ComponentList; |
| 32 | +import org.xwiki.test.page.HTML50ComponentList; |
| 33 | +import org.xwiki.test.page.PageTest; |
| 34 | +import org.xwiki.test.page.TestNoScriptMacro; |
| 35 | +import org.xwiki.test.page.XWikiSyntax21ComponentList; |
| 36 | + |
| 37 | +import com.xpn.xwiki.doc.XWikiDocument; |
| 38 | +import com.xpn.xwiki.plugin.feed.FeedPlugin; |
| 39 | +import com.xpn.xwiki.web.XWikiServletResponseStub; |
| 40 | + |
| 41 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 42 | + |
| 43 | +/** |
| 44 | + * Page test for {@code Main.DatabaseSearch}. |
| 45 | + * |
| 46 | + * @version $Id$ |
| 47 | + */ |
| 48 | +@ComponentList({ |
| 49 | + TestNoScriptMacro.class |
| 50 | +}) |
| 51 | +@RenderingScriptServiceComponentList |
| 52 | +@DefaultRenderingConfigurationComponentList |
| 53 | +@HTML50ComponentList |
| 54 | +@XWikiSyntax21ComponentList |
| 55 | +class DatabaseSearchPageTest extends PageTest |
| 56 | +{ |
| 57 | + private static final String WIKI_NAME = "xwiki"; |
| 58 | + |
| 59 | + private static final String MAIN_SPACE = "Main"; |
| 60 | + |
| 61 | + private static final DocumentReference DATABASE_SEARCH_REFERENCE = |
| 62 | + new DocumentReference(WIKI_NAME, MAIN_SPACE, "DatabaseSearch"); |
| 63 | + |
| 64 | + @BeforeEach |
| 65 | + void setUp() |
| 66 | + { |
| 67 | + this.xwiki.initializeMandatoryDocuments(this.context); |
| 68 | + |
| 69 | + this.xwiki.getPluginManager().addPlugin("feed", FeedPlugin.class.getName(), this.context); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + void checkRSSFeedContent() throws Exception |
| 74 | + { |
| 75 | + String unescapedText = "<b>}}}{{noscript}}</b>"; |
| 76 | + String escapedText = "<b>}}}{{noscript}}</b>"; |
| 77 | + |
| 78 | + this.request.put("text", unescapedText); |
| 79 | + this.context.setAction("get"); |
| 80 | + |
| 81 | + XWikiDocument databaseSearchDocument = loadPage(DATABASE_SEARCH_REFERENCE); |
| 82 | + this.context.setDoc(databaseSearchDocument); |
| 83 | + |
| 84 | + // Get directly the writer to check the RSS feed. |
| 85 | + StringWriter out = new StringWriter(); |
| 86 | + PrintWriter writer = new PrintWriter(out); |
| 87 | + this.response = new XWikiServletResponseStub() { |
| 88 | + @Override |
| 89 | + public PrintWriter getWriter() |
| 90 | + { |
| 91 | + return writer; |
| 92 | + } |
| 93 | + }; |
| 94 | + this.context.setResponse(this.response); |
| 95 | + |
| 96 | + String rssFeed = databaseSearchDocument.displayDocument(Syntax.PLAIN_1_0, this.context); |
| 97 | + assertTrue(rssFeed.isEmpty()); |
| 98 | + |
| 99 | + rssFeed = out.toString(); |
| 100 | + assertTrue(rssFeed.contains("<title>search.rss [" + escapedText + "]</title>")); |
| 101 | + assertTrue(rssFeed.contains("<description>search.rss [" + escapedText + "]</description>")); |
| 102 | + } |
| 103 | +} |
0 commit comments