use of org.xwiki.lesscss.internal.colortheme.ColorTheme in project xwiki-platform by xwiki.
the class DefaultLESSColorThemeConverterTest method getColorThemeFromSkinFileWhenInCache.
@Test
public void getColorThemeFromSkinFileWhenInCache() throws Exception {
// Mocks
ColorTheme cachedColorTheme = new ColorTheme();
cachedColorTheme.put("key", "value1");
LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("file", null, null);
when(lessResourceReferenceFactory.createReferenceForSkinFile("file")).thenReturn(lessSkinFileResourceReference);
when(cache.get(eq(lessSkinFileResourceReference), eq(new FSSkinReference("skin")), eq(new NamedColorThemeReference("colorTheme")))).thenReturn(cachedColorTheme);
// Test
ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("file", "skin", false);
// Verify
assertEquals(cachedColorTheme, result);
// Verify that the returned value is not the instance stored in the cache (that the end-user would wrongly be
// able to modify)
assertTrue(result != cachedColorTheme);
// Be extra-sure :)
result.put("key", "value2");
assertNotEquals("value2", cachedColorTheme.get("key"));
}
use of org.xwiki.lesscss.internal.colortheme.ColorTheme in project xwiki-platform by xwiki.
the class CachedLESSColorThemeConverter method getColorThemeFromCSS.
/**
* Parse a CSS and returns a Color Theme.
* @param css code to parse
* @return the corresponding color theme
*/
private ColorTheme getColorThemeFromCSS(String css) {
ColorTheme results = new ColorTheme();
String cssWithoutComments = css.replaceAll("/\\*[\\u0000-\\uffff]*?\\*/", "");
Matcher m = pattern.matcher(cssWithoutComments);
while (m.find()) {
String variable = m.group(1);
String value = m.group(3);
results.put(variable, value);
}
return results;
}
use of org.xwiki.lesscss.internal.colortheme.ColorTheme in project xwiki-platform by xwiki.
the class LessCompilerScriptServiceTest method getColorThemeFromSkinFileWithException.
@Test
public void getColorThemeFromSkinFileWithException() throws Exception {
// Mocks
Exception exception = new LESSCompilerException("Exception with LESS", null);
when(lessColorThemeConverter.getColorThemeFromSkinFile("style.less", false)).thenThrow(exception);
// Test
ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("style.less");
// Verify
assertEquals(0, result.size());
}
use of org.xwiki.lesscss.internal.colortheme.ColorTheme in project xwiki-platform by xwiki.
the class LessCompilerScriptServiceTest method getColorThemeFromSkinFileWithOtherSkinAndException.
@Test
public void getColorThemeFromSkinFileWithOtherSkinAndException() throws Exception {
// Mocks
Exception exception = new LESSCompilerException("Exception with LESS", null);
when(lessColorThemeConverter.getColorThemeFromSkinFile("style.less", "flamingo", false)).thenThrow(exception);
// Test
ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("style.less", "flamingo");
// Verify
assertEquals(0, result.size());
}
Aggregations