diff options
Diffstat (limited to 'tests/test_config.cpp')
| -rw-r--r-- | tests/test_config.cpp | 119 |
1 files changed, 106 insertions, 13 deletions
diff --git a/tests/test_config.cpp b/tests/test_config.cpp index e69a073..70e3705 100644 --- a/tests/test_config.cpp +++ b/tests/test_config.cpp @@ -120,11 +120,17 @@ private slots: void anAccountCarriesItsTrashFolder(); void aBracketedTrashFolderIsQuoted(); void anAccountWithoutATrashFolderWarns(); + void anAccountCarriesItsSpamFolder(); + void aBracketedSpamFolderIsQuoted(); + void anAccountWithoutASpamFolderWarns(); + void allSpamQueryJoinsAndSkips(); void theDraftsFilterComposesPerAccount(); void theDraftsFilterMatchesNothingWithoutAFolder(); void theDraftsFilterIsFlatLikeSent(); void theTrashFilterComposesPerAccount(); void theTrashFilterMatchesNothingWithoutAFolder(); + void theSpamFilterComposesPerAccount(); + void theSpamFilterMatchesNothingWithoutAFolder(); void anAccountWithoutASendCommandIsReceiveOnly(); void composeSettingsDefaultWhenTheSectionIsAbsent(); void aZeroSendDelayIsHonouredRatherThanTreatedAsUnset(); @@ -451,7 +457,8 @@ void TestConfig::absentSyncCommandIsNoticeNotProblem() const QString path = writeIni(dir, QStringLiteral( "[account.work]\n" "maildir=work-mail\n" - "trash=Trash\n")); + "trash=Trash\n" + "spam=Spam\n")); Config config; config.load(path); @@ -472,7 +479,8 @@ void TestConfig::brokenSyncCommandIsAProblem() "\n" "[account.work]\n" "maildir=work-mail\n" - "trash=Trash\n")); + "trash=Trash\n" + "spam=Spam\n")); Config config; config.load(path); @@ -508,7 +516,8 @@ void TestConfig::validConfigHasNoProblems() "[account.work]\n" "maildir=work-mail\n" "address=user@example.org\n" - "trash=Trash\n")); + "trash=Trash\n" + "spam=Spam\n")); Config config; config.load(path); @@ -929,7 +938,8 @@ void TestConfig::sentQueryIsEmptyWithoutTheKey() config.load(writeIni(dir, QStringLiteral( "[account.provider-c]\n" "maildir = provider-c\n" - "trash = Trash\n"))); + "trash = Trash\n" + "spam = Spam\n"))); QCOMPARE(config.accounts().size(), 1); QVERIFY(config.accounts().at(0).sentQuery().isEmpty()); @@ -1028,6 +1038,52 @@ void TestConfig::anAccountWithoutATrashFolderWarns() QVERIFY(joined.contains(QStringLiteral("trash"))); } +void TestConfig::anAccountCarriesItsSpamFolder() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.work]\nmaildir=work\nspam=Spam\n"))); + const Account account = config.account(QStringLiteral("work")); + QCOMPARE(account.spam, QStringLiteral("Spam")); + QCOMPARE(account.spamQuery(), QStringLiteral("path:\"work/Spam/**\"")); +} + +void TestConfig::aBracketedSpamFolderIsQuoted() +{ + Account account; + account.maildir = QStringLiteral("provider-a"); + account.spam = QStringLiteral("[Provider]/Spam"); + QCOMPARE(account.spamQuery(), + QStringLiteral("path:\"provider-a/[Provider]/Spam/**\"")); +} + +void TestConfig::anAccountWithoutASpamFolderWarns() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.work]\nmaildir=work\n"))); + QVERIFY(config.account(QStringLiteral("work")).isValid()); + const QString joined = config.warnings().join(QLatin1Char('\n')); + QVERIFY(joined.contains(QStringLiteral("work"))); + QVERIFY(joined.contains(QStringLiteral("spam"))); +} + +void TestConfig::allSpamQueryJoinsAndSkips() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.work]\nmaildir=work\nspam=Spam\n" + "\n[account.personal]\nmaildir=personal\nspam=[Provider]/Spam\n" + "\n[account.none]\nmaildir=none\n"))); + const QString all = config.allSpamQuery(); + QVERIFY(all.contains(QStringLiteral("path:\"work/Spam/**\""))); + QVERIFY(all.contains(QStringLiteral("path:\"personal/[Provider]/Spam/**\""))); + QVERIFY(!all.contains(QStringLiteral("none"))); +} + void TestConfig::theDraftsFilterComposesPerAccount() { // Item 138. Follows `sent` and `trash`, which match a FOLDER: `draft` is a @@ -1144,6 +1200,34 @@ void TestConfig::theTrashFilterMatchesNothingWithoutAFolder() QCOMPARE(config.resolvedQuery(trash, QString()), Config::matchNothingQuery()); } +void TestConfig::theSpamFilterComposesPerAccount() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.work]\nmaildir=work\nspam=Spam\n" + "\n[account.personal]\nmaildir=personal\nspam=[Provider]/Spam\n"))); + const SavedQuery spam = Config::builtinFilter(QStringLiteral("spam")); + QVERIFY(spam.isGenerated()); + QVERIFY2(!spam.flat, "spam must be threaded, like trash"); + const QString all = config.resolvedQuery(spam, QString()); + QVERIFY(all.contains(QStringLiteral("path:\"work/Spam/**\""))); + QVERIFY(all.contains(QStringLiteral("path:\"personal/[Provider]/Spam/**\""))); + const QString scoped = config.resolvedQuery(spam, QStringLiteral("work")); + QCOMPARE(scoped, QStringLiteral("path:\"work/Spam/**\"")); + QVERIFY(!scoped.contains(QStringLiteral("personal"))); +} + +void TestConfig::theSpamFilterMatchesNothingWithoutAFolder() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.work]\nmaildir=work\n"))); + const SavedQuery spam = Config::builtinFilter(QStringLiteral("spam")); + QCOMPARE(config.resolvedQuery(spam, QString()), Config::matchNothingQuery()); +} + void TestConfig::sentQueryComposesWithScopedQuery() { // A Sent view under one account must not show another account's sent mail. @@ -1265,10 +1349,12 @@ void TestConfig::theStartupAccountIsReadAndValidated() "[account.work]\n" "maildir=work\n" "trash=Trash\n" + "spam=Spam\n" "\n" "[account.personal]\n" "maildir=personal\n" - "trash=Trash\n"))); + "trash=Trash\n" + "spam=Spam\n"))); QCOMPARE(config.startupAccount(), QStringLiteral("work")); QVERIFY(config.problems().isEmpty()); @@ -1294,7 +1380,8 @@ void TestConfig::theStartupAccountIsReadAndValidated() "\n" "[account.work]\n" "maildir=work\n" - "trash=Trash\n"))); + "trash=Trash\n" + "spam=Spam\n"))); QVERIFY2(wrong.startupAccount().isEmpty(), "an unknown startup account was passed through rather than " "falling back to All accounts"); @@ -1320,7 +1407,8 @@ void TestConfig::theStartupAccountTakesTheKeyNotTheSyncChannel() "[account.provider-work.mailbox]\n" "maildir=provider-work.mailbox\n" "channel=provider-workmailbox\n" - "trash=Trash\n"))); + "trash=Trash\n" + "spam=Spam\n"))); QCOMPARE(config.accounts().size(), 1); QCOMPARE(config.accounts().constFirst().key, @@ -1343,7 +1431,8 @@ void TestConfig::theStartupAccountTakesTheKeyNotTheSyncChannel() "[account.provider-work.mailbox]\n" "maildir=provider-work.mailbox\n" "channel=provider-workmailbox\n" - "trash=Trash\n"))); + "trash=Trash\n" + "spam=Spam\n"))); QVERIFY2(byChannel.startupAccount().isEmpty(), "the sync channel was accepted as an account key"); @@ -1428,7 +1517,8 @@ void TestConfig::theStartupQuerySurvivesATranslatedFilterName() "[account.work]\n" "maildir=work\n" "sent=Sent\n" - "trash=Trash\n"))); + "trash=Trash\n" + "spam=Spam\n"))); QVERIFY2(!config.savedQueries().isEmpty(), "queries.json did not load, so the warning path is unreachable"); @@ -1454,7 +1544,8 @@ void TestConfig::theStartupQuerySurvivesATranslatedFilterName() "[account.work]\n" "maildir=work\n" "sent=Sent\n" - "trash=Trash\n"))); + "trash=Trash\n" + "spam=Spam\n"))); QVERIFY(!byLabel.savedQueries().isEmpty()); QCOMPARE(byLabel.startupSavedQuery().generated, QStringLiteral("inbox")); QVERIFY(byLabel.problems().isEmpty()); @@ -1567,7 +1658,7 @@ void TestConfig::everyBuiltinFilterIsAKnownGenerator() Config config; const QList<SavedQuery> filters = config.builtinFilters(); - QCOMPARE(filters.size(), 6); + QCOMPARE(filters.size(), 7); QStringList names; for (const SavedQuery &filter : filters) { @@ -1590,7 +1681,8 @@ void TestConfig::everyBuiltinFilterIsAKnownGenerator() QStringLiteral("Important"), QStringLiteral("Sent"), QStringLiteral("Drafts"), - QStringLiteral("Trash") })); + QStringLiteral("Trash"), + QStringLiteral("Spam") })); } void TestConfig::aFilterAcrossAllAccountsIsTheUnscopedQuery() @@ -1684,7 +1776,8 @@ void TestConfig::draftsQueryIsEmptyWithoutTheKey() config.load(writeIni(dir, QStringLiteral( "[account.provider-c]\n" "maildir = provider-c\n" - "trash = Trash\n"))); + "trash = Trash\n" + "spam = Spam\n"))); QCOMPARE(config.accounts().size(), 1); QVERIFY(config.accounts().at(0).draftsQuery().isEmpty()); |
