Skip to content

Commit

Permalink
Merge pull request #43678 from LadySolveig/5.1/upmerge/2024-06-20
Browse files Browse the repository at this point in the history
[5.1] Upmerge 2024-06-20
  • Loading branch information
LadySolveig authored Jun 20, 2024
2 parents d8eb36e + 7230327 commit a72ac58
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 34 deletions.
8 changes: 4 additions & 4 deletions tests/System/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ The Joomla System Tests come with some convenient [Cypress Tasks](https://docs.c

- **queryDB** – Executes a query on the database
- **cleanupDB** – Deletes the inserted items from the database
- **writeFile** – Writes a file relative to the CMS root folder
- **deleteFolder** – Deletes a folder relative to the CMS root folder
- **writeRelativeFile** – Writes a file relative to the CMS root folder
- **deleteRelativePath** – Deletes a file or folder relative to the CMS root folder
- **startMailServer** – Starts the smtp-tester SMTP server
- **getMails** – Get received mails from smtp-tester
- **clearEmails** – Clear all smtp-tester received mails

The following code in a test executes the writing file task with parameters:
```JavaScript
cy.task('writeFile', { path: 'images/dummy.text', content: '1' }).then(() => { ... })
cy.task('writeRelativeFile', { path: 'images/dummy.text', content: '1' }).then(() => { ... })
```
:point_right: As each task is asynchronous and must be chained, the result includes `.then()`.

Expand Down Expand Up @@ -273,7 +273,7 @@ If the Cypress installation step or the entire test suite is executed by a non-r
```
1) Install Joomla
Install Joomla:
CypressError: `cy.task('writeFile')` failed with the following error:
CypressError: `cy.task('writeRelativeFile')` failed with the following error:
> EACCES: permission denied, open './configuration.php'
```
Or on Microsoft Windows you will see:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe('Test in backend that the checkin', () => {
beforeEach(() => {
cy.doAdministratorLogin();
cy.visit('/administrator/index.php?option=com_checkin');
});

it('has a title', () => {
cy.get('h1.page-title').should('contain.text', 'Maintenance: Global Check-in');
});

it('can display message', () => {
cy.get('p.lead').should('contain.text', 'There are no tables with checked out items');
});

it('can display a list of checked out', () => {
cy.db_createArticle({ title: 'Test article', checked_out: '1', checked_out_time: '2024-01-01 20:00:00' }).then(() => {
cy.visit('/administrator/index.php?option=com_checkin');
cy.get('tr.row0').should('contain.text', 'content');
});
});

it('can check in items', () => {
cy.db_createArticle({ title: 'Test article', checked_out: '1', checked_out_time: '2024-01-01 20:00:00' }).then(() => {
cy.visit('/administrator/index.php?option=com_checkin');
cy.searchForItem('content');
cy.checkAllResults();
cy.get('#toolbar-checkin').click();
cy.get('#system-message-container').contains('Item checked in').should('exist');
});
});
});
23 changes: 12 additions & 11 deletions tests/System/integration/api/com_media/Files.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
describe('Test that media files API endpoint', () => {
// Ensure test dir is available and has correct permissions
beforeEach(() => cy.task('writeFile', { path: 'images/test-dir/dummy.txt', content: '1' }));
afterEach(() => cy.task('deleteFolder', 'images/test-dir'));
// Ensure 'test-dir' (relative to cmsPath) is available and has correct permissions
beforeEach(() => cy.task('writeRelativeFile', { path: 'images/test-dir/dummy.txt', content: '1' }));
// If it exists, delete the 'test-dir' (relative to cmsPath) and its contents
afterEach(() => cy.task('deleteRelativePath', 'images/test-dir'));

it('can deliver a list of files', () => {
cy.api_get('/media/files')
Expand Down Expand Up @@ -101,7 +102,7 @@ describe('Test that media files API endpoint', () => {
});

it('can update a file without adapter', () => {
cy.task('writeFile', { path: 'images/test-dir/override.jpg', content: '1' })
cy.task('writeRelativeFile', { path: 'images/test-dir/override.jpg', content: '1' })
.then(() => cy.readFile('tests/System/data/com_media/test-image-1.jpg', 'binary'))
.then((data) => cy.api_patch(
'/media/files/test-dir/override.jpg',
Expand All @@ -117,7 +118,7 @@ describe('Test that media files API endpoint', () => {
});

it('can update a folder without adapter', () => {
cy.task('writeFile', { path: 'images/test-dir/override/test.jpg', content: '1' })
cy.task('writeRelativeFile', { path: 'images/test-dir/override/test.jpg', content: '1' })
.then(() => cy.api_patch('/media/files/test-dir/override', { path: 'test-dir/override-new' }))
.then((response) => {
cy.wrap(response).its('body').its('data').its('attributes')
Expand All @@ -130,7 +131,7 @@ describe('Test that media files API endpoint', () => {
});

it('can update a file with adapter', () => {
cy.task('writeFile', { path: 'images/test-dir/override.jpg', content: '1' })
cy.task('writeRelativeFile', { path: 'images/test-dir/override.jpg', content: '1' })
.then(() => cy.readFile('tests/System/data/com_media/test-image-1.jpg', 'binary'))
.then((data) => cy.api_patch(
'/media/files/local-images:/test-dir/override.jpg',
Expand All @@ -146,7 +147,7 @@ describe('Test that media files API endpoint', () => {
});

it('can update a folder with adapter', () => {
cy.task('writeFile', { path: 'images/test-dir/override/test.jpg', content: '1' })
cy.task('writeRelativeFile', { path: 'images/test-dir/override/test.jpg', content: '1' })
.then(() => cy.api_patch('/media/files/local-images:/test-dir/override', { path: 'local-images:/test-dir/override-new' }))
.then((response) => {
cy.wrap(response).its('body').its('data').its('attributes')
Expand All @@ -159,22 +160,22 @@ describe('Test that media files API endpoint', () => {
});

it('can delete a file without adapter', () => {
cy.task('writeFile', { path: 'images/test-dir/todelete.jpg', content: '1' })
cy.task('writeRelativeFile', { path: 'images/test-dir/todelete.jpg', content: '1' })
.then(() => cy.api_delete('/media/files/test-dir/todelete.jpg'));
});

it('can delete a folder without adapter', () => {
cy.task('writeFile', { path: 'images/test-dir/todelete/dummy.txt', content: '1' })
cy.task('writeRelativeFile', { path: 'images/test-dir/todelete/dummy.txt', content: '1' })
.then(() => cy.api_delete('/media/files/test-dir/todelete'));
});

it('can delete a file with adapter', () => {
cy.task('writeFile', { path: 'images/test-dir/todelete.jpg', content: '1' })
cy.task('writeRelativeFile', { path: 'images/test-dir/todelete.jpg', content: '1' })
.then(() => cy.api_delete('/media/files/local-images:/test-dir/todelete.jpg'));
});

it('can delete a folder with adapter', () => {
cy.task('writeFile', { path: 'images/test-dir/todelete/dummy.txt', content: '1' })
cy.task('writeRelativeFile', { path: 'images/test-dir/todelete/dummy.txt', content: '1' })
.then(() => cy.api_delete('/media/files/local-images:/test-dir/todelete'));
});
});
4 changes: 2 additions & 2 deletions tests/System/integration/install/Installation.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
describe('Install Joomla', () => {
it('Install Joomla', () => {
cy.exec('rm configuration.php', { failOnNonZeroExit: false });

const config = {
sitename: Cypress.env('sitename'),
name: Cypress.env('name'),
Expand All @@ -16,6 +14,8 @@ describe('Install Joomla', () => {
db_prefix: Cypress.env('db_prefix'),
};

// If exists, delete PHP configuration file to force a new installation
cy.task('deleteRelativePath', 'configuration.php');
cy.installJoomla(config);

cy.doAdministratorLogin(config.username, config.password, false);
Expand Down
31 changes: 17 additions & 14 deletions tests/System/plugins/fs.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
const fs = require('fs');
const fspath = require('path');
const path = require('path');
const { umask } = require('node:process');

/**
* Deletes a folder with the given path recursive.
* Synchronously deletes a file or folder, relative to cmsPath.
* If it is a folder and contains content, the content is deleted recursively.
* It ignores if the path doesn't exist.
*
* @param {string} path The path
* @param {object} config The config
* @param {string} relativePath - File or folder, relative to cmsPath
* @param {object} config - The Cypress configuration object
*
* @returns null
*/
function deleteFolder(path, config) {
fs.rmSync(`${config.env.cmsPath}/${path}`, { recursive: true, force: true });
function deleteRelativePath(relativePath, config) {
const fullPath = path.join(config.env.cmsPath, relativePath);
fs.rmSync(fullPath, { recursive: true, force: true });

return null;
}
Expand All @@ -23,19 +26,19 @@ function deleteFolder(path, config) {
* If the file already exists, it will be overwritten.
* Finally, the given file mode or the default 0o444 is set for the given file.
*
* @param {string} path The relative file path (e.g. 'images/test-dir/override.jpg')
* @param {mixed} content The file content
* @param {object} config The Cypress configuration
* @param {number} [mode=0o444] The file mode to be used (in octal)
* @param {string} relativePath - The relative file path (e.g. 'images/test-dir/override.jpg')
* @param {mixed} content - The file content
* @param {object} config - The Cypress configuration object
* @param {number} [mode=0o444] - The file mode to be used (in octal)
*
* @returns null
*/
function writeFile(path, content, config, mode = 0o444) {
const fullPath = fspath.join(config.env.cmsPath, path);
function writeRelativeFile(relativePath, content, config, mode = 0o444) {
const fullPath = path.join(config.env.cmsPath, relativePath);
// Prologue: Reset process file mode creation mask to ensure the umask value is not subtracted
const oldmask = umask(0);
// Create missing parent directories with 'rwxrwxrwx'
fs.mkdirSync(fspath.dirname(fullPath), { recursive: true, mode: 0o777 });
fs.mkdirSync(path.dirname(fullPath), { recursive: true, mode: 0o777 });
// Check if the file exists
if (fs.existsSync(fullPath)) {
// Set 'rw-rw-rw-' to be able to overwrite the file
Expand All @@ -51,4 +54,4 @@ function writeFile(path, content, config, mode = 0o444) {
return null;
}

module.exports = { writeFile, deleteFolder };
module.exports = { writeRelativeFile, deleteRelativePath };
4 changes: 2 additions & 2 deletions tests/System/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function setupPlugins(on, config) {
on('task', {
queryDB: (query) => db.queryTestDB(query, config),
cleanupDB: () => db.deleteInsertedItems(config),
writeFile: ({ path, content, mode }) => fs.writeFile(path, content, config, mode),
deleteFolder: (path) => fs.deleteFolder(path, config),
writeRelativeFile: ({ path, content, mode }) => fs.writeRelativeFile(path, content, config, mode),
deleteRelativePath: (path) => fs.deleteRelativePath(path, config),
getMails: () => mail.getMails(),
clearEmails: () => mail.clearEmails(),
startMailServer: () => mail.startMailServer(config),
Expand Down
2 changes: 1 addition & 1 deletion tests/System/support/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ Cypress.Commands.add('config_setParameter', (parameter, value) => {
const content = fileContent.replace(regex, `public $${parameter} = ${newValue};`);

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

0 comments on commit a72ac58

Please sign in to comment.