r1364 - in xwiki/trunk/src: main/java/com/xpn/xwiki/doc test/cactus/com/xpn/xwiki/test
Phung Hai Nam
namphunghai at users.forge.objectweb.org
Thu Oct 5 04:30:00 CEST 2006
Author: namphunghai
Date: 2006-10-05 04:29:59 +0200 (Thu, 05 Oct 2006)
New Revision: 1364
Modified:
xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletSectionEditTest.java
Log:
Fixed bug XWIKI-353 and add a test for SectionEditTest.java: "The problem is that when saving the first section, everything above the document title disappears."
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-10-04 15:04:19 UTC (rev 1363)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-10-05 02:29:59 UTC (rev 1364)
@@ -2792,7 +2792,7 @@
// This function to update a section content in document
public String updateDocumentSection(int sectionNumber , String newSectionContent) throws XWikiException {
- String newContent;
+ StringBuffer newContent = new StringBuffer();
// get document section that will be edited
DocumentSection docSection = getDocumentSection(sectionNumber);
int numberOfSection = getSplitSectionsAccordingToTitle().size();
@@ -2803,7 +2803,8 @@
} else if (sectionNumber == numberOfSection) {
// edit lastest section that doesn't contain subtitle
String contentBegin = getContent().substring(0,indexSection);
- return contentBegin + newSectionContent;
+ newContent = newContent.append(contentBegin).append(newSectionContent);
+ return newContent.toString();
} else {
String sectionLevel = docSection.getSectionLevel();
int nextSectionIndex = 0;
@@ -2819,17 +2820,15 @@
break;
}
}
- if (nextSectionIndex == 0) // edit the last section
- return getContent().substring(0,indexSection) + newSectionContent;
- if (sectionNumber == 1) { // edit the first section
- String contentAfter = getContent().substring(nextSectionIndex);
- newContent = newSectionContent + contentAfter;
+ if (nextSectionIndex == 0) {// edit the last section
+ newContent = newContent.append(getContent().substring(0,indexSection)).append(newSectionContent);
+ return newContent.toString();
} else {
String contentAfter = getContent().substring(nextSectionIndex);
String contentBegin = getContent().substring(0, indexSection);
- newContent = contentBegin + newSectionContent + contentAfter;
+ newContent = newContent.append(contentBegin).append(newSectionContent).append(contentAfter);
}
- return newContent;
+ return newContent.toString();
}
}
Modified: xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletSectionEditTest.java
===================================================================
--- xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletSectionEditTest.java 2006-10-04 15:04:19 UTC (rev 1363)
+++ xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletSectionEditTest.java 2006-10-05 02:29:59 UTC (rev 1364)
@@ -104,6 +104,36 @@
launchTest();
}
+ /** Test edit section for title 1 */
+ public void beginSectionEditTitle1WithContentAbove(WebRequest webRequest) throws HibernateException, XWikiException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+ XWikiDocument doc = new XWikiDocument();
+ Utils.prepareObject(doc, "Main.SectionEditTest");
+ BaseClass bclass = doc.getxWikiClass();
+ BaseObject bobject = doc.getObject(bclass.getName(), 0);
+
+ String content = "This is the content above\n1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1 This is the title 2\nThis is the content of title 2";
+ Utils.createDoc(xwiki.getStore(), "Main", "SectionEditTest", content, bobject, bclass, context);
+ setUrl(webRequest, "edit", "Main", "SectionEditTest", "section=1");
+ }
+
+ public void endSectionEditTitle1WithContentAbove(WebResponse webResponse) throws HibernateException {
+ try {
+ String result = webResponse.getText();
+ assertTrue("Could not find the contents of title 1 : " + result, result.indexOf("1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1") != -1);
+ assertTrue("Find out the contents above title :" + result, result.indexOf("This is the content above") == -1);
+ assertTrue("Find out the contents of title 2 :" + result, result.indexOf("1 This is the title 2\nThis is the content of title 2") == -1);
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testSectionEditTitle1WithContentAbove() throws Throwable {
+ launchTest();
+ }
+
/** Test edit section for subtitle 1 */
public void beginSectionEditSubtitle1(WebRequest webRequest) throws HibernateException, XWikiException {
XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
@@ -237,6 +267,46 @@
launchTest();
}
+ /** Test save a section title after edit it */
+ public void beginSaveSectionWithContentAbove(WebRequest webRequest) throws HibernateException, XWikiException {
+ XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+ StoreHibernateTest.cleanUp(hibstore, context);
+ clientSetUp(hibstore);
+ XWikiDocument doc = new XWikiDocument();
+ Utils.prepareObject(doc, "Main.SaveSectionWithContentAboveTest");
+ BaseClass bclass = doc.getxWikiClass();
+ BaseObject bobject = doc.getObject(bclass.getName(), 0);
+
+ String content = "This is content above first section\n1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1 This is the title 2\nThis is the content of title 2";
+ Utils.createDoc(xwiki.getStore(), "Main", "SaveSectionWithContentAboveTest", content, bobject, bclass, context);
+
+ // Save section 1 with new content.
+ setUrl(webRequest, "save", "SaveSectionWithContentAboveTest", "section=1");
+ webRequest.addParameter("content", "This is modification");
+ webRequest.addParameter("parent", "Main.WebHome");
+ }
+
+ public void endSaveSectionWithContentAbove(WebResponse webResponse) throws HibernateException, XWikiException {
+ try {
+ String result = webResponse.getText();
+ // Verify return
+ assertTrue("Saving returned exception: " + result, result.indexOf("Exception") == -1);
+ // Flush cache to make sure we read from db
+ xwiki.flushCache();
+
+ XWikiDocument doc = xwiki.getDocument("Main.SaveSectionWithContentAboveTest", context);
+ String content = doc.getContent();
+ assertEquals("Content is not indentical", "This is content above first section\nThis is modification\n1 This is the title 2\nThis is the content of title 2", content);
+ assertEquals("Parent is not identical", "Main.WebHome", doc.getParent());
+ } finally {
+ clientTearDown();
+ }
+ }
+
+ public void testSaveSectionWithContentAbove() throws Throwable {
+ launchTest();
+ }
+
/** Test save a section subtitle after edit it */
public void beginSaveSectionSubTitle(WebRequest webRequest) throws HibernateException, XWikiException {
XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
More information about the Xwiki-notifications
mailing list