use of org.structr.web.entity.dom.Template in project structr by structr.
the class DeploymentTest method test18NonNamedNonSharedTemplateWithChildren.
@Test
public void test18NonNamedNonSharedTemplateWithChildren() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test18");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test18");
final Body body = createElement(page, html, "body");
final Template template = createTemplate(page, body, "${render(children)}");
final Template sharedTemplate = createComponent(template);
// remove original template from page
app.delete(template);
createElement(page, sharedTemplate, "div");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true, false);
}
use of org.structr.web.entity.dom.Template in project structr by structr.
the class DeploymentTest method test11TemplateInTbody.
@Test
public void test11TemplateInTbody() {
// setup
try (final Tx tx = app.tx()) {
// create first page
final Page page1 = Page.createNewPage(securityContext, "test11");
final Html html1 = createElement(page1, page1, "html");
final Head head1 = createElement(page1, html1, "head");
createElement(page1, head1, "title", "test11_1");
final Body body1 = createElement(page1, html1, "body");
final Table table = createElement(page1, body1, "table");
final Tbody tbody = createElement(page1, table, "tbody");
final Template template1 = createTemplate(page1, tbody, "<tr><td>${user.name}</td></tr>");
final PropertyMap template1Properties = new PropertyMap();
template1Properties.put(StructrApp.key(DOMNode.class, "functionQuery"), "find('User')");
template1Properties.put(StructrApp.key(DOMNode.class, "dataKey"), "user");
template1.setProperties(template1.getSecurityContext(), template1Properties);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true);
}
use of org.structr.web.entity.dom.Template in project structr by structr.
the class DeploymentTest method test34WidgetWithTemplate.
@Test
public void test34WidgetWithTemplate() {
// setup
try (final Tx tx = app.tx()) {
final Page testPage = Page.createNewPage(securityContext, "WidgetTestPage");
final Html html = createElement(testPage, testPage, "html");
final Head head = createElement(testPage, html, "head");
final Body body = createElement(testPage, html, "body");
final Div div = createElement(testPage, body, "div");
final Div div2 = createElement(testPage, body, "div");
div.setProperty(AbstractNode.name, "WidgetTestPage-Div");
div2.setProperty(AbstractNode.name, "WidgetTestPage-Div2");
Widget widgetToImport = app.create(Widget.class, new NodeAttribute<>(StructrApp.key(Widget.class, "name"), "TestWidget"), new NodeAttribute<>(StructrApp.key(Widget.class, "source"), "<!-- @structr:content(text/html) --><structr:template>${{Structr.print(\"<div>Test</div>\");}}</structr:template>"), new NodeAttribute<>(StructrApp.key(Widget.class, "configuration"), "{\"processDeploymentInfo\": true}"), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToPublicUsers"), true), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToAuthenticatedUsers"), true));
Importer importer = new Importer(securityContext, widgetToImport.getProperty(new StringProperty("source")), null, null, true, true);
importer.setIsDeployment(true);
importer.setCommentHandler(new DeploymentCommentHandler());
importer.parse(true);
DOMNode template = importer.createComponentChildNodes(div, testPage);
div.appendChild(template);
makePublic(testPage, html, head, body, div, div2, template);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// test
try (final Tx tx = app.tx()) {
Div div = (Div) app.nodeQuery().andName("WidgetTestPage-Div").getFirst();
assertEquals(1, div.treeGetChildCount());
Object obj = div.treeGetFirstChild();
assertTrue(Template.class.isAssignableFrom(obj.getClass()));
Template template = (Template) obj;
assertEquals("${{Structr.print(\"<div>Test</div>\");}}", template.getTextContent());
assertEquals("text/html", template.getContentType());
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.web.entity.dom.Template in project structr by structr.
the class DeploymentTest method test08SharedTemplateInTwoPages.
@Test
public void test08SharedTemplateInTwoPages() {
// setup
try (final Tx tx = app.tx()) {
// create first page
final Page page1 = Page.createNewPage(securityContext, "test08_1");
final Html html1 = createElement(page1, page1, "html");
final Head head1 = createElement(page1, html1, "head");
createElement(page1, head1, "title", "test08_1");
final Body body1 = createElement(page1, html1, "body");
final Div div1 = createElement(page1, body1, "div");
final Template template1 = createTemplate(page1, div1, "template source - öäüÖÄÜß'\"'`");
final Template component = createComponent(template1);
// create second page
final Page page2 = Page.createNewPage(securityContext, "test08_2");
final Html html2 = createElement(page2, page2, "html");
final Head head2 = createElement(page2, html2, "head");
createElement(page2, head2, "title", "test08_2");
final Body body2 = createElement(page2, html2, "body");
final Div div2 = createElement(page2, body2, "div");
// re-use template from above
cloneComponent(component, div2);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true);
}
use of org.structr.web.entity.dom.Template in project structr by structr.
the class DeploymentTest method test17NamedNonSharedTemplateWithChildren.
@Test
public void test17NamedNonSharedTemplateWithChildren() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test17");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test17");
final Body body = createElement(page, html, "body");
final Template template = createTemplate(page, body, "${render(children)}");
template.setProperty(AbstractNode.name, "a-template");
final Template sharedTemplate = createComponent(template);
// remove original template from page
app.delete(template);
createElement(page, sharedTemplate, "div");
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
// test
compare(calculateHash(), true, false);
}
Aggregations