From 5c875228d9025f4c779ffc26c3eb0f7b561061e5 Mon Sep 17 00:00:00 2001 From: Maciej PrzepioĢra Date: Wed, 16 Sep 2015 10:48:31 +0200 Subject: Support HTML entities when reading/writing declarative format #18882 Change-Id: I08099673c5dd0d688d3243e5fd169edb05f046f3 --- .../tests/design/DeclarativeTestBaseBase.java | 19 ++- .../AbstractSelectDeclarativeTest.java | 22 +++ .../OptionGroupDeclarativeTests.java | 6 +- .../component/button/ButtonDeclarativeTest.java | 39 +++++ .../GridHeaderFooterDeclarativeTest.java | 181 +++++++++++++++------ .../declarative/GridInlineDataDeclarativeTest.java | 24 +++ .../component/label/LabelDeclarativeTest.java | 36 +++- .../component/table/TableDeclarativeTest.java | 28 ++++ .../textarea/TextAreaDeclarativeTest.java | 22 +++ 9 files changed, 317 insertions(+), 60 deletions(-) (limited to 'server/tests') diff --git a/server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java b/server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java index f0714ef3bd..635b3e37cb 100644 --- a/server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java +++ b/server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java @@ -36,6 +36,18 @@ import com.vaadin.ui.declarative.DesignContext; import com.vaadin.ui.declarative.ShouldWriteDataDelegate; public abstract class DeclarativeTestBaseBase { + private static final class AlwaysWriteDelegate implements + ShouldWriteDataDelegate { + private static final long serialVersionUID = -6345914431997793599L; + + @Override + public boolean shouldWriteData(Component component) { + return true; + } + } + + public static final ShouldWriteDataDelegate ALWAYS_WRITE_DATA = new AlwaysWriteDelegate(); + public interface EqualsAsserter { public void assertObjectEquals(TT o1, TT o2); } @@ -55,12 +67,7 @@ public abstract class DeclarativeTestBaseBase { DesignContext dc = new DesignContext(); if (writeData) { - dc.setShouldWriteDataDelegate(new ShouldWriteDataDelegate() { - @Override - public boolean shouldWriteData(Component component) { - return true; - } - }); + dc.setShouldWriteDataDelegate(DeclarativeTestBaseBase.ALWAYS_WRITE_DATA); } dc.setRootComponent(object); Design.write(dc, outputStream); diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractselect/AbstractSelectDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractselect/AbstractSelectDeclarativeTest.java index b294ffad72..4f971412b8 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractselect/AbstractSelectDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractselect/AbstractSelectDeclarativeTest.java @@ -26,6 +26,7 @@ import com.vaadin.data.util.IndexedContainer; import com.vaadin.server.ExternalResource; import com.vaadin.server.Resource; import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.design.DeclarativeTestBaseBase; import com.vaadin.ui.AbstractSelect; import com.vaadin.ui.AbstractSelect.ItemCaptionMode; import com.vaadin.ui.ComboBox; @@ -257,6 +258,27 @@ public class AbstractSelectDeclarativeTest extends || "true".equals(e.attr("multi-select"))); } + @Test + public void testHtmlEntities() { + String design = "" + + " " + + " " + ""; + AbstractSelect read = read(design); + + Assert.assertEquals("> One", read.getItemCaption("one")); + + AbstractSelect underTest = new ComboBox(); + underTest.addItem("> One"); + + Element root = new Element(Tag.valueOf("v-combo-box"), ""); + DesignContext dc = new DesignContext(); + dc.setShouldWriteDataDelegate(DeclarativeTestBaseBase.ALWAYS_WRITE_DATA); + underTest.writeDesign(root, dc); + + Assert.assertEquals("> One", root.getElementsByTag("option").first() + .html()); + } + public ComboBox createSingleSelectWithOnlyAttributes() { ComboBox cb = new ComboBox(); Container dataSource = new IndexedContainer(); diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractselect/OptionGroupDeclarativeTests.java b/server/tests/src/com/vaadin/tests/server/component/abstractselect/OptionGroupDeclarativeTests.java index efcdc3e997..3e6a7a15cb 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractselect/OptionGroupDeclarativeTests.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractselect/OptionGroupDeclarativeTests.java @@ -128,13 +128,13 @@ public class OptionGroupDeclarativeTests extends og.addItems("foo", "bar", "baz", "bang"); og.setItemCaption("foo", "True"); - og.setItemCaption("bar", "False"); + og.setItemCaption("bar", "False"); //@formatter:off String expected = "" - + "" - + "" + + "" + + "" + "" + "" + ""; diff --git a/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java index b1c10789b4..e299b5ecf7 100644 --- a/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java @@ -15,6 +15,9 @@ */ package com.vaadin.tests.server.component.button; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; +import org.junit.Assert; import org.junit.Test; import com.vaadin.event.ShortcutAction.KeyCode; @@ -22,6 +25,7 @@ import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.tests.design.DeclarativeTestBase; import com.vaadin.ui.Button; import com.vaadin.ui.NativeButton; +import com.vaadin.ui.declarative.DesignContext; /** * Tests declarative support for implementations of {@link Button} and @@ -71,6 +75,41 @@ public class ButtonDeclarativeTest extends DeclarativeTestBase