summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorMaciej PrzepioĢra <matthew@vaadin.com>2015-09-16 10:48:31 +0200
committerVaadin Code Review <review@vaadin.com>2015-09-24 07:46:38 +0000
commit5c875228d9025f4c779ffc26c3eb0f7b561061e5 (patch)
tree2e3a0d230478ef7d9090db31597e440f3f1738e7 /server/tests
parent8006d359acce4fb31e7210ed2f20f1da3d7a1cd0 (diff)
downloadvaadin-framework-5c875228d9025f4c779ffc26c3eb0f7b561061e5.tar.gz
vaadin-framework-5c875228d9025f4c779ffc26c3eb0f7b561061e5.zip
Support HTML entities when reading/writing declarative format #18882
Change-Id: I08099673c5dd0d688d3243e5fd169edb05f046f3
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java19
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractselect/AbstractSelectDeclarativeTest.java22
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractselect/OptionGroupDeclarativeTests.java6
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java39
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java181
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java24
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java36
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java28
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java22
9 files changed, 317 insertions, 60 deletions
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<T extends Component> {
+ 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<TT> {
public void assertObjectEquals(TT o1, TT o2);
}
@@ -55,12 +67,7 @@ public abstract class DeclarativeTestBaseBase<T extends Component> {
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 = "<v-combo-box>"
+ + " <option item-id=\"one\">&gt; One</option>"
+ + " <option>&gt; Two</option>" + "</v-combo-box>";
+ 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("&gt; 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", "<b>True</b>");
- og.setItemCaption("bar", "<font color='red'>False</font>");
+ og.setItemCaption("bar", "<font color=\"red\">False</font>");
//@formatter:off
String expected =
"<v-option-group>"
- + "<option item-id=\"foo\"><b>True</b></option>"
- + "<option item-id=\"bar\"><font color='red'>False</font></option>"
+ + "<option item-id=\"foo\">&lt;b&gt;True&lt;/b&gt;</option>"
+ + "<option item-id=\"bar\">&lt;font color=\"red\"&gt;False&lt;/font&gt;</option>"
+ "<option>baz</option>"
+ "<option>bang</option>"
+ "</v-option-group>";
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<Button> {
testButtonAndNativeButton(design, true, "", expectedWritten);
}
+ @Test
+ public void testHtmlEntitiesInCaption() {
+ String designPlainText = "<v-button plain-text=\"true\">&gt; One</v-button>";
+ String expectedCaptionPlainText = "> One";
+
+ Button read = read(designPlainText);
+ Assert.assertEquals(expectedCaptionPlainText, read.getCaption());
+
+ designPlainText = designPlainText
+ .replace("v-button", "v-native-button");
+ Button nativeButton = read(designPlainText);
+ Assert.assertEquals(expectedCaptionPlainText, nativeButton.getCaption());
+
+ String designHtml = "<v-button>&gt; One</v-button>";
+ String expectedCaptionHtml = "&gt; One";
+ read = read(designHtml);
+ Assert.assertEquals(expectedCaptionHtml, read.getCaption());
+
+ designHtml = designHtml.replace("v-button", "v-native-button");
+ nativeButton = read(designHtml);
+ Assert.assertEquals(expectedCaptionHtml, nativeButton.getCaption());
+
+ read = new Button("&amp; Test");
+ read.setHtmlContentAllowed(true);
+ Element root = new Element(Tag.valueOf("v-button"), "");
+ read.writeDesign(root, new DesignContext());
+ assertEquals("&amp; Test", root.html());
+
+ read.setHtmlContentAllowed(false);
+ root = new Element(Tag.valueOf("v-button"), "");
+ read.writeDesign(root, new DesignContext());
+ assertEquals("&amp;amp; Test", root.html());
+
+ }
+
public void testButtonAndNativeButton(String design, boolean html,
String caption) {
testButtonAndNativeButton(design, html, caption, design);
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java
index 8e1d880c5e..630c81fb30 100644
--- a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridHeaderFooterDeclarativeTest.java
@@ -15,6 +15,9 @@
*/
package com.vaadin.tests.server.component.grid.declarative;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Assert;
import org.junit.Test;
import com.vaadin.shared.ui.label.ContentMode;
@@ -23,21 +26,27 @@ import com.vaadin.ui.Grid.Column;
import com.vaadin.ui.Grid.FooterRow;
import com.vaadin.ui.Grid.HeaderRow;
import com.vaadin.ui.Label;
+import com.vaadin.ui.declarative.DesignContext;
public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testSingleDefaultHeader() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
+ " <col sortable='' property-id='Column2'>"
+ " <col sortable='' property-id='Column3'>"
- + "</colgroup>" //
- + "<thead>" //
- + " <tr default=''><th plain-text=''>Column1<th plain-text=''>Column2<th plain-text=''>Column3</tr>" //
- + "</thead>" //
+ + "</colgroup>"
+ + "<thead>"
+ + " <tr default=''>"
+ + " <th plain-text=''>Column1</th>"
+ + " <th plain-text=''>Column2</th>"
+ + " <th plain-text=''>Column3</tr>"
+ + "</thead>"
+ "</table></v-grid>";
+ //@formatter:on
Grid grid = new Grid();
grid.addColumn("Column1", String.class);
grid.addColumn("Column2", String.class);
@@ -49,15 +58,18 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testSingleDefaultHTMLHeader() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
+ " <col sortable='' property-id='Column2'>"
- + " <col sortable='' property-id='Column3'>" + "</colgroup>" //
- + "<thead>" //
- + " <tr default=''><th>Column1<th>Column2<th>Column3</tr>" //
- + "</thead>" //
+ + " <col sortable='' property-id='Column3'>"
+ + "</colgroup>"
+ + "<thead>"
+ + " <tr default=''><th>Column1<th>Column2<th>Column3</tr>"
+ + "</thead>"
+ "</table></v-grid>";
+ //@formatter:on
Grid grid = new Grid();
grid.addColumn("Column1", String.class);
grid.addColumn("Column2", String.class);
@@ -74,13 +86,14 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testNoHeaderRows() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
- + "</colgroup>" //
- + "<thead />" //
+ + "</colgroup>"
+ + "<thead />"
+ "</table></v-grid>";
-
+ //@formatter:on
Grid grid = new Grid();
grid.addColumn("Column1", String.class);
grid.removeHeaderRow(grid.getDefaultHeaderRow());
@@ -91,18 +104,20 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testMultipleHeadersWithColSpans() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
+ " <col sortable='' property-id='Column2'>"
+ " <col sortable='' property-id='Column3'>"
- + "</colgroup>" //
- + "<thead>" //
+ + "</colgroup>"
+ + "<thead>"
+ " <tr><th colspan=3>Baz</tr>"
- + " <tr default=''><th>Column1<th>Column2<th>Column3</tr>" //
- + " <tr><th>Foo<th colspan=2>Bar</tr>" //
- + "</thead>" //
+ + " <tr default=''><th>Column1<th>Column2<th>Column3</tr>"
+ + " <tr><th>Foo<th colspan=2>Bar</tr>"
+ + "</thead>"
+ "</table></v-grid>";
+ //@formatter:on
Grid grid = new Grid();
grid.addColumn("Column1", String.class);
grid.addColumn("Column2", String.class);
@@ -125,17 +140,19 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testSingleDefaultFooter() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
+ " <col sortable='' property-id='Column2'>"
+ " <col sortable='' property-id='Column3'>"
- + "</colgroup>" //
+ + "</colgroup>"
+ "<thead />" // No headers read or written
- + "<tfoot>" //
- + " <tr><td plain-text=''>Column1<td plain-text=''>Column2<td plain-text=''>Column3</tr>" //
- + "</tfoot>" //
+ + "<tfoot>"
+ + " <tr><td plain-text=''>Column1<td plain-text=''>Column2<td plain-text=''>Column3</tr>"
+ + "</tfoot>"
+ "</table></v-grid>";
+ //@formatter:on
Grid grid = new Grid();
grid.addColumn("Column1", String.class);
grid.addColumn("Column2", String.class);
@@ -154,16 +171,19 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testSingleDefaultHTMLFooter() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
+ " <col sortable='' property-id='Column2'>"
- + " <col sortable='' property-id='Column3'>" + "</colgroup>" //
+ + " <col sortable='' property-id='Column3'>"
+ + "</colgroup>"
+ "<thead />" // No headers read or written
- + "<tfoot>" //
- + " <tr><td>Column1<td>Column2<td>Column3</tr>" //
- + "</tfoot>" //
+ + "<tfoot>"
+ + " <tr><td>Column1<td>Column2<td>Column3</tr>"
+ + "</tfoot>"
+ "</table></v-grid>";
+ //@formatter:on
Grid grid = new Grid();
grid.addColumn("Column1", String.class);
grid.addColumn("Column2", String.class);
@@ -182,19 +202,21 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testMultipleFootersWithColSpans() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
+ " <col sortable='' property-id='Column2'>"
+ " <col sortable='' property-id='Column3'>"
- + "</colgroup>" //
+ + "</colgroup>"
+ "<thead />" // No headers read or written.
- + "<tfoot>" //
+ + "<tfoot>"
+ " <tr><td colspan=3>Baz</tr>"
- + " <tr><td>Column1<td>Column2<td>Column3</tr>" //
- + " <tr><td>Foo<td colspan=2>Bar</tr>" //
- + "</tfoot>" //
+ + " <tr><td>Column1<td>Column2<td>Column3</tr>"
+ + " <tr><td>Foo<td colspan=2>Bar</tr>"
+ + "</tfoot>"
+ "</table></v-grid>";
+ //@formatter:on
Grid grid = new Grid();
grid.addColumn("Column1", String.class);
grid.addColumn("Column2", String.class);
@@ -219,15 +241,16 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testComponentInGridHeader() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
- + "</colgroup>" //
- + "<thead>" //
+ + "</colgroup>"
+ + "<thead>"
+ "<tr default=''><th><v-label><b>Foo</b></v-label></tr>"
- + "</thead>"//
+ + "</thead>"
+ "</table></v-grid>";
-
+ //@formatter:on
Label component = new Label("<b>Foo</b>");
component.setContentMode(ContentMode.HTML);
@@ -241,16 +264,17 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
@Test
public void testComponentInGridFooter() {
- String design = "<v-grid><table>"//
+ //@formatter:off
+ String design = "<v-grid><table>"
+ "<colgroup>"
+ " <col sortable='' property-id='Column1'>"
- + "</colgroup>" //
+ + "</colgroup>"
+ "<thead />" // No headers read or written
- + "<tfoot>" //
- + "<tr><td><v-label><b>Foo</b></v-label></tr>"//
- + "</tfoot>" //
+ + "<tfoot>"
+ + "<tr><td><v-label><b>Foo</b></v-label></tr>"
+ + "</tfoot>"
+ "</table></v-grid>";
-
+ //@formatter:on
Label component = new Label("<b>Foo</b>");
component.setContentMode(ContentMode.HTML);
@@ -262,4 +286,67 @@ public class GridHeaderFooterDeclarativeTest extends GridDeclarativeTestBase {
testRead(design, grid, true);
testWrite(design, grid);
}
+
+ @Test
+ public void testHtmlEntitiesinGridHeaderFooter() {
+ // @formatter off
+ String design = "<v-grid><table>" + "<colgroup>"
+ + " <col sortable=\"true\" property-id=\"> test\">"
+ + "</colgroup>" + "<thead>"
+ + " <tr><th plain-text=\"true\">&gt; Test</th></tr>"
+ + "</thead>" + "<tfoot>"
+ + " <tr><td plain-text=\"true\">&gt; Test</td></tr>"
+ + "</tfoot>" + "<tbody />" + "</table></v-grid>";
+ // @formatter off
+ Grid grid = read(design);
+ String actualHeader = grid.getHeaderRow(0).getCell("> test").getText();
+ String actualFooter = grid.getFooterRow(0).getCell("> test").getText();
+ String expected = "> Test";
+
+ Assert.assertEquals(expected, actualHeader);
+ Assert.assertEquals(expected, actualFooter);
+
+ design = design.replace("plain-text=\"true\"", "");
+ grid = read(design);
+ actualHeader = grid.getHeaderRow(0).getCell("> test").getHtml();
+ actualFooter = grid.getFooterRow(0).getCell("> test").getHtml();
+ expected = "&gt; Test";
+
+ Assert.assertEquals(expected, actualHeader);
+ Assert.assertEquals(expected, actualFooter);
+
+ grid = new Grid();
+ grid.setColumns("test");
+ HeaderRow header = grid.addHeaderRowAt(0);
+ FooterRow footer = grid.addFooterRowAt(0);
+ grid.removeHeaderRow(grid.getDefaultHeaderRow());
+
+ // entities should be encoded when writing back, not interpreted as HTML
+ header.getCell("test").setText("&amp; Test");
+ footer.getCell("test").setText("&amp; Test");
+
+ Element root = new Element(Tag.valueOf("v-grid"), "");
+ grid.writeDesign(root, new DesignContext());
+
+ Assert.assertEquals("&amp;amp; Test", root.getElementsByTag("th")
+ .get(0).html());
+ Assert.assertEquals("&amp;amp; Test", root.getElementsByTag("td")
+ .get(0).html());
+
+ header = grid.addHeaderRowAt(0);
+ footer = grid.addFooterRowAt(0);
+
+ // entities should not be encoded, this is already given as HTML
+ header.getCell("test").setHtml("&amp; Test");
+ footer.getCell("test").setHtml("&amp; Test");
+
+ root = new Element(Tag.valueOf("v-grid"), "");
+ grid.writeDesign(root, new DesignContext());
+
+ Assert.assertEquals("&amp; Test", root.getElementsByTag("th").get(0)
+ .html());
+ Assert.assertEquals("&amp; Test", root.getElementsByTag("td").get(0)
+ .html());
+
+ }
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java
index d7feb4aa70..04f92b0190 100644
--- a/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/grid/declarative/GridInlineDataDeclarativeTest.java
@@ -15,8 +15,10 @@
*/
package com.vaadin.tests.server.component.grid.declarative;
+import org.junit.Assert;
import org.junit.Test;
+import com.vaadin.data.Container;
import com.vaadin.ui.Grid;
public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
@@ -32,6 +34,7 @@ public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
+ "<tr><td>Foo</tr>" //
+ "<tr><td>Bar</tr>" //
+ "<tr><td>Baz</tr>" //
+ + "</tbody>"
+ "</table></v-grid>";
Grid grid = new Grid();
@@ -59,6 +62,7 @@ public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
+ "<tbody>" //
+ "<tr><td>Foo<td>Bar<td>Baz</tr>" //
+ "<tr><td>My<td>Summer<td>Car</tr>" //
+ + "</tbody>"
+ "</table></v-grid>";
Grid grid = new Grid();
@@ -87,6 +91,7 @@ public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
+ "<tbody>" //
+ "<tr><td>Bar<td>Baz<td>Foo</tr>" //
+ "<tr><td>Summer<td>Car<td>My</tr>" //
+ + "</tbody>"
+ "</table></v-grid>";
Grid grid = new Grid();
@@ -103,4 +108,23 @@ public class GridInlineDataDeclarativeTest extends GridDeclarativeTestBase {
testWrite(design, grid, true);
testRead(design, grid, true, true);
}
+
+ @Test
+ public void testHtmlEntities() {
+ String design = "<v-grid><table>"//
+ + "<colgroup>"
+ + " <col property-id='test' />"
+ + "</colgroup>" //
+ + "<thead />" // No headers read or written
+ + "<tbody>"
+ + " <tr><td>&amp;Test</tr></td>"
+ + "</tbody>"
+ + "</table></v-grid>";
+
+ Grid read = read(design);
+ Container cds = read.getContainerDataSource();
+ Assert.assertEquals("&amp;Test",
+ cds.getItem(cds.getItemIds().iterator().next())
+ .getItemProperty("test").getValue());
+ }
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
index c2fed34c7b..6749776397 100644
--- a/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/label/LabelDeclarativeTest.java
@@ -15,11 +15,16 @@
*/
package com.vaadin.tests.server.component.label;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Assert;
import org.junit.Test;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.Label;
+import com.vaadin.ui.declarative.DesignContext;
+import com.vaadin.ui.declarative.DesignFormatter;
/**
* Tests declarative support for implementations of {@link Label}.
@@ -57,11 +62,11 @@ public class LabelDeclarativeTest extends DeclarativeTestBase<Label> {
@Test
public void testPlainText() {
- String design = "<v-label plain-text>This is only <b>text</b>"
+ String design = "<v-label plain-text>This is only &lt;b&gt;text&lt;/b&gt;"
+ " and will contain visible tags</v-label>";
Label l = createLabel(
- "This is only \n<b>text</b> and will contain visible tags",
- null, false);
+ "This is only <b>text</b> and will contain visible tags", null,
+ false);
testRead(design, l);
testWrite(design, l);
}
@@ -84,6 +89,29 @@ public class LabelDeclarativeTest extends DeclarativeTestBase<Label> {
testWrite(design, l);
}
+ @Test
+ public void testHtmlEntities() {
+ String design = "<v-label plain-text=\"true\">&gt; Test</v-label>";
+ Label read = read(design);
+ Assert.assertEquals("> Test", read.getValue());
+
+ design = design.replace("plain-text=\"true\"", "");
+ read = read(design);
+ Assert.assertEquals("&gt; Test", read.getValue());
+
+ Label label = new Label("&amp; Test");
+ label.setContentMode(ContentMode.TEXT);
+
+ Element root = new Element(Tag.valueOf("v-label"), "");
+ label.writeDesign(root, new DesignContext());
+ Assert.assertEquals("&amp;amp; Test", root.html());
+
+ label.setContentMode(ContentMode.HTML);
+ root = new Element(Tag.valueOf("v-label"), "");
+ label.writeDesign(root, new DesignContext());
+ Assert.assertEquals("&amp; Test", root.html());
+ }
+
private Label createLabel(String content, String caption, boolean html) {
Label label = new Label();
label.setContentMode(html ? ContentMode.HTML : ContentMode.TEXT);
@@ -91,7 +119,7 @@ public class LabelDeclarativeTest extends DeclarativeTestBase<Label> {
label.setValue(content);
}
if (caption != null) {
- label.setCaption(caption);
+ label.setCaption(DesignFormatter.encodeForTextNode(caption));
}
return label;
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java
index 3de5ae0524..aad2d1efb0 100644
--- a/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/table/TableDeclarativeTest.java
@@ -15,6 +15,7 @@
*/
package com.vaadin.tests.server.component.table;
+import org.junit.Assert;
import org.junit.Test;
import com.vaadin.server.ExternalResource;
@@ -24,6 +25,7 @@ import com.vaadin.ui.Table.Align;
import com.vaadin.ui.Table.ColumnHeaderMode;
import com.vaadin.ui.Table.RowHeaderMode;
import com.vaadin.ui.Table.TableDragMode;
+import com.vaadin.ui.declarative.Design;
/**
* Test declarative support for {@link Table}.
@@ -166,4 +168,30 @@ public class TableDeclarativeTest extends TableDeclarativeTestBase {
testRead(design, table);
testWrite(design, table, true);
}
+
+ @Test
+ public void testHtmlEntities() {
+ String design = "<v-table>"
+ + "<table>"
+ + " <colgroup>"
+ + " <col property-id=\"test\""
+ + " </colgroup>"
+ + " <thead>"
+ + " <tr><th>&amp; Test</th></tr>"
+ + " </thead>"
+ + " <tbody>"
+ + " <tr item-id=\"test\"><td>&amp; Test</tr>"
+ + " </tbody>"
+ + " <tfoot>"
+ + " <tr><td>&amp; Test</td></tr>"
+ + " </tfoot>"
+ + "</table>"
+ + "</v-table>";
+ Table read = read(design);
+
+ Assert.assertEquals("& Test",
+ read.getContainerProperty("test", "test").getValue());
+ Assert.assertEquals("& Test", read.getColumnHeader("test"));
+ Assert.assertEquals("& Test", read.getColumnFooter("test"));
+ }
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java
index 8b0c26df87..bed8851204 100644
--- a/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java
@@ -15,10 +15,16 @@
*/
package com.vaadin.tests.server.component.textarea;
+import java.io.IOException;
+
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Assert;
import org.junit.Test;
import com.vaadin.tests.design.DeclarativeTestBase;
import com.vaadin.ui.TextArea;
+import com.vaadin.ui.declarative.DesignContext;
/**
* Tests declarative support for implementations of {@link TextArea}.
@@ -38,4 +44,20 @@ public class TextAreaDeclarativeTest extends DeclarativeTestBase<TextArea> {
testRead(design, ta);
testWrite(design, ta);
}
+
+ @Test
+ public void testHtmlEntities() throws IOException {
+ String design = "<v-text-area>&amp; Test</v-text-area>";
+ TextArea read = read(design);
+ Assert.assertEquals("& Test", read.getValue());
+
+ read.setValue("&amp; Test");
+
+ DesignContext dc = new DesignContext();
+ Element root = new Element(Tag.valueOf("v-text-area"), "");
+ read.writeDesign(root, dc);
+
+ Assert.assertEquals("&amp;amp; Test", root.html());
+
+ }
}