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;
}
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"));
}
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);
}
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));
}
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());
}
Aggregations