Search in sources :

Example 56 with LocalDocumentReference

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());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) LocalizationAdministrationSectionPage(org.xwiki.administration.test.po.LocalizationAdministrationSectionPage) Page(org.xwiki.rest.model.jaxb.Page) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) AdministrationPage(org.xwiki.administration.test.po.AdministrationPage) ViewPage(org.xwiki.test.ui.po.ViewPage) ViewPage(org.xwiki.test.ui.po.ViewPage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) Test(org.junit.Test)

Example 57 with LocalDocumentReference

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());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) ObjectEditPane(org.xwiki.test.ui.po.editor.ObjectEditPane) PreviewableEditPage(org.xwiki.test.ui.po.editor.PreviewableEditPage) ClassEditPage(org.xwiki.test.ui.po.editor.ClassEditPage) PreviewEditPage(org.xwiki.test.ui.po.editor.PreviewEditPage) InlinePage(org.xwiki.test.ui.po.InlinePage) ObjectEditPage(org.xwiki.test.ui.po.editor.ObjectEditPage) Test(org.junit.Test)

Example 58 with LocalDocumentReference

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&section=1");
        Assert.assertEquals("Translated title", new WikiEditPage().clickSaveAndView().getDocumentTitle());
    } finally {
        // Restore language settings.
        setLanguageSettings(false, "en", "en");
    }
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) HashMap(java.util.HashMap) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) Test(org.junit.Test)

Aggregations

LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)58 Test (org.junit.Test)28 DocumentReference (org.xwiki.model.reference.DocumentReference)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 BaseObject (com.xpn.xwiki.objects.BaseObject)19 XWikiContext (com.xpn.xwiki.XWikiContext)10 EntityReference (org.xwiki.model.reference.EntityReference)10 ArrayList (java.util.ArrayList)8 ViewPage (org.xwiki.test.ui.po.ViewPage)6 Page (org.xwiki.rest.model.jaxb.Page)5 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)4 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)4 Event (org.xwiki.observation.event.Event)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 Principal (java.security.Principal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2