/*
 * 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 com.xpn.xwiki.it.selenium;

import junit.framework.Test;

import com.xpn.xwiki.it.selenium.framework.AbstractXWikiTestCase;
import com.xpn.xwiki.it.selenium.framework.AlbatrossSkinExecutor;
import com.xpn.xwiki.it.selenium.framework.XWikiTestSuite;

/**
 * Verify proper execution of some Velocity Macros.
 *
 * @version $Id: $
 */
public class VelocityMacrosTest extends AbstractXWikiTestCase
{
    public static Test suite()
    {
        XWikiTestSuite suite = new XWikiTestSuite("Tests Velocity Macros");
        suite.addTestSuite(VelocityMacrosTest.class, AlbatrossSkinExecutor.class);
        return suite;
    }

    protected void setUp() throws Exception
    {
        super.setUp();
        loginAsAdmin();
    }

    public void testMacros() throws Exception
    {
        open("/xwiki/bin/edit/Test/VelocityMacrosTest?editor=wiki");

        // TODO: Add more macro tests here (for performance reasons it's much faster to have more
        // tests in a single junit test) and modify thet assert so that it checks for exact content
        setFieldValue("content", "#mimetypeimg(\"image/jpeg\" \"photo.jpeg\")");
        clickEditSaveAndView();
        assertGeneratedHTML("img[@src='/xwiki/skins/albatross/mimetypes/jpg.png' "
            + "and @alt='Image' and @title='Image']");
    }
    
    /**
     * Verify that we can create macros in a document and including them into another document.
     */
    public void testIncludeMacrosInPage()
    {
        open("/xwiki/bin/edit/Test/Macro?editor=wiki");
        setFieldValue("content", "#macro(testIncludeMacrosInPage)hellomacro#end");
        clickEditSaveAndView();
        open("/xwiki/bin/edit/Test/IncludeMacroTest?editor=wiki");
        setFieldValue("content", "#testIncludeMacrosInPage()");
        clickEditSaveAndView();
        assertTextPresent("hellomacro");
    }
}

@@ -2638,16 +2638,48 @@
 ent%22, %22#
+includeMacros(%5C%22Test.Macro%5C%22)%5Cn#
 testIncl
@@ -2777,11 +2777,543 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Verify that a Macro defined in a document is not visible from another document.%0A     */%0A    public void testMacrosAreLocal()%0A    %7B%0A        open(%22/xwiki/bin/edit/Test/TestMacrosAreLocal1?editor=wiki%22);%0A        setFieldValue(%22content%22, %22#macro(testMacrosAreLocal)mymacro#end%22);%0A        clickEditSaveAndView();%0A        open(%22/xwiki/bin/edit/Test/TestMacrosAreLocal2?editor=wiki%22);%0A        setFieldValue(%22content%22, %22#testMacrosAreLocal()%22);%0A        clickEditSaveAndView();%0A        assertTextNotPresent(%22mymacro%22);%0A    %7D
 %0A%7D%0A

Replace current Velocity configuration code by a Velocity Component