diff --git a/tests/System/integration/site/components/com_privacy/Consent.cy.js b/tests/System/integration/site/components/com_privacy/Consent.cy.js new file mode 100644 index 0000000000000..bde16fb9693a3 --- /dev/null +++ b/tests/System/integration/site/components/com_privacy/Consent.cy.js @@ -0,0 +1,74 @@ +describe('Test in frontend that the privacy consent view', () => { + beforeEach(() => { + cy.db_updateExtensionParameter('allowUserRegistration', '1', 'com_users'); + cy.db_enableExtension('1', 'plg_system_privacyconsent'); + }); + + afterEach(() => { + cy.db_updateExtensionParameter('allowUserRegistration', '0', 'com_users'); + cy.db_enableExtension('0', 'plg_system_privacyconsent'); + cy.task('queryDB', 'DELETE FROM #__privacy_consents'); + cy.task('queryDB', "DELETE FROM #__users WHERE username = 'test'"); + }); + + it('can display privacy policy checkbox to users already with an account', () => { + cy.doFrontendLogin(); + cy.visit('/index.php'); + cy.db_createPrivacyConsent(); + cy.get('.alert').contains('By signing up to this website and agreeing to the Privacy Policy you agree to this website storing your information.'); + }); + + it('can allow users already with an account to not agree to the privacy policy', () => { + cy.doFrontendLogin(); + cy.visit('/index.php'); + cy.get('.controls > .btn-primary').click({ force: true }); + cy.get('.alert-message').should('include.text', "Profile could not be saved: Agreement to the site's Privacy Policy is required."); + }); + + it('can allow users already with an account to agree to the privacy policy', () => { + cy.doFrontendLogin(); + cy.visit('/index.php'); + cy.get('#jform_privacyconsent_privacy0').click(); + cy.get('.controls > .btn-primary').click({ force: true }); + cy.get('.alert-message').should('include.text', 'Profile saved.'); + }); + + it('can allow current users who declined privacy request to edit then agree to privacy consent', () => { + cy.doFrontendLogin(); + cy.visit('/index.php'); + cy.get('#jform_privacyconsent_privacy1').click(); + cy.get('.controls > .btn-primary').click({ force: true }); + cy.get('.alert-message').should('include.text', "Profile could not be saved: Agreement to the site's Privacy Policy is required."); + cy.get('#jform_privacyconsent_privacy0').click(); + cy.get('.controls > .btn-primary').click({ force: true }); + cy.get('.alert-message').should('include.text', 'Profile saved.'); + }); + + it('can display privacy consent on new user registration form', () => { + cy.visit('/index.php?option=com_users&view=registration'); + cy.get('.alert').should('contain.text', 'By signing up to this website and agreeing to the Privacy Policy you agree to this website storing your information.'); + }); + + it('can display privacy consent on new user registration form and have user decline privacy consent', () => { + cy.visit('/index.php?option=com_users&view=registration'); + cy.get('#jform_name').clear().type('test user'); + cy.get('#jform_username').clear().type('test'); + cy.get('#jform_email1').clear().type('test@example.com'); + cy.get('#jform_password1').clear().type('testtesttest'); + cy.get('#jform_password2').clear().type('testtesttest'); + cy.get('.com-users-registration__register').click(); + cy.get('.alert-message').should('contain.text', "Registration failed: Agreement to the site's Privacy Policy is required."); + }); + + it('can display privacy consent on new user registration form and have user accept privacy consent', () => { + cy.visit('/index.php?option=com_users&view=registration'); + cy.get('#jform_name').clear().type('test user'); + cy.get('#jform_username').clear().type('test'); + cy.get('#jform_email1').clear().type('test@example.com'); + cy.get('#jform_password1').clear().type('testtesttest'); + cy.get('#jform_password2').clear().type('testtesttest'); + cy.get('#jform_privacyconsent_privacy0').click(); + cy.get('.com-users-registration__register').click(); + cy.get('.alert-message').should('contain.text', 'Your account has been created and a verification link has been sent to the email address you entered. Note that you must verify the account by selecting the verification link when you get the email and then an administrator will activate your account before you can login.'); + }); +}); diff --git a/tests/System/support/commands/db.js b/tests/System/support/commands/db.js index acb5e1df344be..705d761f6ac95 100644 --- a/tests/System/support/commands/db.js +++ b/tests/System/support/commands/db.js @@ -43,12 +43,32 @@ function createInsertQuery(table, values) { return query; } +/** + * Creates a privacy consent in the database with the given data. + * The privacy consent contains some default values when not all required fields are passed in the given data. + * The id of the inserted privacy consent is returned + * + * @param {Object} privacyRequest The consent data to insert + * + * @returns integer + */ +Cypress.Commands.add('db_createPrivacyConsent', (privacyConsent) => { + const defaultPrivacyConsentOptions = { + state: '0', + created: '2023-01-01 20:00:00', + subject: 'PLG_SYSTEM_PRIVACYCONSENT_SUBJECT', + body: '', + }; + + return cy.task('queryDB', createInsertQuery('privacy_consents', { ...defaultPrivacyConsentOptions, ...privacyConsent })).then(async (info) => info.insertId); +}); + /** * Creates a privacy request in the database with the given data. * The privacy request contains some default values when not all required fields are passed in the given data. * The id of the inserted privacy request is returned * - * @param {Object} privacyRequest The tag data to insert + * @param {Object} privacyRequest The request data to insert * * @returns integer */ @@ -496,6 +516,14 @@ Cypress.Commands.add('db_updateExtensionParameter', (key, value, extension) => c return cy.task('queryDB', `UPDATE #__extensions SET params = '${JSON.stringify(params)}' WHERE name = '${extension}'`); })); +/** + * Sets the enabled status for the given extension. + * + * @param {string} value The value + * @param {string} extension The extension + */ +Cypress.Commands.add('db_enableExtension', (value, extension) => cy.task('queryDB', `UPDATE #__extensions SET enabled ='${value}' WHERE name = '${extension}'`)); + /** * Returns the id of the currently logged in user. *