@Test public void itHasExtendsReferenceInContext() throws Exception { RenderResult renderResult = jinjava.renderForResult(locator.fixture("super-child.html"), new HashMap<String, Object>()); SetMultimap<String, String> dependencies = renderResult.getContext().getDependencies(); assertThat(dependencies.size()).isEqualTo(1); assertThat(dependencies.get("coded_files")).isNotEmpty(); assertThat(dependencies.get("coded_files").contains("super-base.html")); }
@Test public void nestedExtendsHierarchy() throws Exception { String result = jinjava.render(locator.fixture("extends-base2.jinja"), new HashMap<String, Object>()); Document dom = Jsoup.parse(result); assertThat(dom.select(".important").get(0).text()).isEqualTo("foobar"); }
@Test public void singleExtendsTag() throws Exception { String result = jinjava.render(locator.fixture("extends-base1.jinja"), new HashMap<String, Object>()); Document dom = Jsoup.parse(result); assertThat(dom.select(".important").get(0).text()).isEqualTo("Welcome on my awesome homepage."); }
@Test public void itAvoidsNestedExtendsCycles() throws IOException { try { jinjava.render(locator.fixture("a-extends-b.jinja"), new HashMap<String, Object>()); fail("expected extends tag cycle exception"); } catch (FatalTemplateErrorsException e) { TagCycleException cycleException = (TagCycleException) e.getErrors().iterator().next().getException(); assertThat(cycleException.getPath()).isEqualTo("b-extends-a.jinja"); } }
@Test public void extendsWithSuperCall() throws Exception { Document dom = Jsoup.parse(jinjava.render(locator.fixture("super-child.html"), new HashMap<String, Object>())); assertThat(dom.select(".sidebar p").text()).isEqualTo("this is a sidebar."); assertThat(dom.select(".sidebar h3").text()).isEqualTo("Table Of Contents"); }
@Test public void itAvoidsNestedExtendsCycles() throws IOException { try { jinjava.render(locator.fixture("a-extends-b.jinja"), new HashMap<String, Object>()); fail("expected extends tag cycle exception"); } catch (FatalTemplateErrorsException e) { TagCycleException cycleException = (TagCycleException) e.getErrors().iterator().next().getException(); assertThat(cycleException.getPath()).isEqualTo("b-extends-a.jinja"); } }
@Override public String getString(String fullName, Charset encoding, JinjavaInterpreter interpreter) throws IOException { return fixture(fullName); }
@Test public void itAvoidsSimpleExtendsCycles() throws IOException { try { jinjava.render(locator.fixture("extends-self.jinja"), new HashMap<String, Object>()); fail("expected extends tag cycle exception"); } catch (FatalTemplateErrorsException e) { TagCycleException cycleException = (TagCycleException) e.getErrors().iterator().next().getException(); assertThat(cycleException.getPath()).isEqualTo("extends-self.jinja"); } }
@Test public void parentTemplateImportsVarsUsedInChild() throws Exception { Document dom = Jsoup.parse(jinjava.render(locator.fixture("parentvars-child.html"), new HashMap<String, Object>())); assertThat(dom.select("body").attr("bgcolor")).isEqualTo("#f5f5f5"); assertThat(dom.select("p.foo").text()).isEqualTo("bar"); }
@Test public void singleExtendsTag() throws Exception { String result = jinjava.render(locator.fixture("extends-base1.jinja"), new HashMap<String, Object>()); Document dom = Jsoup.parse(result); assertThat(dom.select(".important").get(0).text()).isEqualTo("Welcome on my awesome homepage."); }
@Test public void extendsWithSuperCall() throws Exception { Document dom = Jsoup.parse(jinjava.render(locator.fixture("super-child.html"), new HashMap<String, Object>())); assertThat(dom.select(".sidebar p").text()).isEqualTo("this is a sidebar."); assertThat(dom.select(".sidebar h3").text()).isEqualTo("Table Of Contents"); }
@Test public void parentTemplateImportsVarsUsedInChild() throws Exception { Document dom = Jsoup.parse(jinjava.render(locator.fixture("parentvars-child.html"), new HashMap<String, Object>())); assertThat(dom.select("body").attr("bgcolor")).isEqualTo("#f5f5f5"); assertThat(dom.select("p.foo").text()).isEqualTo("bar"); }
@Before public void setup() { locator = new ExtendsTagTestResourceLocator(); JinjavaConfig conf = new JinjavaConfig(); jinjava = new Jinjava(conf); jinjava.setResourceLocator(locator); }
@Override public String getString(String fullName, Charset encoding, JinjavaInterpreter interpreter) throws IOException { return fixture(fullName); }
@Test public void itHasExtendsReferenceInContext() throws Exception { RenderResult renderResult = jinjava.renderForResult(locator.fixture("super-child.html"), new HashMap<String, Object>()); SetMultimap<String, String> dependencies = renderResult.getContext().getDependencies(); assertThat(dependencies.size()).isEqualTo(1); assertThat(dependencies.get("coded_files")).isNotEmpty(); assertThat(dependencies.get("coded_files").contains("super-base.html")); }
@Test public void nestedExtendsHierarchy() throws Exception { String result = jinjava.render(locator.fixture("extends-base2.jinja"), new HashMap<String, Object>()); Document dom = Jsoup.parse(result); assertThat(dom.select(".important").get(0).text()).isEqualTo("foobar"); }
@Test public void itAvoidsSimpleExtendsCycles() throws IOException { try { jinjava.render(locator.fixture("extends-self.jinja"), new HashMap<String, Object>()); fail("expected extends tag cycle exception"); } catch (FatalTemplateErrorsException e) { TagCycleException cycleException = (TagCycleException) e.getErrors().iterator().next().getException(); assertThat(cycleException.getPath()).isEqualTo("extends-self.jinja"); } }
@Before public void setup() { locator = new ExtendsTagTestResourceLocator(); JinjavaConfig conf = new JinjavaConfig(); jinjava = new Jinjava(conf); jinjava.setResourceLocator(locator); }