On Wed, May 6, 2009 at 16:24, vmassol <[email protected]> wrote:
> Author: vmassol
> Date: 2009-05-06 16:24:58 +0200 (Wed, 06 May 2009)
> New Revision: 19431
>
> Added:
>   
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/HTMLMacroTest.java
>   
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/MockDocumentAccessBridge.java
>   
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/MockDocumentNameSerializer.java
> Modified:
>   
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/pom.xml
>   
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/main/java/org/xwiki/rendering/internal/macro/html/HTMLMacro.java
> Log:
> XWIKI-3764: Modify behavior of HTML macro when it's set to contain wiki syntax
>
> * Fixed regression where non inline content in inline context was allowed to 
> go through
>
> Merged from trunk (rev 19430)
>
>
> Modified: 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/pom.xml
> ===================================================================
> --- 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/pom.xml
>      2009-05-06 14:23:02 UTC (rev 19430)
> +++ 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/pom.xml
>      2009-05-06 14:24:58 UTC (rev 19431)
> @@ -42,6 +42,19 @@
>       <groupId>org.wikimodel</groupId>
>       <artifactId>org.wikimodel.wem</artifactId>
>     </dependency>
> +    <!-- Testing dependencies -->
> +    <dependency>
> +      <groupId>org.xwiki.platform</groupId>
> +      <artifactId>xwiki-core-shared-tests</artifactId>
> +      <version>${pom.version}</version>
> +      <scope>test</scope>
> +    </dependency>

This dependency is already in xwiki-core-rendering-macros-parent

