From bded83d8a3c71973ef245ef2807047a9c662ad8d Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Fri, 17 Mar 2017 09:52:21 +1100 Subject: [PATCH] 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. --- .../fdroid/data/CategoryProviderTest.java | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/app/src/test/java/org/fdroid/fdroid/data/CategoryProviderTest.java b/app/src/test/java/org/fdroid/fdroid/data/CategoryProviderTest.java index 5903f335b..72b5dfbe0 100644 --- a/app/src/test/java/org/fdroid/fdroid/data/CategoryProviderTest.java +++ b/app/src/test/java/org/fdroid/fdroid/data/CategoryProviderTest.java @@ -30,12 +30,49 @@ public class CategoryProviderTest extends FDroidProviderTest { TestUtils.registerContentProvider(AppProvider.getAuthority(), AppProvider.class); } - // ======================================================================== - // "Categories" - // (at this point) not an additional table, but we treat them sort of - // like they are. That means that if we change the implementation to - // use a separate table in the future, these should still pass. - // ======================================================================== + /** + * Different repositories can specify a different set of categories for the same package. + * In this case, only the repository with the highest priority should get to choose which + * category the app goes in. + */ + @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 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 categoriesAfterPurge = CategoryProvider.Helper.categories(context); + assertContainsOnly(categoriesAfterPurge, expectedGp); + } @Test public void queryFreeTextAndCategories() {