Skip to content

Commit 28f7b8b

Browse files
authored
Tests for com_privacy consent on user site (#41529)
* Tests for com_privacy consent on user site * Allow ability to enable extension in tests to prevent errors * remove paramater not needed * Added fixes to stop errors in drone build * Added fixes to stop errors in drone build * Added fixes to stop errors in drone build
1 parent c189551 commit 28f7b8b

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
describe('Test in frontend that the privacy consent view', () => {
2+
beforeEach(() => {
3+
cy.db_updateExtensionParameter('allowUserRegistration', '1', 'com_users');
4+
cy.db_enableExtension('1', 'plg_system_privacyconsent');
5+
});
6+
7+
afterEach(() => {
8+
cy.db_updateExtensionParameter('allowUserRegistration', '0', 'com_users');
9+
cy.db_enableExtension('0', 'plg_system_privacyconsent');
10+
cy.task('queryDB', 'DELETE FROM #__privacy_consents');
11+
cy.task('queryDB', "DELETE FROM #__users WHERE username = 'test'");
12+
});
13+
14+
it('can display privacy policy checkbox to users already with an account', () => {
15+
cy.doFrontendLogin();
16+
cy.visit('/index.php');
17+
cy.db_createPrivacyConsent();
18+
cy.get('.alert').contains('By signing up to this website and agreeing to the Privacy Policy you agree to this website storing your information.');
19+
});
20+
21+
it('can allow users already with an account to not agree to the privacy policy', () => {
22+
cy.doFrontendLogin();
23+
cy.visit('/index.php');
24+
cy.get('.controls > .btn-primary').click({ force: true });
25+
cy.get('.alert-message').should('include.text', "Profile could not be saved: Agreement to the site's Privacy Policy is required.");
26+
});
27+
28+
it('can allow users already with an account to agree to the privacy policy', () => {
29+
cy.doFrontendLogin();
30+
cy.visit('/index.php');
31+
cy.get('#jform_privacyconsent_privacy0').click();
32+
cy.get('.controls > .btn-primary').click({ force: true });
33+
cy.get('.alert-message').should('include.text', 'Profile saved.');
34+
});
35+
36+
it('can allow current users who declined privacy request to edit then agree to privacy consent', () => {
37+
cy.doFrontendLogin();
38+
cy.visit('/index.php');
39+
cy.get('#jform_privacyconsent_privacy1').click();
40+
cy.get('.controls > .btn-primary').click({ force: true });
41+
cy.get('.alert-message').should('include.text', "Profile could not be saved: Agreement to the site's Privacy Policy is required.");
42+
cy.get('#jform_privacyconsent_privacy0').click();
43+
cy.get('.controls > .btn-primary').click({ force: true });
44+
cy.get('.alert-message').should('include.text', 'Profile saved.');
45+
});
46+
47+
it('can display privacy consent on new user registration form', () => {
48+
cy.visit('/index.php?option=com_users&view=registration');
49+
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.');
50+
});
51+
52+
it('can display privacy consent on new user registration form and have user decline privacy consent', () => {
53+
cy.visit('/index.php?option=com_users&view=registration');
54+
cy.get('#jform_name').clear().type('test user');
55+
cy.get('#jform_username').clear().type('test');
56+
cy.get('#jform_email1').clear().type('[email protected]');
57+
cy.get('#jform_password1').clear().type('testtesttest');
58+
cy.get('#jform_password2').clear().type('testtesttest');
59+
cy.get('.com-users-registration__register').click();
60+
cy.get('.alert-message').should('contain.text', "Registration failed: Agreement to the site's Privacy Policy is required.");
61+
});
62+
63+
it('can display privacy consent on new user registration form and have user accept privacy consent', () => {
64+
cy.visit('/index.php?option=com_users&view=registration');
65+
cy.get('#jform_name').clear().type('test user');
66+
cy.get('#jform_username').clear().type('test');
67+
cy.get('#jform_email1').clear().type('[email protected]');
68+
cy.get('#jform_password1').clear().type('testtesttest');
69+
cy.get('#jform_password2').clear().type('testtesttest');
70+
cy.get('#jform_privacyconsent_privacy0').click();
71+
cy.get('.com-users-registration__register').click();
72+
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.');
73+
});
74+
});

tests/System/support/commands/db.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,32 @@ function createInsertQuery(table, values) {
4343
return query;
4444
}
4545

46+
/**
47+
* Creates a privacy consent in the database with the given data.
48+
* The privacy consent contains some default values when not all required fields are passed in the given data.
49+
* The id of the inserted privacy consent is returned
50+
*
51+
* @param {Object} privacyRequest The consent data to insert
52+
*
53+
* @returns integer
54+
*/
55+
Cypress.Commands.add('db_createPrivacyConsent', (privacyConsent) => {
56+
const defaultPrivacyConsentOptions = {
57+
state: '0',
58+
created: '2023-01-01 20:00:00',
59+
subject: 'PLG_SYSTEM_PRIVACYCONSENT_SUBJECT',
60+
body: '',
61+
};
62+
63+
return cy.task('queryDB', createInsertQuery('privacy_consents', { ...defaultPrivacyConsentOptions, ...privacyConsent })).then(async (info) => info.insertId);
64+
});
65+
4666
/**
4767
* Creates a privacy request in the database with the given data.
4868
* The privacy request contains some default values when not all required fields are passed in the given data.
4969
* The id of the inserted privacy request is returned
5070
*
51-
* @param {Object} privacyRequest The tag data to insert
71+
* @param {Object} privacyRequest The request data to insert
5272
*
5373
* @returns integer
5474
*/
@@ -496,6 +516,14 @@ Cypress.Commands.add('db_updateExtensionParameter', (key, value, extension) => c
496516
return cy.task('queryDB', `UPDATE #__extensions SET params = '${JSON.stringify(params)}' WHERE name = '${extension}'`);
497517
}));
498518

519+
/**
520+
* Sets the enabled status for the given extension.
521+
*
522+
* @param {string} value The value
523+
* @param {string} extension The extension
524+
*/
525+
Cypress.Commands.add('db_enableExtension', (value, extension) => cy.task('queryDB', `UPDATE #__extensions SET enabled ='${value}' WHERE name = '${extension}'`));
526+
499527
/**
500528
* Returns the id of the currently logged in user.
501529
*

0 commit comments

Comments
 (0)