use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class XWikiLinkLabelGeneratorTest method generateWhenNestedPage.
@Test
public void generateWhenNestedPage() throws Exception {
ResourceReference resourceReference = new DocumentResourceReference("WebHome");
DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("space1", "NestedPage"), "WebHome");
EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
DocumentModelBridge dmb = mock(DocumentModelBridge.class);
when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(dmb);
when(dmb.getTitle()).thenReturn("My title");
EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
when(localSerializer.serialize(new SpaceReference("wiki", "space1", "NestedPage"))).thenReturn("space1.NestedPage");
assertEquals("%l%la%n%na%N%NA " + "[wiki:space1.NestedPage.WebHome] NestedPage NestedPage Web Home Nested Page (My title) " + "[wiki:space1.NestedPage.WebHome] NestedPage NestedPage Web Home Nested Page (My title)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class XWikiLinkLabelGeneratorTest method generateWhenDocumentFailsToLoad.
@Test
public void generateWhenDocumentFailsToLoad() throws Exception {
ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
DocumentReference documentReference = new DocumentReference("xwiki", "Main", "HelloWorld");
EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
when(dab.getTranslatedDocumentInstance(documentReference)).thenThrow(new Exception("error"));
EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
when(localSerializer.serialize(new SpaceReference("xwiki", "Main"))).thenReturn("Main");
assertEquals("%l%la%n%na%N%NA " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld) " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class DefaultWikiMacroManagerTest method registerAndUnregisterWikiMacroWhenGlobalVisibilityAndAllowed.
@Test
public void registerAndUnregisterWikiMacroWhenGlobalVisibilityAndAllowed() throws Exception {
DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.GLOBAL);
// Simulate a user who's allowed for the GLOBAL visibility
WikiMacroFactory wikiMacroFactory = this.mocker.getInstance(WikiMacroFactory.class);
when(wikiMacroFactory.isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.GLOBAL)).thenReturn(true);
WikiMacroManager wikiMacroManager = this.mocker.getComponentUnderTest();
assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
EntityReferenceSerializer<String> serializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
when(serializer.serialize(this.authorReference)).thenReturn("authorwiki:authorspace.authorpage");
// Test registration
wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
assertTrue(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
// Verify that the WikiMacroManager has registered the macro against the root CM
assertTrue(this.mocker.hasComponent(Macro.class, "testwikimacro"));
// Verify that the user and wiki where the macro is located have been set in the context
DocumentAccessBridge bridge = this.mocker.getInstance(DocumentAccessBridge.class);
verify(bridge).setCurrentUser("authorwiki:authorspace.authorpage");
ModelContext modelContext = this.mocker.getInstance(ModelContext.class);
verify(modelContext).setCurrentEntityReference(wikiMacro.getDocumentReference());
// Test unregistration
wikiMacroManager.unregisterWikiMacro(wikiMacro.getDocumentReference());
assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
// Verify that the WikiMacroManager has unregistered the macro from the root CM
assertFalse(this.mocker.hasComponent(Macro.class, "testwikimacro"));
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class DefaultSheetManagerTest method configure.
@Before
public void configure() throws Exception {
documentAccessBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
documentSheetBinder = getComponentManager().getInstance(SheetBinder.class, "document");
classSheetBinder = getComponentManager().getInstance(SheetBinder.class, "class");
modelBridge = getComponentManager().getInstance(ModelBridge.class);
document = getMockery().mock(DocumentModelBridge.class);
final Execution execution = getComponentManager().getInstance(Execution.class);
getMockery().checking(new Expectations() {
{
allowing(execution).getContext();
will(returnValue(context));
allowing(document).getDocumentReference();
will(returnValue(new DocumentReference(WIKI_NAME, "Space", "Page")));
}
});
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class SpacePreferencesConfigurationSourceTest method before.
@Override
public void before() throws Exception {
super.before();
DocumentAccessBridge documentAccessBridge = this.componentManager.getInstance(DocumentAccessBridge.class);
when(documentAccessBridge.getCurrentDocumentReference()).thenReturn(SPACE_DOCUMENT);
}
Aggregations