Search in sources :

Example 6 with WikiMacroFactory

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");
}
Also used : WikiMacroFactory(org.xwiki.rendering.macro.wikibridge.WikiMacroFactory) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) ComponentManager(org.xwiki.component.manager.ComponentManager) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 WikiMacroFactory (org.xwiki.rendering.macro.wikibridge.WikiMacroFactory)6 WikiMacroManager (org.xwiki.rendering.macro.wikibridge.WikiMacroManager)3 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)2 ComponentManager (org.xwiki.component.manager.ComponentManager)2 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)1 ModelContext (org.xwiki.model.ModelContext)1 Macro (org.xwiki.rendering.macro.Macro)1