use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class LanguageTest method testTranslateDocument.
@Test
public void testTranslateDocument() throws Exception {
LocalDocumentReference referenceDEFAULT = new LocalDocumentReference("LanguageTest", "Page");
LocalDocumentReference referenceFR = new LocalDocumentReference(referenceDEFAULT, Locale.FRENCH);
// Cleanup
getUtil().rest().delete(referenceFR);
getUtil().rest().delete(referenceDEFAULT);
// Set 2 locales
setLanguageSettings(true, "en", Arrays.asList("en", "fr"));
// Create default version
ViewPage viewPage = getUtil().createPage("LanguageTest", "Page", "en content", "en title");
// Edit the page
WikiEditPage editPage = viewPage.editWiki();
// Make sure current translation is the right one
assertTrue(getDriver().hasElement(By.xpath("//strong[text()='You are editing the original page (en).']")));
assertEquals(Arrays.asList(Locale.FRENCH), editPage.getNotExistingLocales());
assertEquals(Arrays.asList(), editPage.getExistingLocales());
// Translated to French
editPage = editPage.clickTranslate("fr");
editPage.setTitle("titre fr");
editPage.setContent("contenu fr");
viewPage = editPage.clickSaveAndView();
// Make sure both have the right content
Page page = getUtil().rest().get(referenceFR);
assertEquals("titre fr", page.getTitle());
assertEquals("contenu fr", page.getContent());
page = getUtil().rest().get(referenceDEFAULT);
assertEquals("en title", page.getTitle());
assertEquals("en content", page.getContent());
// Make sure two locales are listed for this page in the UI
assertEquals(new HashSet<>(Arrays.asList(Locale.ENGLISH, Locale.FRENCH)), new HashSet<>(viewPage.getLocales()));
// Switch to en
viewPage.clickLocale(Locale.ENGLISH);
// Verify edit mode informations
editPage = viewPage.editWiki();
assertEquals(Arrays.asList(), editPage.getNotExistingLocales());
assertEquals(Arrays.asList(Locale.FRENCH), editPage.getExistingLocales());
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class PreviewTest method previewWithSheet.
/**
* @see "XWIKI-9527: Sheets are not applied on preview action if the document is new"
*/
@Test
public void previewWithSheet() throws Exception {
// Create the class.
getUtil().rest().deletePage(getTestClassName(), getTestMethodName() + "Class");
ClassEditPage classEditor = ClassEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Class");
classEditor.addProperty("color", "String");
// Create the sheet.
getUtil().rest().savePage(new LocalDocumentReference(getTestClassName(), getTestMethodName() + "Sheet"), "{{velocity}}$doc.display('color'){{/velocity}}", "");
// Bind the class to the sheet.
ObjectEditPage objectEditor = ObjectEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Class");
ObjectEditPane objectEditPane = objectEditor.addObject("XWiki.ClassSheetBinding");
objectEditPane.setFieldValue(objectEditPane.byPropertyName("sheet"), getTestClassName() + "." + getTestMethodName() + "Sheet");
objectEditor.clickSaveAndContinue();
// Create the template.
String classFullName = getTestClassName() + "." + getTestMethodName() + "Class";
getUtil().rest().deletePage(getTestClassName(), getTestMethodName() + "Template");
objectEditor = ObjectEditPage.gotoPage(getTestClassName(), getTestMethodName() + "Template");
objectEditPane = objectEditor.addObject(classFullName);
objectEditPane.setFieldValue(objectEditPane.byPropertyName("color"), "red");
objectEditor.clickSaveAndContinue();
// Create the test instance.
getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit", "template=" + getTestClassName() + "." + getTestMethodName() + "Template");
objectEditPane = new ObjectEditPane(new InlinePage().getForm(), classFullName, 0);
objectEditPane.setFieldValue(objectEditPane.byPropertyName("color"), "green");
// Test the preview when the page is not yet saved.
PreviewableEditPage editPage = new PreviewableEditPage();
PreviewEditPage previewPage = editPage.clickPreview();
assertEquals("green", previewPage.getContent());
// Test the preview after the page is saved.
previewPage.clickBackToEdit().clickSaveAndView().editInline().clickPreview();
assertEquals("green", previewPage.getContent());
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class SectionTest method testSectionSaveDoesNotOverwriteTheTitle.
/**
* Verify that the document title is not overwritten when saving a section.
*
* @see <a href="https://jira.xwiki.org/browse/XWIKI-8938">XWIKI-8938: Translated title is overwritten by the default
* translation title when editing a document section</a>
*/
@Test
public void testSectionSaveDoesNotOverwriteTheTitle() throws Exception {
LocalDocumentReference pageReference = new LocalDocumentReference(getTestClassName(), getTestMethodName());
// Create the English version.
setLanguageSettings(false, "en", "en");
getUtil().rest().delete(pageReference);
getUtil().rest().savePage(pageReference, "Original content", "Original title");
try {
// Create the French version.
setLanguageSettings(true, "en", "en,fr");
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("language", "fr");
parameters.put("title", "Translated title");
parameters.put("content", "= Chapter 1 =\n\n Once upon a time ...");
getUtil().gotoPage(pageReference, "save", parameters);
// Switch back to monolingual with French as default language.
setLanguageSettings(false, "fr", "fr");
// Edit and save a document section and check if the document title was overwritten.
getUtil().gotoPage(pageReference, "edit", "editor=wiki§ion=1");
Assert.assertEquals("Translated title", new WikiEditPage().clickSaveAndView().getDocumentTitle());
} finally {
// Restore language settings.
setLanguageSettings(false, "en", "en");
}
}
Aggregations