mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-06-18 04:39:45 -04:00
App.isLocalized() marks whether relevant translations are available
!886
This commit is contained in:
@@ -9,6 +9,7 @@ import android.net.Uri;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.TestUtils;
|
||||
import org.fdroid.fdroid.data.Schema.AppMetadataTable.Cols;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -17,7 +18,10 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.fdroid.fdroid.Assert.assertContainsOnly;
|
||||
@@ -36,6 +40,8 @@ public class AppProviderTest extends FDroidProviderTest {
|
||||
|
||||
private static final String[] PROJ = Cols.ALL;
|
||||
|
||||
private static Locale defaultLocale;
|
||||
|
||||
@BeforeClass
|
||||
public static void setRandomTimeZone() {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone(String.format("GMT-%d:%02d",
|
||||
@@ -45,10 +51,16 @@ public class AppProviderTest extends FDroidProviderTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
defaultLocale = Locale.getDefault();
|
||||
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
|
||||
Preferences.setupForTests(context);
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Although this doesn't directly relate to the {@link AppProvider}, it is here because
|
||||
* the {@link AppProvider} used to stumble across this bug when asking for installed apps,
|
||||
@@ -268,6 +280,58 @@ public class AppProviderTest extends FDroidProviderTest {
|
||||
assertEquals("F-Droid", otherApp.name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppSetLocalized() {
|
||||
final String enSummary = "utility for getting information about the APKs that are installed on your device";
|
||||
HashMap<String, Object> en = new HashMap<>();
|
||||
en.put("summary", enSummary);
|
||||
|
||||
final String esSummary = "utilidad para obtener información sobre los APKs instalados en su dispositivo";
|
||||
HashMap<String, Object> es = new HashMap<>();
|
||||
es.put("summary", esSummary);
|
||||
|
||||
final String frSummary = "utilitaire pour obtenir des informations sur les APKs qui sont installés sur vot";
|
||||
HashMap<String, Object> fr = new HashMap<>();
|
||||
fr.put("summary", frSummary);
|
||||
|
||||
final String nlSummary = "hulpprogramma voor het verkrijgen van informatie over de APK die zijn geïnstalle";
|
||||
HashMap<String, Object> nl = new HashMap<>();
|
||||
nl.put("summary", nlSummary);
|
||||
|
||||
App app = new App();
|
||||
Map<String, Map<String, Object>> localized = new HashMap<>();
|
||||
localized.put("es", es);
|
||||
localized.put("fr", fr);
|
||||
|
||||
Locale.setDefault(new Locale("nl", "NL"));
|
||||
app.setLocalized(localized);
|
||||
assertFalse(app.isLocalized);
|
||||
|
||||
localized.put("nl", nl);
|
||||
app.setLocalized(localized);
|
||||
assertTrue(app.isLocalized);
|
||||
assertEquals(nlSummary, app.summary);
|
||||
|
||||
app = new App();
|
||||
localized.clear();
|
||||
localized.put("nl", nl);
|
||||
app.setLocalized(localized);
|
||||
assertTrue(app.isLocalized);
|
||||
|
||||
app = new App();
|
||||
localized.clear();
|
||||
localized.put("en-US", en);
|
||||
app.setLocalized(localized);
|
||||
assertFalse(app.isLocalized);
|
||||
|
||||
Locale.setDefault(new Locale("en", "US"));
|
||||
app = new App();
|
||||
localized.clear();
|
||||
localized.put("en-US", en);
|
||||
app.setLocalized(localized);
|
||||
assertTrue(app.isLocalized);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertTrimsNamesAndSummary() {
|
||||
// Insert a new record with unwanted newlines...
|
||||
|
||||
Reference in New Issue
Block a user