From 9c0f37b2fd7535a46c324ff7eb89ed9454aee88f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 18 Aug 2017 13:58:34 +0300 Subject: www: no more ugnich templates --- .../src/test/java/com/juick/www/WebAppTests.java | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'juick-www/src/test/java') diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java index 98df3660..d09bded2 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -22,6 +22,7 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.css.StyleElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.juick.Message; +import com.juick.Tag; import com.juick.User; import com.juick.configuration.MockDataConfiguration; import com.juick.server.configuration.BaseWebConfiguration; @@ -31,6 +32,10 @@ import com.juick.test.util.MockUtils; import com.juick.www.configuration.SapeConfiguration; import com.juick.www.configuration.WwwAppConfiguration; import com.juick.www.configuration.WwwServletConfiguration; +import com.mitchellbosecke.pebble.PebbleEngine; +import com.mitchellbosecke.pebble.error.PebbleException; +import com.mitchellbosecke.pebble.template.PebbleTemplate; +import org.apache.commons.text.StringEscapeUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -44,9 +49,9 @@ import org.springframework.web.context.WebApplicationContext; import javax.inject.Inject; import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Optional; +import java.io.StringWriter; +import java.io.Writer; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.StreamSupport; @@ -81,6 +86,9 @@ public class WebAppTests { @Inject MessagesService messagesService; + @Inject + PebbleEngine pebbleEngine; + @Before public void setup() { webClient = MockMvcWebClientBuilder.webAppContextSetup(this.wac).build(); @@ -176,6 +184,15 @@ public class WebAppTests { return display == null || !display.getValue().equals("none"); }).count(); assertThat(visibleItems, equalTo(1L)); - + } + @Test + public void correctTagsEscaping() throws PebbleException, IOException { + PebbleTemplate template = pebbleEngine.getTemplate("views/test"); + Writer writer = new StringWriter(); + template.evaluate(writer, + Collections.singletonMap("tagsList", + Collections.singletonList(StringEscapeUtils.escapeHtml4(new Tag(">_<").getName())))); + String output = writer.toString().trim(); + assertThat(output, equalTo(">_<")); } } -- cgit v1.2.3