use of org.xwiki.rendering.macro.wikibridge.WikiMacroFactory in project xwiki-platform by xwiki.
the class DefaultWikiMacroManagerTest method registerWikiMacroWhenUserVisibilityAndAllowed.
@Test
public void registerWikiMacroWhenUserVisibilityAndAllowed() throws Exception {
DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.USER);
// Simulate a user who's allowed for the USER visibility
WikiMacroFactory wikiMacroFactory = this.mocker.getInstance(WikiMacroFactory.class);
when(wikiMacroFactory.isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.USER)).thenReturn(true);
ComponentManager userComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "user");
// 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 user CM
verify(userComponentManager).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 user CM
verify(userComponentManager).unregisterComponent(Macro.class, "testwikimacro");
}
Aggregations