> +    <dependency>
> +      <groupId>jmock</groupId>
> +      <artifactId>jmock</artifactId>
> +      <version>1.1.0</version>
> +      <scope>test</scope>
> +    </dependency>
>   </dependencies>
>   <build>
>     <plugins>
> @@ -49,9 +62,9 @@
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-surefire-plugin</artifactId>
>         <configuration>
> -          <includes>
> -            <include>**/RenderingTests.java</include>
> -          </includes>
> +          <excludes>
> +            <exclude>**/Mock*.java</exclude>
> +          </excludes>
>         </configuration>
>       </plugin>
>       <plugin>
>
> Modified: 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/main/java/org/xwiki/rendering/internal/macro/html/HTMLMacro.java
> ===================================================================
> --- 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/main/java/org/xwiki/rendering/internal/macro/html/HTMLMacro.java
>         2009-05-06 14:23:02 UTC (rev 19430)
> +++ 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/main/java/org/xwiki/rendering/internal/macro/html/HTMLMacro.java
>         2009-05-06 14:24:58 UTC (rev 19431)
> @@ -26,6 +26,8 @@
>
>  import org.apache.commons.lang.StringUtils;
>  import org.w3c.dom.Document;
> +import org.w3c.dom.Element;
> +import org.w3c.dom.Node;
>  import org.xwiki.bridge.DocumentAccessBridge;
>  import org.xwiki.bridge.DocumentNameSerializer;
>  import org.xwiki.component.annotation.Component;
> @@ -193,8 +195,9 @@
>      * @param isInline true if the content is inline and thus if we need to 
> remove the top level paragraph
>      *        element created by the cleaner
>      * @return the cleaned HTML as a string representing valid XHTML
> +     * @throws MacroExecutionException if the macro is inline and the 
> content is not inline HTML
>      */
> -    private String cleanHTML(String content, boolean isInline)
> +    private String cleanHTML(String content, boolean isInline) throws 
> MacroExecutionException
>     {
>         String cleanedContent = content;
>
> @@ -216,9 +219,20 @@
>         // HTML envelope when rendered. We remove it so that the HTML <head> 
> tag isn't output.
>         HTMLUtils.stripHTMLEnvelope(document);
>
> -        // If in inline mode remove the top level paragraph if there's one.
> +        // If in inline mode verify we have inline HTML content and remove 
> the top level paragraph if there's one
>         if (isInline) {
> -            HTMLUtils.stripFirstElementInside(document, 
> HTMLConstants.TAG_HTML, HTMLConstants.TAG_P);
> +            // TODO: Improve this since when're inside a table cell or a 
> list item we can allow non inline items too
> +            Element root = document.getDocumentElement();
> +            if (root.getChildNodes().getLength() == 1 && 
> root.getFirstChild().getNodeType() == Node.ELEMENT_NODE
> +                && root.getFirstChild().getNodeName().equalsIgnoreCase("p"))
> +            {
> +                HTMLUtils.stripFirstElementInside(document, 
> HTMLConstants.TAG_HTML, HTMLConstants.TAG_P);
> +            } else {
> +                throw new MacroExecutionException(
> +                    "When using the HTML macro inline, you can only use 
> inline HTML content."
> +                        + " Block HTML content (such as tables) cannot be 
> displayed."
> +                        + " Try leaving an empty line before and after the 
> HTML macro.");
> +            }
>         }
>
>         // Don't print the XML declaration nor the XHTML DocType.
>
> Added: 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/HTMLMacroTest.java
> ===================================================================
> --- 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/HTMLMacroTest.java
>                                 (rev 0)
> +++ 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/HTMLMacroTest.java
>         2009-05-06 14:24:58 UTC (rev 19431)
> @@ -0,0 +1,69 @@
> +/*
> + * See the NOTICE file distributed with this work for additional
> + * information regarding copyright ownership.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as
> + * published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This software is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this software; if not, write to the Free
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> + */
> +package org.xwiki.rendering;
> +
> +import org.xwiki.rendering.internal.macro.html.HTMLMacro;
> +import org.xwiki.rendering.macro.Macro;
> +import org.xwiki.rendering.macro.MacroExecutionException;
> +import org.xwiki.rendering.macro.html.HTMLMacroParameters;
> +import org.xwiki.rendering.scaffolding.MockDocumentNameSerializer;
> +import org.xwiki.rendering.transformation.MacroTransformationContext;
> +import org.xwiki.test.AbstractXWikiComponentTestCase;
> +
> +/**
> + * Unit tests for {...@link HTMLMacro} that cannot be performed using the 
> Rendering Test framework.
> + *
> + * @version $Id: $
> + * @since 1.8.3
> + */
> +public class HTMLMacroTest extends AbstractXWikiComponentTestCase
> +{
> +    /**
> +     * {...@inheritdoc}
> +     *
> +     * @see com.xpn.xwiki.test.AbstractXWikiComponentTestCase#setUp()
> +     */
> +   �...@override
> +    protected void setUp() throws Exception
> +    {
> +        super.setUp();
> +        
> getComponentManager().registerComponent(MockDocumentAccessBridge.getComponentDescriptor());
> +        
> getComponentManager().registerComponent(MockDocumentNameSerializer.getComponentDescriptor());
> +    }
> +
> +    /**
> +     * Verify that inline HTML macros with non inline content generate an 
> exception.
> +     */
> +    public void testHTMLMacroWhenNonInlineContentInInlineContext() throws 
> Exception
> +    {
> +        HTMLMacro macro = (HTMLMacro) 
> getComponentManager().lookup(Macro.class.getName(), "html");
> +        HTMLMacroParameters parameters = new HTMLMacroParameters();
> +        MacroTransformationContext context = new 
> MacroTransformationContext();
> +        context.setInline(true);
> +        try {
> +            macro.execute(parameters, "<ul><li>item</li></ul>", context);
> +            fail("Should have thrown an exception here");
> +        } catch (MacroExecutionException expected) {
> +            assertEquals("When using the HTML macro inline, you can only use 
> inline HTML content. Block HTML "
> +                + "content (such as tables) cannot be displayed. Try leaving 
> an empty line before and after the "
> +                + "HTML macro.", expected.getMessage());
> +        }
> +    }
> +}
>
> Added: 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/MockDocumentAccessBridge.java
> ===================================================================
> --- 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/MockDocumentAccessBridge.java
>                              (rev 0)
> +++ 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/MockDocumentAccessBridge.java
>      2009-05-06 14:24:58 UTC (rev 19431)
> @@ -0,0 +1,271 @@
> +/*
> + * See the NOTICE file distributed with this work for additional
> + * information regarding copyright ownership.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as
> + * published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This software is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this software; if not, write to the Free
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> + */
> +package org.xwiki.rendering;
> +
> +import java.util.Map;
> +
> +import org.xwiki.bridge.DocumentAccessBridge;
> +import org.xwiki.bridge.DocumentModelBridge;
> +import org.xwiki.bridge.DocumentName;
> +import org.xwiki.component.descriptor.ComponentDescriptor;
> +import org.xwiki.component.descriptor.DefaultComponentDescriptor;
> +
> +/**
> + * Mock {...@link DocumentAccessBridge} implementation used for testing, 
> since we don't want to pull any dependency on the
> + * Model/Skin/etc for the Rendering module's unit tests.
> + *
> + * @version $Id: $
> + * @since 1.8.3
> + */
> +public class MockDocumentAccessBridge implements DocumentAccessBridge
> +{
> +    /**
> +     * Create and return a descriptor for this component.
> +     *
> +     * @return the descriptor of the component.
> +     */
> +    public static ComponentDescriptor getComponentDescriptor()
> +    {
> +        DefaultComponentDescriptor componentDescriptor = new 
> DefaultComponentDescriptor();
> +
> +        componentDescriptor.setRole(DocumentAccessBridge.class);
> +        
> componentDescriptor.setImplementation(MockDocumentAccessBridge.class.getName());
> +
> +        return componentDescriptor;
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getDocumentContent(String documentName) throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getDocumentContent(String documentName, String language) 
> throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public boolean exists(String documentName)
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getURL(String documentName, String action, String 
> queryString, String anchor)
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getAttachmentURL(String documentName, String 
> attachmentName)
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getProperty(String documentName, String className, int 
> objectNumber, String propertyName)
> +        throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getProperty(String documentName, String className, String 
> propertyName) throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getProperty(String documentName, String propertyName) 
> throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getPropertyType(String className, String propertyName) 
> throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public boolean isPropertyCustomMapped(String className, String 
> propertyName) throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public void setProperty(String documentName, String className, String 
> propertyName, Object propertyValue)
> +        throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public byte[] getAttachmentContent(String documentName, String 
> attachmentName) throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public boolean hasProgrammingRights()
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getDocumentContentForDefaultLanguage(String arg0) throws 
> Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public boolean isDocumentViewable(String arg0)
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getCurrentUser()
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getDefaultEncoding()
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public String getDocumentSyntaxId(String arg0) throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public boolean isDocumentEditable(String arg0)
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public void setAttachmentContent(String arg0, String arg1, byte[] arg2) 
> throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public void setDocumentContent(String arg0, String arg1, String arg2, 
> boolean arg3) throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public void setDocumentSyntaxId(String arg0, String arg1) throws 
> Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public DocumentModelBridge getDocument(String documentName) throws 
> Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public DocumentName getDocumentName(String documentName)
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public DocumentName getCurrentDocumentName()
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public void popDocumentFromContext(Map<String, Object> backupObjects)
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     */
> +    public void pushDocumentInContext(Map<String, Object> backupObjects, 
> String documentName) throws Exception
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +}
>
> Added: 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/MockDocumentNameSerializer.java
> ===================================================================
> --- 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/MockDocumentNameSerializer.java
>                            (rev 0)
> +++ 
> platform/core/branches/xwiki-core-1.8/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/test/java/org/xwiki/rendering/MockDocumentNameSerializer.java
>    2009-05-06 14:24:58 UTC (rev 19431)
> @@ -0,0 +1,61 @@
> +/*
> + * See the NOTICE file distributed with this work for additional
> + * information regarding copyright ownership.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as
> + * published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This software is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this software; if not, write to the Free
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> + */
> +package org.xwiki.rendering;
> +
> +import org.xwiki.bridge.DocumentAccessBridge;
> +import org.xwiki.bridge.DocumentName;
> +import org.xwiki.bridge.DocumentNameSerializer;
> +import org.xwiki.component.descriptor.ComponentDescriptor;
> +import org.xwiki.component.descriptor.DefaultComponentDescriptor;
> +
> +/**
> + * Mock {...@link DocumentAccessBridge} implementation used for testing, 
> since we don't want to pull any dependency on the
> + * Model/Skin/etc for the Rendering module's unit tests.
> + *
> + * @version $Id: MockDocumentNameSerializer.java 19152 2009-04-27 21:02:41Z 
> tmortagne $
> + * @since 1.9M2
> + */
> +public class MockDocumentNameSerializer implements DocumentNameSerializer
> +{
> +    /**
> +     * Create and return a descriptor for this component.
> +     *
> +     * @return the descriptor of the component.
> +     */
> +    public static ComponentDescriptor getComponentDescriptor()
> +    {
> +        DefaultComponentDescriptor componentDescriptor = new 
> DefaultComponentDescriptor();
> +
> +        componentDescriptor.setRole(DocumentNameSerializer.class);
> +        
> componentDescriptor.setImplementation(MockDocumentNameSerializer.class.getName());
> +
> +        return componentDescriptor;
> +    }
> +
> +    /**
> +     * {...@inheritdoc}
> +     *
> +     * @see 
> org.xwiki.bridge.DocumentNameSerializer#serialize(org.xwiki.bridge.DocumentName)
> +     */
> +    public String serialize(DocumentName documentName)
> +    {
> +        throw new RuntimeException("Not implemented");
> +    }
> +}
>
> _______________________________________________
> notifications mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/notifications
>



-- 
Thomas Mortagne
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to