assertEquals(p2, paragraphs.item(1));
assertEquals(p3, paragraphs.item(2));
assertEquals(p4, paragraphs.item(3));
// create users
final User tester1 = app.create(User.class, new NodeAttribute<>(User.name, "tester1"), new NodeAttribute<>(User.eMail, "tester1@test.com"));
final User tester2 = app.create(User.class, new NodeAttribute<>(User.name, "tester2"), new NodeAttribute<>(User.eMail, "tester2@test.com"));
assertNotNull("User tester1 should exist.", tester1);
assertNotNull("User tester2 should exist.", tester2);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
final RenderContext ctx = new RenderContext();
ctx.setPage(page);
// test for "empty" return value
assertEquals("", p1.replaceVariables(securityContext, ctx, "${err}"));
assertEquals("", p1.replaceVariables(securityContext, ctx, "${this.error}"));
assertEquals("", p1.replaceVariables(securityContext, ctx, "${this.this.this.error}"));
assertEquals("", p1.replaceVariables(securityContext, ctx, "${parent.error}"));
assertEquals("", p1.replaceVariables(securityContext, ctx, "${this.owner}"));
assertEquals("", p1.replaceVariables(securityContext, ctx, "${parent.owner}"));
// other functions are tested in the ActionContextTest in structr-core, see there.
assertEquals("true", p1.replaceVariables(securityContext, ctx, "${true}"));
assertEquals("false", p1.replaceVariables(securityContext, ctx, "${false}"));
assertEquals("yes", p1.replaceVariables(securityContext, ctx, "${if(true, \"yes\", \"no\")}"));
assertEquals("no", p1.replaceVariables(securityContext, ctx, "${if(false, \"yes\", \"no\")}"));
assertEquals("true", p1.replaceVariables(securityContext, ctx, "${if(true, true, false)}"));
assertEquals("false", p1.replaceVariables(securityContext, ctx, "${if(false, true, false)}"));
assertEquals("${element} should evaluate to the current DOM node", p1.toString(), p1.replaceVariables(securityContext, ctx, "${element}"));
assertNull(p1.replaceVariables(securityContext, ctx, "${if(true, null, \"no\")}"));
assertNull(p1.replaceVariables(securityContext, ctx, "${null}"));
assertEquals("Invalid replacement result", "/testpage?" + page.getUuid(), p1.replaceVariables(securityContext, ctx, "/${page.name}?${page.id}"));
assertEquals("Invalid replacement result", "/testpage?" + page.getUuid(), a.replaceVariables(securityContext, ctx, "/${link.name}?${link.id}"));
// these tests find single element => success
assertEquals("Invalid replacement result", page.getUuid(), a.replaceVariables(securityContext, ctx, "${get(find('Page', 'name', 'testpage'), 'id')}"));
assertEquals("Invalid replacement result", a.getUuid(), a.replaceVariables(securityContext, ctx, "${get(find('A'), 'id')}"));
// this test finds multiple <p> elements => error
assertEquals("Invalid replacement result", Functions.ERROR_MESSAGE_GET_ENTITY, a.replaceVariables(securityContext, ctx, "${get(find('P'), 'id')}"));
// more complex replacement
//assertEquals("Invalid replacement result", "", a.replaceVariables(securityContext, ctx, "${get(find('P'), 'id')}"));
// String default value
assertEquals("bar", p1.replaceVariables(securityContext, ctx, "${request.foo!bar}"));
// Number default value (will be evaluated to a string)
assertEquals("1", p1.replaceVariables(securityContext, ctx, "${page.position!1}"));
// Number default value
assertEquals("true", p1.replaceVariables(securityContext, ctx, "${equal(42, this.null!42)}"));
final User tester1 = app.nodeQuery(User.class).andName("tester1").getFirst();
final User tester2 = app.nodeQuery(User.class).andName("tester2").getFirst();
assertNotNull("User tester1 should exist.", tester1);
assertNotNull("User tester2 should exist.", tester2);
final SecurityContext tester1Context = SecurityContext.getInstance(tester1, AccessMode.Backend);