コード例 #1
0
  public void testSwitchOrderOfRenderers() throws Exception {
    String text = "#set($x = '<' + '% println(\"hello world\"); %' + '>')\n$x";
    String velocityFirst = "hello world";
    String groovyFirst = "<% println(\"hello world\"); %>";

    XWikiDocument document = new XWikiDocument();

    // Prove that the renderers are in the right order by default.
    assertEquals(
        engine.getRendererNames(),
        new ArrayList<String>() {
          {
            add("mapping");
            add("groovy");
            add("velocity");
            add("plugin");
            add("wiki");
            add("xwiki");
          }
        });

    assertEquals(groovyFirst, engine.renderText(text, document, getContext()));

    xwiki
        .getConfig()
        .put(
            "xwiki.render.renderingorder",
            "macromapping, velocity, groovy, plugin, wiki, wikiwiki");

    DefaultXWikiRenderingEngine myEngine = new DefaultXWikiRenderingEngine(xwiki, getContext());

    assertEquals(
        myEngine.getRendererNames(),
        new ArrayList<String>() {
          {
            add("mapping");
            add("velocity");
            add("groovy");
            add("plugin");
            add("wiki");
            add("xwiki");
          }
        });

    assertEquals(velocityFirst, myEngine.renderText(text, document, getContext()));
  }
コード例 #2
0
  /** Test that links are preserved after rendering. XWIKI-2672 */
  public void testLinksAndCache() throws Exception {
    String link = "http://some:123/link";
    String text = "$context.setCacheDuration(1800)\n" + link;
    XWikiDocument document = new XWikiDocument();

    Utils.enablePlaceholders(getContext());
    String out = engine.renderText(text, document, getContext());
    assertTrue(out.contains(link));
  }
コード例 #3
0
  public void testRenderTextWhenUsingCodeMacro() throws Exception {
    // We verify that the code macro doesn't render wiki markup, velocity, HTML, or other radeox
    // macros.
    // We also ensure that any Radeox macro coming after the code macro is rendered properly.
    // Last we also ensure that a second code macro works too.
    String text =
        "{code:none}\n"
            + "1 Title\n"
            + "c:\\dev\n"
            + "#info(\"test\")\n"
            + "<pre>hello</pre>\n"
            + "$xwiki.getVersion()\n"
            + "{style}style{style}\n"
            + "&#123;code}nested&#123;code}\n"
            + "<% print(\"hello\") %>\n"
            + "{code}\n"
            + "{table}\n"
            + "a | b\n"
            + "c | d\n"
            + "{table}\n"
            + "#set ($var = 'dummy')\n"
            + "{code:none}\n"
            + "1 Something\n"
            + "{code}";

    String expectedText =
        "<div class=\"code\"><pre>1 Title\n"
            + "c:&#92;dev\n"
            + "&#35;info(\"test\")\n"
            + "&#60;pre&#62;hello&#60;/pre&#62;\n"
            + "&#36;xwiki.getVersion()\n"
            + "&#123;style&#125;style&#123;style&#125;\n"
            + "&&#35;123;code&#125;nested&&#35;123;code&#125;\n"
            + "&#60;% print(\"hello\") %&#62;</pre></div>\n"
            + "<table class=\"wiki-table\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><th>a</th>"
            + "<th>b</th></tr><tr class=\"table-odd\"><td>c</td><td>d</td></tr></table>\n"
            + "<div class=\"code\"><pre>1 Something</pre></div>";

    XWikiDocument document = new XWikiDocument();
    assertEquals(expectedText, engine.renderText(text, document, getContext()));
  }
コード例 #4
0
 public void testRenderGroovy() throws Exception {
   assertEquals(
       "hello world",
       engine.renderText("<% println(\"hello world\"); %>", new XWikiDocument(), getContext()));
 }