Skip to content
Snippets Groups Projects
Commit 3203d264 authored by Simon Urli's avatar Simon Urli
Browse files

XWIKI-20651: Pt_br (Pt_br) and Zh_tw (Zh_Tw) languages displayed in drop-downs...

XWIKI-20651: Pt_br (Pt_br) and Zh_tw (Zh_Tw) languages displayed in drop-downs which cause many "Invalid locale" warnings if selected

  * Improve dateFormat test to force the timezone so that it covers this
    and don't fail on CI because of bad offset
parent b6948032
No related branches found
No related tags found
No related merge requests found
......@@ -54,6 +54,8 @@
import org.xwiki.test.annotation.AllComponents;
import org.xwiki.test.junit5.mockito.MockComponent;
import org.xwiki.test.mockito.MockitoComponentManager;
import org.xwiki.user.CurrentUserReference;
import org.xwiki.user.UserProperties;
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
......@@ -1113,12 +1115,15 @@ void atomicRename() throws Exception
void formatDate()
{
Date date = new Date(1718887539000L);
String expectedResult = "2024/06/20 14:45";
String expectedResult = "2024/06/20 12:45";
this.oldcore.getMockWikiConfigurationSource().setProperty("default_language", "fr_CA");
this.oldcore.getMockXWikiCfg().setProperty("xwiki.timezone", "BRT");
when(this.oldcore.getMockAllUserPropertiesResolver().resolve(CurrentUserReference.INSTANCE))
.thenReturn(mock(UserProperties.class));
assertEquals(expectedResult, this.xwiki.formatDate(date, null, this.oldcore.getXWikiContext()));
String format = "EEEE dd MMMM YYYY HH:mm:ss";
assertEquals("jeudi 20 juin 2024 14:45:39",
assertEquals("jeudi 20 juin 2024 12:45:39",
this.xwiki.formatDate(date, format, this.oldcore.getXWikiContext()));
}
}
......@@ -82,6 +82,7 @@
import org.xwiki.test.internal.MockConfigurationSource;
import org.xwiki.test.mockito.MockitoComponentManager;
import org.xwiki.url.URLConfiguration;
import org.xwiki.user.UserPropertiesResolver;
import org.xwiki.user.UserReference;
import org.xwiki.user.UserReferenceResolver;
import org.xwiki.user.UserReferenceSerializer;
......@@ -206,6 +207,8 @@ public class MockitoOldcore
private UserReferenceSerializer<DocumentReference> documentReferenceUserReferenceSerializer;
private UserPropertiesResolver allUserPropertiesResolver;
/**
* @version $Id$
* @since 15.5RC1
......@@ -1123,6 +1126,12 @@ public String answer(InvocationOnMock invocation) throws Throwable
getMocker().getInstance(userReferenceDocumentReferenceSerializer, "document");
}
if (!this.componentManager.hasComponent(UserPropertiesResolver.class, "all")) {
this.allUserPropertiesResolver = getMocker().registerMockComponent(UserPropertiesResolver.class, "all");
} else {
this.allUserPropertiesResolver = getMocker().getInstance(UserPropertiesResolver.class, "all");
}
// we ensure that when trying to resolve a DocumentReference to UserReference, then the returned mock
// will return the original DocumentReference when resolved back to DocumentReference.
when(userReferenceResolver.resolve(any()))
......@@ -1423,4 +1432,9 @@ public void registerMockEnvironment() throws Exception
when(this.environment.getTemporaryDirectory()).thenReturn(this.temporaryDirectory);
when(this.environment.getPermanentDirectory()).thenReturn(this.permanentDirectory);
}
public UserPropertiesResolver getMockAllUserPropertiesResolver()
{
return this.allUserPropertiesResolver;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment