File indexing completed on 2024-12-22 04:45:40
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "accountsettingswidgettest.h" 0008 #include "administratorsettingsdialog/accounts/accountsettingswidget.h" 0009 #include "settingswidgetshelper.h" 0010 #include <QCheckBox> 0011 #include <QFormLayout> 0012 #include <QLineEdit> 0013 #include <QSpinBox> 0014 0015 QTEST_MAIN(AccountSettingsWidgetTest) 0016 0017 AccountSettingsWidgetTest::AccountSettingsWidgetTest(QObject *parent) 0018 : QObject{parent} 0019 { 0020 } 0021 0022 void AccountSettingsWidgetTest::shouldHaveDefaultValues() 0023 { 0024 AccountSettingsWidget w(nullptr); 0025 QVERIFY(w.widgetResizable()); 0026 0027 auto mainLayout = w.findChild<QFormLayout *>(QStringLiteral("mainLayout")); 0028 QVERIFY(mainLayout); 0029 0030 auto mAllowChangeName = w.findChild<QCheckBox *>(QStringLiteral("mAllowChangeName")); 0031 QVERIFY(mAllowChangeName); 0032 QVERIFY(!mAllowChangeName->isChecked()); 0033 QVERIFY(!mAllowChangeName->text().isEmpty()); 0034 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowChangeName), QStringLiteral("Accounts_AllowRealNameChange")); 0035 0036 auto mAllowChangeUserProfile = w.findChild<QCheckBox *>(QStringLiteral("mAllowChangeUserProfile")); 0037 QVERIFY(mAllowChangeUserProfile); 0038 QVERIFY(!mAllowChangeUserProfile->isChecked()); 0039 QVERIFY(!mAllowChangeUserProfile->text().isEmpty()); 0040 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowChangeUserProfile), QStringLiteral("Accounts_AllowUserProfileChange")); 0041 0042 auto mAllowChangeUserAvatar = w.findChild<QCheckBox *>(QStringLiteral("mAllowChangeUserAvatar")); 0043 QVERIFY(mAllowChangeUserAvatar); 0044 QVERIFY(!mAllowChangeUserAvatar->isChecked()); 0045 QVERIFY(!mAllowChangeUserAvatar->text().isEmpty()); 0046 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowChangeUserAvatar), QStringLiteral("Accounts_AllowUserAvatarChange")); 0047 0048 auto mAllowChangeEmail = w.findChild<QCheckBox *>(QStringLiteral("mAllowChangeEmail")); 0049 QVERIFY(mAllowChangeEmail); 0050 QVERIFY(!mAllowChangeEmail->isChecked()); 0051 QVERIFY(!mAllowChangeEmail->text().isEmpty()); 0052 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowChangeEmail), QStringLiteral("Accounts_AllowEmailChange")); 0053 0054 auto mAllowChangePassword = w.findChild<QCheckBox *>(QStringLiteral("mAllowChangePassword")); 0055 QVERIFY(mAllowChangePassword); 0056 QVERIFY(!mAllowChangePassword->isChecked()); 0057 QVERIFY(!mAllowChangePassword->text().isEmpty()); 0058 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowChangePassword), QStringLiteral("Accounts_AllowPasswordChange")); 0059 0060 auto mAllowChangeEmailNotifications = w.findChild<QCheckBox *>(QStringLiteral("mAllowChangeEmailNotifications")); 0061 QVERIFY(mAllowChangeEmailNotifications); 0062 QVERIFY(!mAllowChangeEmailNotifications->isChecked()); 0063 QVERIFY(!mAllowChangeEmailNotifications->text().isEmpty()); 0064 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowChangeEmailNotifications), QStringLiteral("Accounts_AllowEmailNotifications")); 0065 0066 auto mAllowUsersToDeleteOwnAccount = w.findChild<QCheckBox *>(QStringLiteral("mAllowUsersToDeleteOwnAccount")); 0067 QVERIFY(mAllowUsersToDeleteOwnAccount); 0068 QVERIFY(!mAllowUsersToDeleteOwnAccount->isChecked()); 0069 QVERIFY(!mAllowUsersToDeleteOwnAccount->text().isEmpty()); 0070 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowUsersToDeleteOwnAccount), QStringLiteral("Accounts_AllowDeleteOwnAccount")); 0071 0072 auto mAllowAnonymousWrite = w.findChild<QCheckBox *>(QStringLiteral("mAllowAnonymousWrite")); 0073 QVERIFY(mAllowAnonymousWrite); 0074 QVERIFY(!mAllowAnonymousWrite->isChecked()); 0075 QVERIFY(!mAllowAnonymousWrite->text().isEmpty()); 0076 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowAnonymousWrite), QStringLiteral("Accounts_AllowAnonymousWrite")); 0077 0078 auto mAllowAnonymousRead = w.findChild<QCheckBox *>(QStringLiteral("mAllowAnonymousRead")); 0079 QVERIFY(mAllowAnonymousRead); 0080 QVERIFY(!mAllowAnonymousRead->isChecked()); 0081 QVERIFY(!mAllowAnonymousRead->text().isEmpty()); 0082 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowAnonymousRead), QStringLiteral("Accounts_AllowAnonymousRead")); 0083 0084 auto mAllowUsersDeleteOwnAccount = w.findChild<QCheckBox *>(QStringLiteral("mAllowUsersDeleteOwnAccount")); 0085 QVERIFY(mAllowUsersDeleteOwnAccount); 0086 QVERIFY(!mAllowUsersDeleteOwnAccount->isChecked()); 0087 QVERIFY(!mAllowUsersDeleteOwnAccount->text().isEmpty()); 0088 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowUsersDeleteOwnAccount), QStringLiteral("Accounts_AllowDeleteOwnAccount")); 0089 0090 auto mAllowPasswordChangeOauthUsers = w.findChild<QCheckBox *>(QStringLiteral("mAllowPasswordChangeOauthUsers")); 0091 QVERIFY(mAllowPasswordChangeOauthUsers); 0092 QVERIFY(!mAllowPasswordChangeOauthUsers->isChecked()); 0093 QVERIFY(!mAllowPasswordChangeOauthUsers->text().isEmpty()); 0094 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowPasswordChangeOauthUsers), QStringLiteral("Accounts_AllowPasswordChangeForOAuthUsers")); 0095 0096 auto mLoginExpirationInDays = w.findChild<QSpinBox *>(QStringLiteral("mLoginExpirationInDays")); 0097 QVERIFY(mLoginExpirationInDays); 0098 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mLoginExpirationInDays), QStringLiteral("Accounts_LoginExpiration")); 0099 0100 auto mAllowInvisibleStatusOption = w.findChild<QCheckBox *>(QStringLiteral("mAllowInvisibleStatusOption")); 0101 QVERIFY(mAllowInvisibleStatusOption); 0102 QVERIFY(!mAllowInvisibleStatusOption->isChecked()); 0103 QVERIFY(!mAllowInvisibleStatusOption->text().isEmpty()); 0104 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowInvisibleStatusOption), QStringLiteral("Accounts_AllowInvisibleStatusOption")); 0105 0106 auto mForgetUserSessionWindowClose = w.findChild<QCheckBox *>(QStringLiteral("mForgetUserSessionWindowClose")); 0107 QVERIFY(mForgetUserSessionWindowClose); 0108 QVERIFY(!mForgetUserSessionWindowClose->isChecked()); 0109 QVERIFY(!mForgetUserSessionWindowClose->text().isEmpty()); 0110 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mForgetUserSessionWindowClose), QStringLiteral("Accounts_ForgetUserSessionOnWindowClose")); 0111 0112 auto failedLoginAttemptsLabel = w.findChild<QLabel *>(QStringLiteral("failedLoginAttemptsLabel")); 0113 QVERIFY(failedLoginAttemptsLabel); 0114 QVERIFY(!failedLoginAttemptsLabel->text().isEmpty()); 0115 0116 auto mEnableCollectLog = w.findChild<QCheckBox *>(QStringLiteral("mEnableCollectLog")); 0117 QVERIFY(mEnableCollectLog); 0118 QVERIFY(!mEnableCollectLog->isChecked()); 0119 QVERIFY(!mEnableCollectLog->text().isEmpty()); 0120 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mEnableCollectLog), QStringLiteral("Block_Multiple_Failed_Logins_Enabled")); 0121 0122 auto mAllowCustomStatusMessage = w.findChild<QCheckBox *>(QStringLiteral("mAllowCustomStatusMessage")); 0123 QVERIFY(mAllowCustomStatusMessage); 0124 QVERIFY(!mAllowCustomStatusMessage->isChecked()); 0125 QVERIFY(!mAllowCustomStatusMessage->text().isEmpty()); 0126 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowCustomStatusMessage), QStringLiteral("Accounts_AllowUserStatusMessageChange")); 0127 0128 auto mBlockFailedLoginAttemptsUsername = w.findChild<QCheckBox *>(QStringLiteral("mBlockFailedLoginAttemptsUsername")); 0129 QVERIFY(mBlockFailedLoginAttemptsUsername); 0130 QVERIFY(!mBlockFailedLoginAttemptsUsername->isChecked()); 0131 QVERIFY(!mBlockFailedLoginAttemptsUsername->text().isEmpty()); 0132 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mBlockFailedLoginAttemptsUsername), QStringLiteral("Block_Multiple_Failed_Logins_By_User")); 0133 0134 auto mHowManyFailedAttemptsUntilBlockUser = w.findChild<QSpinBox *>(QStringLiteral("mHowManyFailedAttemptsUntilBlockUser")); 0135 QVERIFY(mHowManyFailedAttemptsUntilBlockUser); 0136 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mHowManyFailedAttemptsUntilBlockUser), 0137 QStringLiteral("Block_Multiple_Failed_Logins_Attempts_Until_Block_by_User")); 0138 0139 auto mTimeUnblockUser = w.findChild<QSpinBox *>(QStringLiteral("mTimeUnblockUser")); 0140 QVERIFY(mTimeUnblockUser); 0141 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mTimeUnblockUser), QStringLiteral("Block_Multiple_Failed_Logins_Time_To_Unblock_By_User_In_Minutes")); 0142 0143 auto mHowManyFailedAttemptsUntilBlockByIP = w.findChild<QSpinBox *>(QStringLiteral("mHowManyFailedAttemptsUntilBlockByIP")); 0144 QVERIFY(mHowManyFailedAttemptsUntilBlockByIP); 0145 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mHowManyFailedAttemptsUntilBlockByIP), 0146 QStringLiteral("Block_Multiple_Failed_Logins_Attempts_Until_Block_By_Ip")); 0147 0148 auto mSendEmailUserWhenUserActivated = w.findChild<QCheckBox *>(QStringLiteral("mSendEmailUserWhenUserActivated")); 0149 QVERIFY(mSendEmailUserWhenUserActivated); 0150 QVERIFY(!mSendEmailUserWhenUserActivated->isChecked()); 0151 QVERIFY(!mSendEmailUserWhenUserActivated->text().isEmpty()); 0152 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSendEmailUserWhenUserActivated), QStringLiteral("Accounts_Send_Email_When_Activating")); 0153 0154 auto mSendEmailUserWhenUserDeactivated = w.findChild<QCheckBox *>(QStringLiteral("mSendEmailUserWhenUserDeactivated")); 0155 QVERIFY(mSendEmailUserWhenUserDeactivated); 0156 QVERIFY(!mSendEmailUserWhenUserDeactivated->isChecked()); 0157 QVERIFY(!mSendEmailUserWhenUserDeactivated->text().isEmpty()); 0158 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mSendEmailUserWhenUserDeactivated), QStringLiteral("Accounts_Send_Email_When_Deactivating")); 0159 0160 auto mRequireNameSignup = w.findChild<QCheckBox *>(QStringLiteral("mRequireNameSignup")); 0161 QVERIFY(mRequireNameSignup); 0162 QVERIFY(!mRequireNameSignup->isChecked()); 0163 QVERIFY(!mRequireNameSignup->text().isEmpty()); 0164 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mRequireNameSignup), QStringLiteral("Accounts_RequireNameForSignUp")); 0165 0166 auto mRequirePasswordConfirmation = w.findChild<QCheckBox *>(QStringLiteral("mRequirePasswordConfirmation")); 0167 QVERIFY(mRequirePasswordConfirmation); 0168 QVERIFY(!mRequirePasswordConfirmation->isChecked()); 0169 QVERIFY(!mRequirePasswordConfirmation->text().isEmpty()); 0170 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mRequirePasswordConfirmation), QStringLiteral("Accounts_RequirePasswordConfirmation")); 0171 0172 auto mOnlyAllowVerifiedUsersLogin = w.findChild<QCheckBox *>(QStringLiteral("mOnlyAllowVerifiedUsersLogin")); 0173 QVERIFY(mOnlyAllowVerifiedUsersLogin); 0174 QVERIFY(!mOnlyAllowVerifiedUsersLogin->isChecked()); 0175 QVERIFY(!mOnlyAllowVerifiedUsersLogin->text().isEmpty()); 0176 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mOnlyAllowVerifiedUsersLogin), QStringLiteral("Accounts_EmailVerification")); 0177 0178 auto mMarkEmailExternalAccountsVerified = w.findChild<QCheckBox *>(QStringLiteral("mMarkEmailExternalAccountsVerified")); 0179 QVERIFY(mMarkEmailExternalAccountsVerified); 0180 QVERIFY(!mMarkEmailExternalAccountsVerified->isChecked()); 0181 QVERIFY(!mMarkEmailExternalAccountsVerified->text().isEmpty()); 0182 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mMarkEmailExternalAccountsVerified), QStringLiteral("Accounts_Verify_Email_For_External_Accounts")); 0183 0184 auto mManualApproveNewUser = w.findChild<QCheckBox *>(QStringLiteral("mManualApproveNewUser")); 0185 QVERIFY(mManualApproveNewUser); 0186 QVERIFY(!mManualApproveNewUser->isChecked()); 0187 QVERIFY(!mManualApproveNewUser->text().isEmpty()); 0188 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mManualApproveNewUser), QStringLiteral("Accounts_ManuallyApproveNewUsers")); 0189 0190 auto mDefaultUsernamePrefixSuggestion = w.findChild<QLineEdit *>(QStringLiteral("mDefaultUsernamePrefixSuggestion")); 0191 QVERIFY(mDefaultUsernamePrefixSuggestion); 0192 QVERIFY(mDefaultUsernamePrefixSuggestion->text().isEmpty()); 0193 QVERIFY(mDefaultUsernamePrefixSuggestion->toolTip().isEmpty()); 0194 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mDefaultUsernamePrefixSuggestion), QStringLiteral("Accounts_DefaultUsernamePrefixSuggestion")); 0195 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Accounts_DefaultUsernamePrefixSuggestion")); 0196 0197 auto mAllowedDomainsList = w.findChild<QLineEdit *>(QStringLiteral("mAllowedDomainsList")); 0198 QVERIFY(mAllowedDomainsList); 0199 QVERIFY(mAllowedDomainsList->text().isEmpty()); 0200 QVERIFY(!mAllowedDomainsList->toolTip().isEmpty()); 0201 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowedDomainsList), QStringLiteral("Accounts_AllowedDomainsList")); 0202 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Accounts_AllowedDomainsList")); 0203 0204 auto mBlockedDomainsList = w.findChild<QLineEdit *>(QStringLiteral("mBlockedDomainsList")); 0205 QVERIFY(mBlockedDomainsList); 0206 QVERIFY(mBlockedDomainsList->text().isEmpty()); 0207 QVERIFY(!mBlockedDomainsList->toolTip().isEmpty()); 0208 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mBlockedDomainsList), QStringLiteral("Accounts_BlockedDomainsList")); 0209 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Accounts_BlockedDomainsList")); 0210 0211 auto mBlockedUsernameList = w.findChild<QLineEdit *>(QStringLiteral("mBlockedUsernameList")); 0212 QVERIFY(mBlockedUsernameList); 0213 QVERIFY(mBlockedUsernameList->text().isEmpty()); 0214 QVERIFY(!mBlockedUsernameList->toolTip().isEmpty()); 0215 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mBlockedUsernameList), QStringLiteral("Accounts_BlockedUsernameList")); 0216 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Accounts_BlockedUsernameList")); 0217 0218 auto mUseDefaultBlockedDomainsList = w.findChild<QCheckBox *>(QStringLiteral("mUseDefaultBlockedDomainsList")); 0219 QVERIFY(mUseDefaultBlockedDomainsList); 0220 QVERIFY(!mUseDefaultBlockedDomainsList->isChecked()); 0221 QVERIFY(!mUseDefaultBlockedDomainsList->text().isEmpty()); 0222 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUseDefaultBlockedDomainsList), QStringLiteral("Accounts_UseDefaultBlockedDomainsList")); 0223 0224 auto mUseDNSDomainCheck = w.findChild<QCheckBox *>(QStringLiteral("mUseDNSDomainCheck")); 0225 QVERIFY(mUseDNSDomainCheck); 0226 QVERIFY(!mUseDNSDomainCheck->isChecked()); 0227 QVERIFY(!mUseDNSDomainCheck->text().isEmpty()); 0228 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mUseDNSDomainCheck), QStringLiteral("Accounts_UseDNSDomainCheck")); 0229 0230 auto mAllowFeaturePreview = w.findChild<QCheckBox *>(QStringLiteral("mAllowFeaturePreview")); 0231 QVERIFY(mAllowFeaturePreview); 0232 QVERIFY(!mAllowFeaturePreview->isChecked()); 0233 QVERIFY(!mAllowFeaturePreview->text().isEmpty()); 0234 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mAllowFeaturePreview), QStringLiteral("Accounts_AllowFeaturePreview")); 0235 0236 auto mRegistrationAuthenticationServices = w.findChild<QCheckBox *>(QStringLiteral("mRegistrationAuthenticationServices")); 0237 QVERIFY(mRegistrationAuthenticationServices); 0238 QVERIFY(!mRegistrationAuthenticationServices->isChecked()); 0239 QVERIFY(!mRegistrationAuthenticationServices->text().isEmpty()); 0240 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mRegistrationAuthenticationServices), 0241 QStringLiteral("Accounts_Registration_AuthenticationServices_Enabled")); 0242 0243 auto mRegistrationAuthenticationServicesDefaultRoles = w.findChild<QLineEdit *>(QStringLiteral("mRegistrationAuthenticationServicesDefaultRoles")); 0244 QVERIFY(mRegistrationAuthenticationServicesDefaultRoles); 0245 QVERIFY(mRegistrationAuthenticationServicesDefaultRoles->text().isEmpty()); 0246 QVERIFY(!mRegistrationAuthenticationServicesDefaultRoles->toolTip().isEmpty()); 0247 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mRegistrationAuthenticationServicesDefaultRoles), 0248 QStringLiteral("Accounts_Registration_AuthenticationServices_Default_Roles")); 0249 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Accounts_Registration_AuthenticationServices_Default_Roles")); 0250 0251 auto mRegistrationUsersDefaultRoles = w.findChild<QLineEdit *>(QStringLiteral("mRegistrationUsersDefaultRoles")); 0252 QVERIFY(mRegistrationUsersDefaultRoles); 0253 QVERIFY(mRegistrationUsersDefaultRoles->text().isEmpty()); 0254 QVERIFY(!mRegistrationUsersDefaultRoles->toolTip().isEmpty()); 0255 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mRegistrationUsersDefaultRoles), QStringLiteral("Accounts_Registration_Users_Default_Roles")); 0256 SettingsWidgetHelper::checkLabelToolButton(&w, QStringLiteral("Accounts_Registration_Users_Default_Roles")); 0257 0258 auto mPasswordReset = w.findChild<QCheckBox *>(QStringLiteral("mPasswordReset")); 0259 QVERIFY(mPasswordReset); 0260 QVERIFY(!mPasswordReset->isChecked()); 0261 QVERIFY(!mPasswordReset->text().isEmpty()); 0262 QCOMPARE(SettingsWidgetHelper::widgetSettingsName(mPasswordReset), QStringLiteral("Accounts_PasswordReset")); 0263 } 0264 0265 #include "moc_accountsettingswidgettest.cpp"