Search in sources :

Example 1 with WikiMacroManager

use of org.xwiki.rendering.macro.wikibridge.WikiMacroManager 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");
}
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)

Example 2 with WikiMacroManager

use of org.xwiki.rendering.macro.wikibridge.WikiMacroManager 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"));
}
Also used : WikiMacroFactory(org.xwiki.rendering.macro.wikibridge.WikiMacroFactory) ModelContext(org.xwiki.model.ModelContext) Macro(org.xwiki.rendering.macro.Macro) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Test(org.junit.Test)

Example 3 with WikiMacroManager

use of org.xwiki.rendering.macro.wikibridge.WikiMacroManager 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)3 WikiMacroFactory (org.xwiki.rendering.macro.wikibridge.WikiMacroFactory)3 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