Added test to ensure categories are remoed when a repo is disabled.
This will help diagnose, test, and prevent regressions of #806.
This commit is contained in:
parent
99216d923a
commit
5be23b793e
@ -275,10 +275,14 @@ public class AppProviderTest extends FDroidProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static App insertApp(ShadowContentResolver contentResolver, Context context, String id, String name, ContentValues additionalValues) {
|
public static App insertApp(ShadowContentResolver contentResolver, Context context, String id, String name, ContentValues additionalValues) {
|
||||||
|
return insertApp(contentResolver, context, id, name, additionalValues, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static App insertApp(ShadowContentResolver contentResolver, Context context, String id, String name, ContentValues additionalValues, long repoId) {
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(Cols.Package.PACKAGE_NAME, id);
|
values.put(Cols.Package.PACKAGE_NAME, id);
|
||||||
values.put(Cols.REPO_ID, 1);
|
values.put(Cols.REPO_ID, repoId);
|
||||||
values.put(Cols.NAME, name);
|
values.put(Cols.NAME, name);
|
||||||
|
|
||||||
// Required fields (NOT NULL in the database).
|
// Required fields (NOT NULL in the database).
|
||||||
|
@ -8,6 +8,7 @@ import android.net.Uri;
|
|||||||
import org.fdroid.fdroid.BuildConfig;
|
import org.fdroid.fdroid.BuildConfig;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.data.Schema.AppMetadataTable.Cols;
|
import org.fdroid.fdroid.data.Schema.AppMetadataTable.Cols;
|
||||||
|
import org.fdroid.fdroid.mock.MockRepo;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -107,9 +108,11 @@ public class CategoryProviderTest extends FDroidProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCategoriesMultiple() {
|
public void testCategoriesMultiple() {
|
||||||
insertAppWithCategory("com.rock.dog", "Rock-Dog", "Mineral,Animal");
|
long mainRepo = 1;
|
||||||
insertAppWithCategory("com.dog.rock.apple", "Dog-Rock-Apple", "Animal,Mineral,Vegetable");
|
|
||||||
insertAppWithCategory("com.banana.apple", "Banana", "Vegetable,Vegetable");
|
insertAppWithCategory("com.rock.dog", "Rock-Dog", "Mineral,Animal", mainRepo);
|
||||||
|
insertAppWithCategory("com.dog.rock.apple", "Dog-Rock-Apple", "Animal,Mineral,Vegetable", mainRepo);
|
||||||
|
insertAppWithCategory("com.banana.apple", "Banana", "Vegetable,Vegetable", mainRepo);
|
||||||
|
|
||||||
List<String> categories = CategoryProvider.Helper.categories(context);
|
List<String> categories = CategoryProvider.Helper.categories(context);
|
||||||
String[] expected = new String[] {
|
String[] expected = new String[] {
|
||||||
@ -123,9 +126,11 @@ public class CategoryProviderTest extends FDroidProviderTest {
|
|||||||
};
|
};
|
||||||
assertContainsOnly(categories, expected);
|
assertContainsOnly(categories, expected);
|
||||||
|
|
||||||
|
int additionalRepo = 2;
|
||||||
|
|
||||||
insertAppWithCategory("com.example.game", "Game",
|
insertAppWithCategory("com.example.game", "Game",
|
||||||
"Running,Shooting,Jumping,Bleh,Sneh,Pleh,Blah,Test category," +
|
"Running,Shooting,Jumping,Bleh,Sneh,Pleh,Blah,Test category," +
|
||||||
"The quick brown fox jumps over the lazy dog,With apostrophe's");
|
"The quick brown fox jumps over the lazy dog,With apostrophe's", additionalRepo);
|
||||||
|
|
||||||
List<String> categoriesLonger = CategoryProvider.Helper.categories(context);
|
List<String> categoriesLonger = CategoryProvider.Helper.categories(context);
|
||||||
String[] expectedLonger = new String[] {
|
String[] expectedLonger = new String[] {
|
||||||
@ -150,11 +155,19 @@ public class CategoryProviderTest extends FDroidProviderTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
assertContainsOnly(categoriesLonger, expectedLonger);
|
assertContainsOnly(categoriesLonger, expectedLonger);
|
||||||
|
|
||||||
|
RepoProvider.Helper.purgeApps(context, new MockRepo(additionalRepo));
|
||||||
|
List<String> categoriesAfterPurge = CategoryProvider.Helper.categories(context);
|
||||||
|
assertContainsOnly(categoriesAfterPurge, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertAppWithCategory(String id, String name, String categories) {
|
private void insertAppWithCategory(String id, String name, String categories) {
|
||||||
|
insertAppWithCategory(id, name, categories, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insertAppWithCategory(String id, String name, String categories, long repoId) {
|
||||||
ContentValues values = new ContentValues(1);
|
ContentValues values = new ContentValues(1);
|
||||||
values.put(Cols.ForWriting.Categories.CATEGORIES, categories);
|
values.put(Cols.ForWriting.Categories.CATEGORIES, categories);
|
||||||
AppProviderTest.insertApp(contentResolver, context, id, name, values);
|
AppProviderTest.insertApp(contentResolver, context, id, name, values, repoId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,6 @@ public class ProviderUriTests {
|
|||||||
assertValidUri(resolver, AppProvider.getSearchUri("/"), "content://org.fdroid.fdroid.data.AppProvider/search/%2F", projection);
|
assertValidUri(resolver, AppProvider.getSearchUri("/"), "content://org.fdroid.fdroid.data.AppProvider/search/%2F", projection);
|
||||||
assertValidUri(resolver, AppProvider.getSearchUri(""), "content://org.fdroid.fdroid.data.AppProvider", projection);
|
assertValidUri(resolver, AppProvider.getSearchUri(""), "content://org.fdroid.fdroid.data.AppProvider", projection);
|
||||||
assertValidUri(resolver, AppProvider.getSearchUri(null), "content://org.fdroid.fdroid.data.AppProvider", projection);
|
assertValidUri(resolver, AppProvider.getSearchUri(null), "content://org.fdroid.fdroid.data.AppProvider", projection);
|
||||||
assertValidUri(resolver, AppProvider.getNoApksUri(), "content://org.fdroid.fdroid.data.AppProvider/noApks", projection);
|
|
||||||
assertValidUri(resolver, AppProvider.getInstalledUri(), "content://org.fdroid.fdroid.data.AppProvider/installed", projection);
|
assertValidUri(resolver, AppProvider.getInstalledUri(), "content://org.fdroid.fdroid.data.AppProvider/installed", projection);
|
||||||
assertValidUri(resolver, AppProvider.getCanUpdateUri(), "content://org.fdroid.fdroid.data.AppProvider/canUpdate", projection);
|
assertValidUri(resolver, AppProvider.getCanUpdateUri(), "content://org.fdroid.fdroid.data.AppProvider/canUpdate", projection);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user