Search in sources :

Example 1 with Title

use of org.structr.web.entity.html.Title in project structr by structr.

the class CustomHtmlAttributeTest method testCustomHtmlAttribute.

@Test
public void testCustomHtmlAttribute() {
    try (final Tx tx = app.tx()) {
        // create a page
        final Page newPage = Page.createNewPage(securityContext, "customAttributeTestPage");
        final Html html = createElement(newPage, newPage, "html");
        final Head head = createElement(newPage, html, "head");
        final Title title = createElement(newPage, head, "title", "Test Page for custom html attributes");
        final Body body = createElement(newPage, html, "body");
        final Div div1 = createElement(newPage, body, "div", "DIV with old-style data attribute");
        div1.setProperty(new GenericProperty<String>("data-test-attribute-old-style"), "old-style data attribute");
        final Div div2 = createElement(newPage, body, "div", "DIV with new-style custom html attribute");
        div2.setProperty(new GenericProperty<String>("_custom_html_test-attribute-new-style"), "new-style custom attribute");
        final Div div3 = createElement(newPage, body, "div", "DIV with data-attribute as new-style custom html attribute");
        div3.setProperty(new GenericProperty<String>("_custom_html_data-test-attribute-new-style"), "new-style custom data-attribute");
        final RenderContext renderContext = new RenderContext(securityContext);
        newPage.render(renderContext, 0);
        final String renderedHtml = StringUtils.join(renderContext.getBuffer().getQueue(), "");
        final String expectedHtml = "<!DOCTYPE html>\n" + "<html>\n" + "	<head>\n" + "		<title>Test Page for custom html attributes</title>\n" + "	</head>\n" + "	<body>\n" + "		<div data-test-attribute-old-style=\"old-style data attribute\">DIV with old-style data attribute</div>\n" + "		<div test-attribute-new-style=\"new-style custom attribute\">DIV with new-style custom html attribute</div>\n" + "		<div data-test-attribute-new-style=\"new-style custom data-attribute\">DIV with data-attribute as new-style custom html attribute</div>\n" + "	</body>\n" + "</html>";
        Assert.assertEquals(expectedHtml, renderedHtml);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
}
Also used : Div(org.structr.web.entity.html.Div) RenderContext(org.structr.web.common.RenderContext) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Title(org.structr.web.entity.html.Title) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Test (org.junit.Test)1 FrameworkException (org.structr.common.error.FrameworkException)1 Tx (org.structr.core.graph.Tx)1 StructrUiTest (org.structr.web.StructrUiTest)1 RenderContext (org.structr.web.common.RenderContext)1 Page (org.structr.web.entity.dom.Page)1 Body (org.structr.web.entity.html.Body)1 Div (org.structr.web.entity.html.Div)1 Head (org.structr.web.entity.html.Head)1 Html (org.structr.web.entity.html.Html)1 Title (org.structr.web.entity.html.Title)1