Skip to content

Commit

Permalink
Set the configuration options through a command (#41787)
Browse files Browse the repository at this point in the history
* Set the configuration options through a command

* cs
  • Loading branch information
laoneo committed Sep 18, 2023
1 parent 9284af9 commit a892b91
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
19 changes: 7 additions & 12 deletions tests/System/integration/install/Installation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@ describe('Install Joomla', () => {
cy.setErrorReportingToDevelopment();
cy.doAdministratorLogout();

cy.readFile(`${Cypress.env('cmsPath')}/configuration.php`).then((fileContent) => {
// Update to the correct secret for the API tests because of the bearer token
let content = fileContent.replace(/^.*\$secret.*$/mg, "public $secret = 'tEstValue';");
// Update to the correct secret for the API tests because of the bearer token
cy.config_setParameter('secret', 'tEstValue');

// Setup mailing
content = content.replace(/^.*\$mailonline.*$/mg, 'public $mailonline = true;');
content = content.replace(/^.*\$mailer.*$/mg, 'public $mailer = \'smtp\';');
content = content.replace(/^.*\$smtphost.*$/mg, `public $smtphost = '${Cypress.env('smtp_host')}';`);
content = content.replace(/^.*\$smtpport.*$/mg, `public $smtpport = '${Cypress.env('smtp_port')}';`);

// Write the modified content back to the configuration file
cy.task('writeFile', { path: 'configuration.php', content });
});
// Setup mailing
cy.config_setParameter('mailonline', true);
cy.config_setParameter('mailer', 'smtp');
cy.config_setParameter('smtphost', Cypress.env('smtp_host'));
cy.config_setParameter('smtpport', Cypress.env('smtp_port'));
});
});
3 changes: 2 additions & 1 deletion tests/System/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* https://github.com/cypress-io/cypress/issues/6575
*/

import './commands/db';
import './commands/api';
import './commands/config';
import './commands/db';

const { registerCommands } = require('../../../node_modules/joomla-cypress/src/index.js');

Expand Down
18 changes: 18 additions & 0 deletions tests/System/support/commands/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Cypress.Commands.add('config_setParameter', (parameter, value) => {
cy.readFile(`${Cypress.env('cmsPath')}/configuration.php`).then((fileContent) => {
// Setup the new value
let newValue = value;
if (typeof value === 'string') {
newValue = `'${value}'`;
}

// The regex to find the line of the parameter
const regex = new RegExp(`^.*\\$${parameter}\\s.*$`, 'mg');

// Replace the whole line with the new value
const content = fileContent.replace(regex, `public $${parameter} = ${newValue};`);

// Write the modified content back to the configuration file
cy.task('writeFile', { path: 'configuration.php', content });
});
});

0 comments on commit a892b91

Please sign in to comment.