Search in sources :

Example 1 with Content

use of org.structr.web.entity.dom.Content in project structr by structr.

the class DeploymentTest method test31RoundtripWithEmptyContentElements.

@Test
public void test31RoundtripWithEmptyContentElements() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test31");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test31");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Div div2 = createElement(page, div1, "div", "");
        final Table table1 = createElement(page, div2, "table");
        final Thead thead = createElement(page, table1, "thead");
        final Tbody tbody = createElement(page, table1, "tbody");
        final Tr tr1 = createElement(page, thead, "tr");
        final Tr tr2 = createElement(page, tbody, "tr");
        final Td td11 = createElement(page, tr1, "td");
        final Content c1 = createContent(page, td11, "");
        final Td td12 = createElement(page, tr1, "td", "content12");
        final P p1 = createElement(page, td12, "p", "");
        final Ul ul = createElement(page, p1, "ul");
        final Li li = createElement(page, ul, "li", "");
        final Td td21 = createElement(page, tr2, "td", "content21");
        final Td td22 = createElement(page, tr2, "td", "content22");
        final Select select = createElement(page, td11, "select");
        final Option option1 = createElement(page, select, "option", "");
        final Option option2 = createElement(page, select, "option", "value2");
        final Content c2 = createContent(page, div2, "");
        final Table table2 = createElement(page, div2, "table");
        // include visibility flags
        page.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
        c1.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
        c2.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
        // modify visibility to produce two consecutive deployment instruction comments
        td12.setProperty(AbstractNode.visibleToPublicUsers, true);
        table2.setProperty(AbstractNode.visibleToPublicUsers, true);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    compare(calculateHash(), true);
}
Also used : Head(org.structr.web.entity.html.Head) Table(org.structr.web.entity.html.Table) Tx(org.structr.core.graph.Tx) Thead(org.structr.web.entity.html.Thead) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Div(org.structr.web.entity.html.Div) Td(org.structr.web.entity.html.Td) P(org.structr.web.entity.html.P) Content(org.structr.web.entity.dom.Content) Ul(org.structr.web.entity.html.Ul) Select(org.structr.web.entity.html.Select) Option(org.structr.web.entity.html.Option) Tbody(org.structr.web.entity.html.Tbody) Body(org.structr.web.entity.html.Body) Li(org.structr.web.entity.html.Li) Tr(org.structr.web.entity.html.Tr) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 2 with Content

use of org.structr.web.entity.dom.Content in project structr by structr.

the class DeploymentTest method test21ExportGrants.

@Test
public void test21ExportGrants() {
    Principal user1 = null;
    Principal user2 = null;
    try (final Tx tx = app.tx()) {
        user1 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
        user2 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
        tx.success();
    } catch (FrameworkException ex) {
        fail("Unexpected exception.");
    }
    Assert.assertNotNull("User was not created, test cannot continue", user1);
    Assert.assertNotNull("User was not created, test cannot continue", user2);
    // setup
    final SecurityContext context1 = SecurityContext.getInstance(user1, AccessMode.Backend);
    final App app1 = StructrApp.getInstance(context1);
    try (final Tx tx = app1.tx()) {
        final Page page = Page.createNewPage(context1, "test21");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test21");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Content content = createContent(page, div1, "<b>Test</b>");
        content.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
        // create grants
        page.grant(Permission.read, user2);
        div1.grant(Permission.read, user2);
        content.grant(Permission.read, user2);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true, false);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) NodeAttribute(org.structr.core.graph.NodeAttribute) Head(org.structr.web.entity.html.Head) User(org.structr.web.entity.User) 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) Div(org.structr.web.entity.html.Div) Content(org.structr.web.entity.dom.Content) SecurityContext(org.structr.common.SecurityContext) Body(org.structr.web.entity.html.Body) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 3 with Content

use of org.structr.web.entity.dom.Content in project structr by structr.

the class DeploymentTest method test26Escaping.

@Test
public void test26Escaping() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test25");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test25");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Content content1 = createContent(page, div1, "<div><script>var test = '<h3>Title</h3>';</script></div>");
        content1.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    compare(calculateHash(), true);
}
Also used : Div(org.structr.web.entity.html.Div) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 4 with Content

use of org.structr.web.entity.dom.Content in project structr by structr.

the class DeploymentTest method test03ContentTypes.

@Test
public void test03ContentTypes() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test03");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test03");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Script script = createElement(page, div1, "script");
        final Content content = createContent(page, script, "$(function () {\n\n" + "$('a[data-toggle=\"tab\"]').on('click', function (e) {\n\n" + "var id = $(e.target).attr(\"href\").substr(1) // activated tab\n" + "window.location.hash = id;\n" + "});\n\n" + "});");
        // workaround for strange importer behaviour
        script.setProperty(StructrApp.key(Script.class, "_html_type"), "text/javascript");
        content.setProperty(StructrApp.key(Content.class, "contentType"), "text/javascript");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true);
}
Also used : Div(org.structr.web.entity.html.Div) Script(org.structr.web.entity.html.Script) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 5 with Content

use of org.structr.web.entity.dom.Content in project structr by structr.

the class DeploymentTest method test20ExportOwnership.

@Test
public void test20ExportOwnership() {
    Principal user1 = null;
    Principal user2 = null;
    try (final Tx tx = app.tx()) {
        user1 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
        user2 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
        tx.success();
    } catch (FrameworkException ex) {
        fail("Unexpected exception.");
    }
    Assert.assertNotNull("User was not created, test cannot continue", user1);
    Assert.assertNotNull("User was not created, test cannot continue", user2);
    // setup
    final SecurityContext context1 = SecurityContext.getInstance(user1, AccessMode.Backend);
    final App app1 = StructrApp.getInstance(context1);
    try (final Tx tx = app1.tx()) {
        final Page page = Page.createNewPage(context1, "test20");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test20");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Content content = createContent(page, div1, "<b>Test</b>");
        content.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
        // set owner to different user
        div1.setProperty(AbstractNode.owner, user2);
        content.setProperty(AbstractNode.owner, user2);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true, false);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) NodeAttribute(org.structr.core.graph.NodeAttribute) Head(org.structr.web.entity.html.Head) User(org.structr.web.entity.User) 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) Div(org.structr.web.entity.html.Div) Content(org.structr.web.entity.dom.Content) SecurityContext(org.structr.common.SecurityContext) Body(org.structr.web.entity.html.Body) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Content (org.structr.web.entity.dom.Content)14 Test (org.junit.Test)12 FrameworkException (org.structr.common.error.FrameworkException)12 Tx (org.structr.core.graph.Tx)12 StructrUiTest (org.structr.web.StructrUiTest)12 Page (org.structr.web.entity.dom.Page)12 Div (org.structr.web.entity.html.Div)11 Body (org.structr.web.entity.html.Body)8 Head (org.structr.web.entity.html.Head)8 Html (org.structr.web.entity.html.Html)7 NodeAttribute (org.structr.core.graph.NodeAttribute)3 DOMNode (org.structr.web.entity.dom.DOMNode)3 SecurityContext (org.structr.common.SecurityContext)2 App (org.structr.core.app.App)2 StructrApp (org.structr.core.app.StructrApp)2 Principal (org.structr.core.entity.Principal)2 User (org.structr.web.entity.User)2 Table (org.structr.web.entity.html.Table)2 IOException (java.io.IOException)1 Attribute (org.jsoup.nodes.Attribute)1