/** Test {@link UniqueIdFilter}. */
 @Test
 public void duplicateIds() throws Exception {
   String actual = "<p id=\"x\">1</p><p id=\"xy\">2</p><p id=\"x\">3</p>";
   String expected = "<p id=\"x\">1</p><p id=\"xy\">2</p><p id=\"x0\">3</p>";
   HTMLCleanerConfiguration config = this.mocker.getComponentUnderTest().getDefaultConfiguration();
   List<HTMLFilter> filters = new ArrayList<HTMLFilter>(config.getFilters());
   filters.add(this.mocker.<HTMLFilter>getInstance(HTMLFilter.class, "uniqueId"));
   config.setFilters(filters);
   Assert.assertEquals(
       HEADER_FULL + expected + FOOTER,
       HTMLUtils.toString(
           this.mocker.getComponentUnderTest().clean(new StringReader(actual), config)));
 }
  /** Verify that the restricted parameter works. */
  @Test
  public void restrictedHtml() throws ComponentLookupException {
    HTMLCleanerConfiguration configuration =
        this.mocker.getComponentUnderTest().getDefaultConfiguration();
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.putAll(configuration.getParameters());
    parameters.put("restricted", "true");
    configuration.setParameters(parameters);

    String result =
        HTMLUtils.toString(
            this.mocker
                .getComponentUnderTest()
                .clean(new StringReader("<script>alert(\"foo\")</script>"), configuration));
    Assert.assertEquals(HEADER_FULL + "<pre>alert(\"foo\")</pre>" + FOOTER, result);

    result =
        HTMLUtils.toString(
            this.mocker
                .getComponentUnderTest()
                .clean(new StringReader("<style>p {color:white;}</style>"), configuration));
    Assert.assertEquals(HEADER_FULL + "<pre>p {color:white;}</pre>" + FOOTER, result);
  }
 /** Verify that we can control what filters are used for cleaning. */
 @Test
 public void explicitFilterList() throws ComponentLookupException {
   HTMLCleanerConfiguration configuration =
       this.mocker.getComponentUnderTest().getDefaultConfiguration();
   configuration.setFilters(Collections.<HTMLFilter>emptyList());
   String result =
       HTMLUtils.toString(
           this.mocker
               .getComponentUnderTest()
               .clean(new StringReader("something"), configuration));
   // Note that if the default Body filter had been executed the result would have been:
   // <p>something</p>.
   Assert.assertEquals(HEADER_FULL + "something" + FOOTER, result);
 }
 /**
  * Test that cleaning works when there's a TITLE element in the body (but with a namespace). The
  * issue was that HTMLCleaner would consider it a duplicate of the TITLE element in the HEAD even
  * though it's namespaced. (see also <a
  * href="http://jira.xwiki.org/browse/XWIKI-9753">XWIKI-9753</a>).
  */
 @Test
 @Ignore("See http://jira.xwiki.org/browse/XWIKI-9753")
 public void cleanTitleWithNamespace() throws Exception {
   // Test with TITLE in HEAD
   String input =
       "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"
           + "  <head>\n"
           + "    <title>Title test</title>\n"
           + "  </head>\n"
           + "  <body>\n"
           + "    <p>before</p>\n"
           + "    <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"300\" width=\"500\">\n"
           + "      <g>\n"
           + "        <title>SVG Title Demo example</title>\n"
           + "        <rect height=\"50\" style=\"fill:none; stroke:blue; stroke-width:1px\" width=\"200\" x=\"10\" "
           + "y=\"10\"></rect>\n"
           + "      </g>\n"
           + "    </svg>\n"
           + "    <p>after</p>\n";
   Assert.assertEquals(
       HEADER + input + FOOTER,
       HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(input))));
 }
 private void assertHTMLWithHeadContent(String expected, String actual)
     throws ComponentLookupException {
   Assert.assertEquals(
       HEADER + "<html><head>" + expected + "</head><body>" + FOOTER,
       HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(actual))));
 }
 private void assertHTML(String expected, String actual) throws ComponentLookupException {
   Assert.assertEquals(
       HEADER_FULL + expected + FOOTER,
       HTMLUtils.toString(this.mocker.getComponentUnderTest().clean(new StringReader(actual))));
 }