Index: src/test/java/com/xpn/xwiki/XWikiTest.java
===================================================================
--- src/test/java/com/xpn/xwiki/XWikiTest.java	(révision 4466)
+++ src/test/java/com/xpn/xwiki/XWikiTest.java	(copie de travail)
@@ -52,14 +52,21 @@
 
     private Mock mockXWikiVersioningStore;
 
-    private Map docs = new HashMap();
+    private Map databases = new HashMap();
 
+    private static final String WIKI_NAME = "xwiki";
+    
+    private static final String TARGET_WIKI_NAME = "targetWiki";
+    
     protected void setUp() throws XWikiException
     {
         this.context = new XWikiContext();
         this.document = new XWikiDocument("MilkyWay", "Fidis");
         this.xwiki = new XWiki(new XWikiConfig(), this.context);
 
+        this.databases.put(WIKI_NAME, new HashMap());
+        this.databases.put(TARGET_WIKI_NAME, new HashMap());
+        
         this.mockXWikiStore =
             mock(XWikiHibernateStore.class, new Class[] {XWiki.class, XWikiContext.class},
                 new Object[] {this.xwiki, this.context});
@@ -69,11 +76,30 @@
                 public Object invoke(Invocation invocation) throws Throwable
                 {
                     XWikiDocument shallowDoc = (XWikiDocument) invocation.parameterValues.get(0);
+                    XWikiContext context = (XWikiContext) invocation.parameterValues.get(1);
+                    
+                    String database = context.getDatabase();
+                    
+                    if (database == null || database.length() == 0)
+                        database = WIKI_NAME;
+                    
+                    if (!databases.containsKey(database))
+                        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETE_DATABASE,
+                            "Database " + database + " does not exists.");
+                    
+                    Map docs = (Map)databases.get(database);
+                    
+                    XWikiDocument document = null;
+                    
                     if (docs.containsKey(shallowDoc.getName())) {
-                        return (XWikiDocument) docs.get(shallowDoc.getName());
+                        document = (XWikiDocument) docs.get(shallowDoc.getName());
                     } else {
-                        return shallowDoc;
+                        document = shallowDoc;
                     }
+                    
+                    document.setDatabase(context.getDatabase());
+                    
+                    return document;
                 }
             });
         this.mockXWikiStore.stubs().method("saveXWikiDoc").will(
@@ -82,9 +108,25 @@
                 public Object invoke(Invocation invocation) throws Throwable
                 {
                     XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0);
+                    XWikiContext context = (XWikiContext) invocation.parameterValues.get(1);
+                    
+                    String database = context.getDatabase();
+                    
+                    if (database == null || database.length() == 0)
+                        database = WIKI_NAME;
+                    
+                    if (!databases.containsKey(database))
+                        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETE_DATABASE,
+                            "Database " + database + " does not exists.");
+                    
+                    Map docs = (Map)databases.get(database);
+                    
                     document.setNew(false);
+                    document.setDatabase(context.getDatabase());
                     document.setStore((XWikiStoreInterface) mockXWikiStore.proxy());
+                    
                     docs.put(document.getName(), document);
+                    
                     return null;
                 }
             });
@@ -142,4 +184,48 @@
 
         assertTrue(copy.getCreationDate().equals(sourceCreationDate));
     }
+    
+    public void testContentAfterDocumentCopy() throws XWikiException
+    {
+        String copyName = this.document.getName() + "Copy";
+        this.xwiki.copyDocument(this.document.getName(), this.document.getSpace() + "."
+            + copyName, this.context);
+        XWikiDocument copy = this.xwiki.getDocument(copyName, context);
+        
+        assertEquals(this.document.getContent(), copy.getContent());
+    }
+    
+    public void testContentAfterDocumentCopyInclude() throws XWikiException
+    {
+        String database = this.context.getDatabase();
+        
+        this.context.setDatabase(null);
+
+        String fullCopyName = this.document.getSpace() + "." + this.document.getName() + "Copy";
+        this.xwiki.copyDocument(this.document.getFullName(), fullCopyName, true, null, null, null, false, true, false, this.context);
+        XWikiDocument copy = this.xwiki.getDocument(fullCopyName, context);
+
+        assertEquals("#includeInContext(\"" + document.getFullName() + "\")", copy.getContent());
+        
+        this.context.setDatabase(database);
+    }
+    
+    public void testContentAfterDocumentCopyIncludeVirtual() throws XWikiException
+    {
+        String database = this.context.getDatabase();
+        boolean virtual = this.context.isVirtual();
+        
+        this.context.setDatabase(WIKI_NAME);
+        this.context.setVirtual(true);
+
+        String fullCopyName = this.document.getSpace() + "." + this.document.getName() + "Copy";
+        this.xwiki.copyDocument(this.document.getName(), fullCopyName, true, WIKI_NAME, TARGET_WIKI_NAME, null, false, true, false, this.context);
+        XWikiDocument copy = this.xwiki.getDocument(TARGET_WIKI_NAME+":" + fullCopyName, context);
+
+        assertEquals("#includeInContext(\"" + WIKI_NAME+":"
+            + document.getFullName() + "\")", copy.getContent());
+        
+        this.context.setDatabase(database);
+        this.context.setVirtual(virtual);
+    }
 }
Index: src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- src/main/java/com/xpn/xwiki/XWiki.java	(révision 4466)
+++ src/main/java/com/xpn/xwiki/XWiki.java	(copie de travail)
@@ -3301,19 +3301,33 @@
             false, context);
     }
 
-    public boolean copyDocument(String docname, String targetdocname, String sourceWiki,
-        String targetWiki, String wikilanguage, boolean reset, boolean force, XWikiContext context)
-        throws XWikiException
-    {
-        return copyDocument(docname, targetdocname, sourceWiki, targetWiki, wikilanguage, reset, force,
-            false, context);
-    }
+    public boolean copyDocument(String docname, String targetdocname,
+			String sourceWiki, String targetWiki, String wikilanguage,
+			boolean reset, boolean force, XWikiContext context)
+			throws XWikiException {
+		return copyDocument(docname, targetdocname, sourceWiki, targetWiki,
+				wikilanguage, reset, force, false, context);
+	}
 
-    public boolean copyDocument(String docname, String targetdocname, String sourceWiki,
-        String targetWiki, String wikilanguage, boolean reset, boolean force, boolean resetCreationData,
-        XWikiContext context)
-        throws XWikiException
-    {
+	public boolean copyDocument(String docname, String targetdocname,
+			String sourceWiki, String targetWiki, String wikilanguage,
+			boolean reset, boolean force, boolean resetCreationData,
+			XWikiContext context) throws XWikiException {
+		return copyDocument(docname, targetdocname, false, sourceWiki,
+				targetWiki, wikilanguage, reset, force, resetCreationData,
+				context);
+	}
+
+	public boolean copyDocument(String docname, String targetdocname,
+			boolean includeContent, String sourceWiki, String targetWiki,
+			String wikilanguage, boolean reset, boolean force,
+			boolean resetCreationData, XWikiContext context)
+			throws XWikiException {
+		if (includeContent) {
+			reset = true;
+			wikilanguage = null;
+		}
+
         String db = context.getDatabase();
         if (sourceWiki == null)
             sourceWiki = db;
@@ -3346,7 +3360,7 @@
                     context.setDatabase(sourceWiki);
 
                 if (wikilanguage == null) {
-                    tdoc = sdoc.copyDocument(targetdocname, context);
+                    tdoc = sdoc.copyDocument(targetdocname, includeContent, context);
                     // forget past versions
                     if (reset) {
                         tdoc.setVersion("1.1");
