use of org.xwiki.rendering.macro.wikibridge.WikiMacroFactory in project xwiki-platform by xwiki.
the class DefaultWikiMacroManagerTest method registerWikiMacroWhenUserVisibilityAndNotAllowed.
@Test(expected = InsufficientPrivilegesException.class)
public void registerWikiMacroWhenUserVisibilityAndNotAllowed() throws Exception {
DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.USER);
// Simulate a user who's not allowed for the USER visibility
WikiMacroFactory wikiMacroFactory = this.mocker.getInstance(WikiMacroFactory.class);
when(wikiMacroFactory.isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.USER)).thenReturn(false);
this.mocker.getComponentUnderTest().registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
}
use of org.xwiki.rendering.macro.wikibridge.WikiMacroFactory in project xwiki-platform by xwiki.
the class DefaultWikiMacroManagerTest method registerWikiMacroWhenWikiVisibilityAndAllowed.
@Test
public void registerWikiMacroWhenWikiVisibilityAndAllowed() throws Exception {
DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.WIKI);
// Simulate a user who's allowed for the WIKI visibility
WikiMacroFactory wikiMacroFactory = this.mocker.getInstance(WikiMacroFactory.class);
when(wikiMacroFactory.isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.WIKI)).thenReturn(true);
ComponentManager wikiComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "wiki");
// Test registration
WikiMacroManager wikiMacroManager = this.mocker.getComponentUnderTest();
wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
assertTrue(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
// Verify that the WikiMacroManager has registered the macro against the wiki CM
verify(wikiComponentManager).registerComponent(any(DefaultComponentDescriptor.class), eq(wikiMacro));
// Test unregistration
wikiMacroManager.unregisterWikiMacro(wikiMacro.getDocumentReference());
assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
// Verify that the WikiMacroManager has unregistered the macro against the wiki CM
verify(wikiComponentManager).unregisterComponent(Macro.class, "testwikimacro");
}
use of org.xwiki.rendering.macro.wikibridge.WikiMacroFactory in project xwiki-platform by xwiki.
the class DefaultWikiMacroManagerTest method registerWikiMacroWhenWikiVisibilityAndNotAllowed.
@Test(expected = InsufficientPrivilegesException.class)
public void registerWikiMacroWhenWikiVisibilityAndNotAllowed() throws Exception {
DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.WIKI);
// Simulate a user who's not allowed for the WIKI visibility
WikiMacroFactory wikiMacroFactory = this.mocker.getInstance(WikiMacroFactory.class);
when(wikiMacroFactory.isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.WIKI)).thenReturn(false);
this.mocker.getComponentUnderTest().registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
}
use of org.xwiki.rendering.macro.wikibridge.WikiMacroFactory 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.rendering.macro.wikibridge.WikiMacroFactory in project xwiki-platform by xwiki.
the class DefaultWikiMacroManagerTest method registerWikiMacroWhenGlobalVisibilityAndNotAllowed.
@Test(expected = InsufficientPrivilegesException.class)
public void registerWikiMacroWhenGlobalVisibilityAndNotAllowed() throws Exception {
DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.GLOBAL);
// Simulate a user who's not allowed for the GLOBAL visibility
WikiMacroFactory wikiMacroFactory = this.mocker.getInstance(WikiMacroFactory.class);
when(wikiMacroFactory.isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.GLOBAL)).thenReturn(false);
this.mocker.getComponentUnderTest().registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
}
Aggregations