Added test to ensure repo priority plays nice with categories

This is in response to identifying a bug with the way priorities work
with categories. Two repos may both specify different categories for
the same package. In this case, F-Droid should only select the
categories from the highest priority repo. Well, it is not to say that
this is the most preferable option, but it is consistent with other ways
that repo priorities are used.
This commit is contained in:
Peter Serwylo 2017-03-17 09:52:21 +11:00
parent bc1ff7d8c8
commit bded83d8a3

View File

@ -30,12 +30,49 @@ public class CategoryProviderTest extends FDroidProviderTest {
TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class); TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class);
} }
// ======================================================================== /**
// "Categories" * Different repositories can specify a different set of categories for the same package.
// (at this point) not an additional table, but we treat them sort of * In this case, only the repository with the highest priority should get to choose which
// like they are. That means that if we change the implementation to * category the app goes in.
// use a separate table in the future, these should still pass. */
// ======================================================================== @Test
public void onlyHighestPriorityMetadataDefinesCategories() {
long mainRepo = 1;
long gpRepo = 3;
insertAppWithCategory("info.guardianproject.notepadbot", "NoteCipher", "Writing,Security", 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);
String[] expected = new String[] {
context.getResources().getString(R.string.category_Whats_New),
context.getResources().getString(R.string.category_Recently_Updated),
context.getResources().getString(R.string.category_All),
"Animal",
"Mineral",
"Security",
"Vegetable",
"Writing",
};
assertContainsOnly(categories, expected);
insertAppWithCategory("info.guardianproject.notepadbot", "NoteCipher", "Office,GuardianProject", gpRepo);
assertContainsOnly(CategoryProvider.Helper.categories(context), expected);
RepoProvider.Helper.purgeApps(context, new MockRepo(mainRepo));
String[] expectedGp = new String[] {
context.getResources().getString(R.string.category_Whats_New),
context.getResources().getString(R.string.category_Recently_Updated),
context.getResources().getString(R.string.category_All),
"GuardianProject",
"Office",
};
List<String> categoriesAfterPurge = CategoryProvider.Helper.categories(context);
assertContainsOnly(categoriesAfterPurge, expectedGp);
}
@Test @Test
public void queryFreeTextAndCategories() { public void queryFreeTextAndCategories() {