Search in sources :

Example 1 with IconSet

use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.

the class DefaultIconSetManager method getDefaultIconSet.

@Override
public IconSet getDefaultIconSet() throws IconException {
    XWikiContext xcontext = xcontextProvider.get();
    XWiki xwiki = xcontext.getWiki();
    IconSet iconSet = iconSetCache.get(DEFAULT_ICONSET_NAME);
    if (iconSet == null) {
        try {
            // lazy loading
            iconSet = iconSetLoader.loadIconSet(new InputStreamReader(xwiki.getResourceAsStream("/resources/icons/default.iconset")), DEFAULT_ICONSET_NAME);
            iconSetCache.put(DEFAULT_ICONSET_NAME, iconSet);
        } catch (IconException | MalformedURLException e) {
            throw new IconException("Failed to get the current default icon set.", e);
        }
    }
    return iconSet;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStreamReader(java.io.InputStreamReader) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) IconSet(org.xwiki.icon.IconSet) IconException(org.xwiki.icon.IconException)

Example 2 with IconSet

use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.

the class DefaultIconManagerTest method getIconNames.

@Test
public void getIconNames() throws Exception {
    IconSet iconSet = new IconSet("iconSet1");
    iconSet.addIcon("icon1", new Icon("icon1 value"));
    iconSet.addIcon("icon2", new Icon("icon2 value"));
    // Mocks
    when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet);
    when(iconSetManager.getIconSet("iconSet1")).thenReturn(iconSet);
    // Test
    List<String> results = mocker.getComponentUnderTest().getIconNames();
    List<String> results2 = mocker.getComponentUnderTest().getIconNames("iconSet1");
    // Verify
    assertEquals(2, results.size());
    assertTrue(results.contains("icon1"));
    assertTrue(results.contains("icon2"));
    assertEquals(2, results2.size());
    assertTrue(results2.contains("icon1"));
    assertTrue(results2.contains("icon2"));
}
Also used : Icon(org.xwiki.icon.Icon) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Example 3 with IconSet

use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.

the class DefaultIconManagerTest method render.

@Test
public void render() throws Exception {
    IconSet iconSet = new IconSet("silk");
    iconSet.addIcon("test", new Icon("hello"));
    when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet);
    when(iconRenderer.render("test", iconSet)).thenReturn("rendered icon");
    // Test
    String result = mocker.getComponentUnderTest().render("test");
    assertEquals("rendered icon", result);
}
Also used : Icon(org.xwiki.icon.Icon) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Example 4 with IconSet

use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.

the class DefaultIconManagerTest method renderWithIconSetName.

@Test
public void renderWithIconSetName() throws Exception {
    // Mocks
    IconSet iconSet1 = new IconSet("iconSet1");
    iconSet1.addIcon("icon1", new Icon("icon"));
    when(iconSetManager.getIconSet("iconSet1")).thenReturn(iconSet1);
    when(iconRenderer.render("icon1", iconSet1)).thenReturn("rendered icon 1");
    when(iconRenderer.renderHTML("icon1", iconSet1)).thenReturn("HTML rendered icon 1");
    when(iconRenderer.render("icon2", iconSet1)).thenReturn("");
    when(iconRenderer.renderHTML("icon2", iconSet1)).thenReturn("");
    IconSet defaultIconSet = new IconSet("default");
    defaultIconSet.addIcon("icon2", new Icon("icon"));
    when(iconSetManager.getDefaultIconSet()).thenReturn(defaultIconSet);
    when(iconRenderer.render("icon1", defaultIconSet)).thenReturn("default rendered icon 1");
    when(iconRenderer.render("icon2", defaultIconSet)).thenReturn("default rendered icon 2");
    when(iconRenderer.renderHTML("icon1", defaultIconSet)).thenReturn("HTML default rendered icon 1");
    when(iconRenderer.renderHTML("icon2", defaultIconSet)).thenReturn("HTML default rendered icon 2");
    // Tests
    assertEquals("rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet1"));
    assertEquals("default rendered icon 2", mocker.getComponentUnderTest().render("icon2", "iconSet1"));
    assertEquals("default rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet2"));
    assertEquals("rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet1", true));
    assertEquals("default rendered icon 2", mocker.getComponentUnderTest().render("icon2", "iconSet1", true));
    assertEquals("default rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet2", true));
    assertEquals("rendered icon 1", mocker.getComponentUnderTest().render("icon1", "iconSet1", false));
    assertEquals("", mocker.getComponentUnderTest().render("icon2", "iconSet1", false));
    assertEquals("", mocker.getComponentUnderTest().render("icon1", "iconSet2", false));
    assertEquals("HTML rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet1"));
    assertEquals("HTML default rendered icon 2", mocker.getComponentUnderTest().renderHTML("icon2", "iconSet1"));
    assertEquals("HTML default rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet2"));
    assertEquals("HTML rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet1", true));
    assertEquals("HTML default rendered icon 2", mocker.getComponentUnderTest().renderHTML("icon2", "iconSet1", true));
    assertEquals("HTML default rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet2", true));
    assertEquals("HTML rendered icon 1", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet1", false));
    assertEquals("", mocker.getComponentUnderTest().renderHTML("icon2", "iconSet1", false));
    assertEquals("", mocker.getComponentUnderTest().renderHTML("icon1", "iconSet2", false));
}
Also used : Icon(org.xwiki.icon.Icon) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Example 5 with IconSet

use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.

the class DefaultIconRendererTest method renderHTMLWithCSS.

@Test
public void renderHTMLWithCSS() throws Exception {
    IconSet iconSet = new IconSet("default");
    iconSet.setCss("css");
    iconSet.addIcon("test", new Icon("blabla"));
    when(velocityRenderer.render("css")).thenReturn("velocityParsedCSS");
    // Test
    mocker.getComponentUnderTest().renderHTML("test", iconSet);
    // Verify
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("rel", "stylesheet");
    verify(linkExtension).use(eq("velocityParsedCSS"), eq(parameters));
    verify(skinExtension, never()).use(any());
    verify(jsExtension, never()).use(any());
}
Also used : HashMap(java.util.HashMap) Icon(org.xwiki.icon.Icon) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Aggregations

IconSet (org.xwiki.icon.IconSet)38 Test (org.junit.Test)33 Icon (org.xwiki.icon.Icon)14 DocumentReference (org.xwiki.model.reference.DocumentReference)9 InputStreamReader (java.io.InputStreamReader)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 IconException (org.xwiki.icon.IconException)4 InputStream (java.io.InputStream)2 Reader (java.io.Reader)2 HashMap (java.util.HashMap)2 Query (org.xwiki.query.Query)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Before (org.junit.Before)1 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)1