Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Add Files folder to Media component and to "FileSystem local" adapter #43532

Open
wants to merge 16 commits into
base: 5.2-dev
Choose a base branch
from
Prev Previous commit
Next Next commit
test
  • Loading branch information
Fedik committed May 29, 2024
commit 1350604a11257c9d96414687e0d09af5f930f479
44 changes: 29 additions & 15 deletions tests/System/integration/api/com_media/Files.cy.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
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'));
beforeEach(() => {
cy.task('writeFile', { path: 'images/test-dir/dummy.txt', content: '1' });
cy.task('writeFile', { path: 'files/test-dir/dummy.txt', content: '1' });

// Copy test image to /files folder
cy.readFile('tests/System/data/com_media/test-image-1.jpg', 'binary').then((data) => {
return cy.writeFile('files/test-image-1.jpg', data, 'binary').then(() => {
cy.writeFile('files/test-dir/test-image-1-subfolder.jpg', data, 'binary')
});
});
});
afterEach(() => {
cy.task('deleteFolder', 'images/test-dir');
cy.task('deleteFolder', 'files/test-dir');
cy.task('deleteFolder', 'files/test-image-1.jpg');
});

it('can deliver a list of files', () => {
cy.api_get('/media/files')
.then((response) => {
cy.api_responseContains(response, 'name', 'banners');
cy.api_responseContains(response, 'name', 'joomla_black.png');
cy.api_responseContains(response, 'name', 'test-dir');
cy.api_responseContains(response, 'name', 'test-image-1.jpg');
});
});

it('can deliver a list of files in a subfolder', () => {
cy.api_get('/media/files/sampledata/cassiopeia/')
.then((response) => cy.api_responseContains(response, 'name', 'nasa1-1200.jpg'));
cy.api_get('/media/files/test-dir/')
.then((response) => cy.api_responseContains(response, 'name', 'test-image-1-subfolder.jpg'));
});

it('can deliver a list of files with an adapter', () => {
Expand All @@ -22,29 +36,29 @@ describe('Test that media files API endpoint', () => {
});

it('can search in filenames', () => {
cy.api_get('/media/files?filter[search]=joomla')
cy.api_get('/media/files/local-images:/?filter[search]=joomla')
.then((response) => {
cy.api_responseContains(response, 'name', 'joomla_black.png');
cy.wrap(response).its('body').its('data').should('have.length', 1);
});
});

it('can deliver a single file', () => {
cy.api_get('/media/files/joomla_black.png')
cy.api_get('/media/files/local-images:/joomla_black.png')
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('name')
.should('include', 'joomla_black.png'));
});

it('can deliver a single file with the url', () => {
cy.api_get('/media/files/joomla_black.png?url=1')
cy.api_get('/media/files/local-images:/joomla_black.png?url=1')
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('url')
.should('include', 'joomla_black.png'));
});

it('can deliver a single folder', () => {
cy.api_get('/media/files/sampledata/cassiopeia')
cy.api_get('/media/files/local-images:/sampledata/cassiopeia')
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('name')
.should('include', 'cassiopeia'));
Expand All @@ -71,7 +85,7 @@ describe('Test that media files API endpoint', () => {
.should('include', 'test-from-create');
cy.wrap(response).its('body').its('data').its('attributes')
.its('path')
.should('include', 'local-images:/test-dir/test-from-create');
.should('include', 'local-files:/test-dir/test-from-create');
});
});

Expand Down Expand Up @@ -112,7 +126,7 @@ describe('Test that media files API endpoint', () => {
.should('include', 'override.jpg');
cy.wrap(response).its('body').its('data').its('attributes')
.its('path')
.should('include', 'local-images:/test-dir/override.jpg');
.should('include', 'local-files:/test-dir/override.jpg');
});
});

Expand All @@ -125,7 +139,7 @@ describe('Test that media files API endpoint', () => {
.should('include', 'override-new');
cy.wrap(response).its('body').its('data').its('attributes')
.its('path')
.should('include', 'local-images:/test-dir/override-new');
.should('include', 'local-files:/test-dir/override-new');
});
});

Expand Down Expand Up @@ -159,12 +173,12 @@ 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('writeFile', { path: 'files/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('writeFile', { path: 'files/test-dir/todelete/dummy.txt', content: '1' })
.then(() => cy.api_delete('/media/files/test-dir/todelete'));
});

Expand Down