use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class AbstractXWikiPreferencesConfigurationSource method getBaseObject.
@Override
protected BaseObject getBaseObject() throws XWikiException {
XWikiContext xcontext = this.xcontextProvider.get();
if (xcontext != null && xcontext.getWiki() != null) {
DocumentReference documentReference = getFailsafeDocumentReference();
LocalDocumentReference classReference = getFailsafeClassReference();
if (documentReference != null && classReference != null) {
XWikiDocument document = xcontext.getWiki().getDocument(getDocumentReference(), xcontext);
// First we try to get a translated preference object
BaseObject object = getBaseObject(document, xcontext.getLanguage());
if (object != null) {
return object;
}
return document.getXObject(classReference);
}
}
return null;
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class ColorThemeListenerTest method onEventWhenColorThemeChanged.
@Test
public void onEventWhenColorThemeChanged() throws Exception {
// Mocks
Event event = mock(Event.class);
XWikiDocument doc = mock(XWikiDocument.class);
Object data = new Object();
EntityReference classReference = new LocalDocumentReference("ColorThemes", "ColorThemeClass");
List<BaseObject> objects = new ArrayList<>();
BaseObject object = mock(BaseObject.class);
objects.add(object);
when(doc.getXObjects(classReference)).thenReturn(objects);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
when(doc.getDocumentReference()).thenReturn(documentReference);
ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null);
when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference);
// Test
mocker.getComponentUnderTest().onEvent(event, doc, data);
// Verify
verify(lessResourcesCache).clearFromColorTheme(colorThemeReference);
verify(colorThemeCache).clearFromColorTheme(colorThemeReference);
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class ColorThemeListenerTest method onEventWhenFlamingoThemeChanged.
@Test
public void onEventWhenFlamingoThemeChanged() throws Exception {
// Mocks
Event event = mock(Event.class);
XWikiDocument doc = mock(XWikiDocument.class);
Object data = new Object();
EntityReference classReference = new LocalDocumentReference("FlamingoThemesCode", "ThemeClass");
List<BaseObject> objects = new ArrayList<>();
BaseObject object = mock(BaseObject.class);
objects.add(object);
when(doc.getXObjects(classReference)).thenReturn(objects);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
when(doc.getDocumentReference()).thenReturn(documentReference);
ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null);
when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference);
// Test
mocker.getComponentUnderTest().onEvent(event, doc, data);
// Verify
verify(lessResourcesCache).clearFromColorTheme(colorThemeReference);
verify(colorThemeCache).clearFromColorTheme(colorThemeReference);
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XWikiAuthServiceImplTest method testLoginWithWikiPrefix.
/**
* Test that SomeUser is correctly authenticated as XWiki.SomeUser when xwiki:SomeUser is entered as username.
*/
@Test
public void testLoginWithWikiPrefix() throws Exception {
// Setup a simple user profile document
XWikiDocument userDoc = new XWikiDocument(new DocumentReference(this.oldcore.getXWikiContext().getWikiId(), "XWiki", "SomeUser"));
BaseObject mockUserObj = userDoc.newXObject(new LocalDocumentReference("XWiki", "XWikiUsers"), this.oldcore.getXWikiContext());
mockUserObj.setStringValue("password", "pass");
// Save the user
this.oldcore.getSpyXWiki().saveDocument(userDoc, this.oldcore.getXWikiContext());
// Finally run the test: Using xwiki:Admin should correctly authenticate the Admin user
Principal principal = this.authService.authenticate("xwiki:SomeUser", "pass", this.oldcore.getXWikiContext());
assertNotNull(principal);
assertEquals("xwiki:XWiki.SomeUser", principal.getName());
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XWikiServletURLFactoryTest method createWiki.
/**
* Creates a new sub-wiki with the given name.
*
* @param wikiName the wiki name
* @throws Exception if creating the wiki fails
*/
private void createWiki(String wikiName) throws Exception {
String wikiDocName = "XWikiServer" + wikiName.substring(0, 1).toUpperCase() + wikiName.substring(1);
XWikiDocument wikiDoc = this.oldcore.getSpyXWiki().getDocument(new DocumentReference(MAIN_WIKI_NAME, "XWiki", wikiDocName), this.oldcore.getXWikiContext());
BaseObject wikiObj = wikiDoc.newXObject(new LocalDocumentReference("XWiki", "XWikiServerClass"), this.oldcore.getXWikiContext());
wikiObj.setStringValue("server", wikiName + "server");
this.oldcore.getSpyXWiki().saveDocument(wikiDoc, this.oldcore.getXWikiContext());
}
Aggregations