Search in sources :

Example 26 with Div

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

the class DeploymentTest method test40TwoTemplatesWithSameNameInTwoPages.

@Test
public void test40TwoTemplatesWithSameNameInTwoPages() {
    // setup
    try (final Tx tx = app.tx()) {
        // create first page
        final Page page1 = Page.createNewPage(securityContext, "test40_1");
        final Html html1 = createElement(page1, page1, "html");
        final Head head1 = createElement(page1, html1, "head");
        createElement(page1, head1, "title", "test40_1");
        final Body body1 = createElement(page1, html1, "body");
        final Div div1 = createElement(page1, body1, "div");
        // create first template and give it a name
        final Template template1 = createTemplate(page1, div1, "template source - öäüÖÄÜß'\"'`");
        final PropertyMap template1Properties = new PropertyMap();
        template1Properties.put(Template.name, "Test40Template");
        template1.setProperties(template1.getSecurityContext(), template1Properties);
        // create second page
        final Page page2 = Page.createNewPage(securityContext, "test40_2");
        final Html html2 = createElement(page2, page2, "html");
        final Head head2 = createElement(page2, html2, "head");
        createElement(page2, head2, "title", "test40_2");
        final Body body2 = createElement(page2, html2, "body");
        final Div div2 = createElement(page2, body2, "div");
        // create second template and give it the same name as the first one
        final Template template2 = createTemplate(page2, div2, "template source 2 - öäüÖÄÜß'\"'`");
        final PropertyMap template2Properties = new PropertyMap();
        template2Properties.put(Template.name, "Test40Template");
        template2.setProperties(template2.getSecurityContext(), template2Properties);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true);
}
Also used : Div(org.structr.web.entity.html.Div) Head(org.structr.web.entity.html.Head) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 27 with Div

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

the class UiScriptingTest method testIncludeWithRepeaterInJavaScript.

@Test
public void testIncludeWithRepeaterInJavaScript() {
    try (final Tx tx = app.tx()) {
        final Page page = Page.createSimplePage(securityContext, "test");
        final Div div = (Div) page.getElementsByTagName("div").item(0);
        final Content content = (Content) div.getFirstChild();
        // setup scripting repeater
        content.setProperty(StructrApp.key(Content.class, "content"), "${{ var arr = []; for (var i=0; i<10; i++) { arr.push({name: 'test' + i}); } Structr.include('item', arr, 'test'); }}");
        content.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
        // setup shared component with name "table" to include
        final ShadowDocument shadowDoc = CreateComponentCommand.getOrCreateHiddenDocument();
        final Div item = (Div) shadowDoc.createElement("div");
        final Content txt = (Content) shadowDoc.createTextNode("${test.name}");
        item.setProperty(StructrApp.key(Table.class, "name"), "item");
        item.appendChild(txt);
        // create admin user
        createTestNode(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
        fail("Unexpected exception.");
    }
    RestAssured.basePath = "/";
    // test successful basic auth
    RestAssured.given().headers("X-User", "admin", "X-Password", "admin").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("html.head.title", Matchers.equalTo("Test")).body("html.body.h1", Matchers.equalTo("Test")).body("html.body.div.div[0]", Matchers.equalTo("test0")).body("html.body.div.div[1]", Matchers.equalTo("test1")).body("html.body.div.div[2]", Matchers.equalTo("test2")).body("html.body.div.div[3]", Matchers.equalTo("test3")).body("html.body.div.div[4]", Matchers.equalTo("test4")).body("html.body.div.div[5]", Matchers.equalTo("test5")).body("html.body.div.div[6]", Matchers.equalTo("test6")).body("html.body.div.div[7]", Matchers.equalTo("test7")).body("html.body.div.div[8]", Matchers.equalTo("test8")).body("html.body.div.div[9]", Matchers.equalTo("test9")).when().get("/html/test");
}
Also used : Div(org.structr.web.entity.html.Div) Table(org.structr.web.entity.html.Table) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Page(org.structr.web.entity.dom.Page) ShadowDocument(org.structr.web.entity.dom.ShadowDocument) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 28 with Div

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

the class UiScriptingTest method testFunctionQueryWithJavaScriptAndRepeater.

@Test
public void testFunctionQueryWithJavaScriptAndRepeater() {
    try (final Tx tx = app.tx()) {
        final Page page = Page.createSimplePage(securityContext, "test");
        final Div div = (Div) page.getElementsByTagName("div").item(0);
        final Content content = (Content) div.getFirstChild();
        // setup repeater
        content.setProperty(StructrApp.key(DOMNode.class, "functionQuery"), "{ var arr = []; for (var i=0; i<10; i++) { arr.push({ name: 'test' + i }); }; return arr; }");
        content.setProperty(StructrApp.key(DOMNode.class, "dataKey"), "test");
        content.setProperty(StructrApp.key(Content.class, "content"), "${test.name}");
        // create admin user
        createTestNode(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
        fail("Unexpected exception.");
    }
    RestAssured.basePath = "/";
    // test successful basic auth
    RestAssured.given().headers("X-User", "admin", "X-Password", "admin").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).body("html.head.title", Matchers.equalTo("Test")).body("html.body.h1", Matchers.equalTo("Test")).body("html.body.div", Matchers.equalTo("test0test1test2test3test4test5test6test7test8test9")).when().get("/html/test");
}
Also used : Div(org.structr.web.entity.html.Div) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Page(org.structr.web.entity.dom.Page) DOMNode(org.structr.web.entity.dom.DOMNode) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Test (org.junit.Test)28 FrameworkException (org.structr.common.error.FrameworkException)28 Tx (org.structr.core.graph.Tx)28 StructrUiTest (org.structr.web.StructrUiTest)28 Page (org.structr.web.entity.dom.Page)28 Div (org.structr.web.entity.html.Div)28 Body (org.structr.web.entity.html.Body)22 Head (org.structr.web.entity.html.Head)22 Html (org.structr.web.entity.html.Html)22 Content (org.structr.web.entity.dom.Content)11 MailTemplate (org.structr.core.entity.MailTemplate)7 Template (org.structr.web.entity.dom.Template)7 DOMNode (org.structr.web.entity.dom.DOMNode)6 PropertyMap (org.structr.core.property.PropertyMap)5 GraphObject (org.structr.core.GraphObject)3 Principal (org.structr.core.entity.Principal)3 NodeAttribute (org.structr.core.graph.NodeAttribute)3 User (org.structr.web.entity.User)3 Table (org.structr.web.entity.html.Table)3 SecurityContext (org.structr.common.SecurityContext)2