Skip to content

Commit 6af88f5

Browse files
muhmelaoneordeutz
authored
[Cypress] PHP Backend Notice com_media/Files (joomla#44976)
* [Cypress] PHP Backend Notice com_media/Files.cy.js Fixing all Joomla backend PHP notices from Cypress test file `api/com_media/Files.cy.js` and doing some refactoring. Fixed PHP notices are: ``` [Sat Feb 22 18:28:44.019593 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice: exif_imagetype(): Error reading from /var/www/html/files/test-image-1.jpg! in /var/www/html/libraries/src/Helper/MediaHelper.php on line 93 [Sat Feb 22 18:28:44.022074 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice: getimagesize(): Error reading from /var/www/html/files/test-image-1.jpg! in /var/www/html/libraries/src/Image/Image.php on line 177 [Sat Feb 22 18:28:44.258619 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice: exif_imagetype(): Error reading from /var/www/html/files/test-dir/test-image-1-subfolder.jpg! in /var/www/html/libraries/src/Helper/MediaHelper.php on line 93 [Sat Feb 22 18:28:44.259092 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice: getimagesize(): Error reading from /var/www/html/files/test-dir/test-image-1-subfolder.jpg! in /var/www/html/libraries/src/Image/Image.php on line 177 [Sat Feb 22 18:28:47.177357 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice: exif_imagetype(): Error reading from /var/www/html/files/test-dir/todelete.jpg! in /var/www/html/libraries/src/Helper/MediaHelper.php on line 93 [Sat Feb 22 18:28:47.178099 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice: getimagesize(): Error reading from /var/www/html/files/test-dir/todelete.jpg! in /var/www/html/libraries/src/Image/Image.php on line 177 [Sat Feb 22 18:28:47.564807 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice: exif_imagetype(): Error reading from /var/www/html/images/test-dir/todelete.jpg! in /var/www/html/libraries/src/Helper/MediaHelper.php on line 93 [Sat Feb 22 18:28:47.565288 2025] [php:notice] [pid 31:tid 31] [client 10.0.0.1:64714] PHP Notice: getimagesize(): Error reading from /var/www/html/images/test-dir/todelete.jpg! in /var/www/html/libraries/src/Image/Image.php on line 177 ``` All 8 x PHP notices are fixed. Instead of using 1-Byte files real images are used from Cypress fixtures. Please consider there are still 4 x PHP warning to be fixed (I assume they need to be fixed in PHP API backend code) from `api/com_media/Files.cy.js` and more warnings and notices in the overall Joomla System Tests. Some refactoring: * Deleted 3 images in `tests/System/data/com_media`, 2 are not used and Cypress default is to use `fixtures` folder * The image file names are counted through and the images show name and path in different colors. * Second `test-dir` was named `test-dir2` to distinguish clearly. * `afterEach()` is reduced to `after()`, as it is only a clean-up and not needed to execute the tests. * The last 4 tests can use the prepared files too, as with `beforeEach` the files are restored before each test. * Corrected Image Description to test-dir2 Used command: ``` convert -size 100x100 -gravity center -pointsize 11 xc:lightgreen -fill red -annotate +0+0 'Joomla\nSystem Tests\n\nimages/test-dir2\ntest-image-3.jpg' tests/System/fixtures/com_media/test-image-3.jpg ``` * Fix for Windows Path and Read-Only Overwrites - Creating relative fixtures folder path now also works on Windows with backslashes as separators and a drive letter - All overwrite files are now created with explicit read-write 0o666, as the default 0o444 creates read-only files, leading to PHP Warnings `Failed to open` --------- Co-authored-by: Allon Moritz <[email protected]> Co-authored-by: Robert Deutz <[email protected]>
1 parent 4c6bb85 commit 6af88f5

File tree

7 files changed

+46
-38
lines changed

7 files changed

+46
-38
lines changed
-3.4 KB
Binary file not shown.
-255 Bytes
Binary file not shown.
-255 Bytes
Binary file not shown.
4.67 KB
Loading
5.2 KB
Loading
4.78 KB
Loading

tests/System/integration/api/com_media/Files.cy.js

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
describe('Test that media files API endpoint', () => {
2-
// Ensure 'test-dir' (relative to cmsPath) is available and has correct permissions
2+
// Create relative path to the fixtures images directory, from Cypress config and platform independent
3+
const fixturesFolder = Cypress.config('fixturesFolder').replace(/\\/g, '/');
4+
// projectRoot is e.g. 'C:\laragon\www\joomla53\tests\System\fixtures'
5+
const projectRoot = Cypress.config('projectRoot').replace(/\\/g, '/');
6+
// Result is e.g. 'tests/System/fixtures/com_media'
7+
const mediaFixturesFolder = `${fixturesFolder
8+
.replace(projectRoot, '')
9+
.replace(/^\//, '')}/com_media`;
10+
11+
// Create directories and test images before running each test
312
beforeEach(() => {
4-
cy.task('writeRelativeFile', { path: 'images/test-dir/dummy.txt', content: '1' });
5-
cy.task('writeRelativeFile', { path: 'files/test-image-1.jpg', content: '1' });
13+
// Ensure 'files/test-dir' exists (relative to cmsPath) and has the correct permissions
614
cy.task('writeRelativeFile', { path: 'files/test-dir/dummy.txt', content: '1' });
7-
cy.task('writeRelativeFile', { path: 'files/test-dir/test-image-1-subfolder.jpg', content: '1' });
8-
});
9-
// If it exists, delete the 'test-dir' (relative to cmsPath) and its contents
10-
afterEach(() => {
11-
cy.task('deleteRelativePath', 'images/test-dir');
15+
// Ensure 'images/test-dir2' exists (relative to cmsPath) and has the correct permissions
16+
cy.task('writeRelativeFile', { path: 'images/test-dir2/dummy.txt', content: '1' });
17+
cy.task('copyRelativeFile', { source: `${mediaFixturesFolder}/test-image-1.jpg`, destination: 'files/test-image-1.jpg' });
18+
cy.task('copyRelativeFile', { source: `${mediaFixturesFolder}/test-image-2.jpg`, destination: 'files/test-dir/test-image-2.jpg' });
19+
cy.task('copyRelativeFile', { source: `${mediaFixturesFolder}/test-image-3.jpg`, destination: 'images/test-dir2/test-image-3.jpg' });
20+
});
21+
// Delete all files and directories created during the test, only for clean-up and only if they exist
22+
after(() => {
1223
cy.task('deleteRelativePath', 'files/test-dir');
24+
cy.task('deleteRelativePath', 'images/test-dir2');
1325
cy.task('deleteRelativePath', 'files/test-image-1.jpg');
1426
});
1527

@@ -23,7 +35,7 @@ describe('Test that media files API endpoint', () => {
2335

2436
it('can deliver a list of files in a subfolder', () => {
2537
cy.api_get('/media/files/test-dir/')
26-
.then((response) => cy.api_responseContains(response, 'name', 'test-image-1-subfolder.jpg'));
38+
.then((response) => cy.api_responseContains(response, 'name', 'test-image-2.jpg'));
2739
});
2840

2941
it('can deliver a list of files with an adapter', () => {
@@ -61,7 +73,7 @@ describe('Test that media files API endpoint', () => {
6173
});
6274

6375
it('can create a file without adapter', () => {
64-
cy.readFile('tests/System/data/com_media/test-image-1.jpg', 'binary')
76+
cy.readFile('tests/System/fixtures/com_media/test-image-1.jpg', 'binary')
6577
.then((data) => cy.api_post('/media/files', { path: 'test-dir/test.jpg', content: Buffer.from(data, 'binary').toString('base64') }))
6678
.then((response) => {
6779
cy.wrap(response).its('body').its('data').its('attributes')
@@ -86,33 +98,33 @@ describe('Test that media files API endpoint', () => {
8698
});
8799

88100
it('can create a file with adapter', () => {
89-
cy.readFile('tests/System/data/com_media/test-image-1.jpg', 'binary')
90-
.then((data) => cy.api_post('/media/files', { path: 'local-images:/test-dir/test.jpg', content: Buffer.from(data, 'binary').toString('base64') }))
101+
cy.readFile('tests/System/fixtures/com_media/test-image-2.jpg', 'binary')
102+
.then((data) => cy.api_post('/media/files', { path: 'local-images:/test-dir2/test.jpg', content: Buffer.from(data, 'binary').toString('base64') }))
91103
.then((response) => {
92104
cy.wrap(response).its('body').its('data').its('attributes')
93105
.its('name')
94106
.should('include', 'test.jpg');
95107
cy.wrap(response).its('body').its('data').its('attributes')
96108
.its('path')
97-
.should('include', 'local-images:/test-dir/test.jpg');
109+
.should('include', 'local-images:/test-dir2/test.jpg');
98110
});
99111
});
100112

101113
it('can create a folder with adapter', () => {
102-
cy.api_post('/media/files', { path: 'local-images:/test-dir/test-from-create' })
114+
cy.api_post('/media/files', { path: 'local-images:/test-dir2/test-from-create' })
103115
.then((response) => {
104116
cy.wrap(response).its('body').its('data').its('attributes')
105117
.its('name')
106118
.should('include', 'test-from-create');
107119
cy.wrap(response).its('body').its('data').its('attributes')
108120
.its('path')
109-
.should('include', 'local-images:/test-dir/test-from-create');
121+
.should('include', 'local-images:/test-dir2/test-from-create');
110122
});
111123
});
112124

113125
it('can update a file without adapter', () => {
114-
cy.task('writeRelativeFile', { path: 'files/test-dir/override.jpg', content: '1' })
115-
.then(() => cy.readFile('tests/System/data/com_media/test-image-1.jpg', 'binary'))
126+
cy.task('writeRelativeFile', { path: 'files/test-dir/override.jpg', content: '1', mode: 0o666 })
127+
.then(() => cy.readFile('tests/System/fixtures/com_media/test-image-1.jpg', 'binary'))
116128
.then((data) => cy.api_patch(
117129
'/media/files/test-dir/override.jpg',
118130
{ path: 'test-dir/override.jpg', content: Buffer.from(data, 'binary').toString('base64') },
@@ -127,7 +139,7 @@ describe('Test that media files API endpoint', () => {
127139
});
128140

129141
it('can update a folder without adapter', () => {
130-
cy.task('writeRelativeFile', { path: 'files/test-dir/override/test.jpg', content: '1' })
142+
cy.task('writeRelativeFile', { path: 'files/test-dir/override/test.jpg', content: '1', mode: 0o666 })
131143
.then(() => cy.api_patch('/media/files/test-dir/override', { path: 'test-dir/override-new' }))
132144
.then((response) => {
133145
cy.wrap(response).its('body').its('data').its('attributes')
@@ -140,51 +152,47 @@ describe('Test that media files API endpoint', () => {
140152
});
141153

142154
it('can update a file with adapter', () => {
143-
cy.task('writeRelativeFile', { path: 'images/test-dir/override.jpg', content: '1' })
144-
.then(() => cy.readFile('tests/System/data/com_media/test-image-1.jpg', 'binary'))
155+
cy.task('writeRelativeFile', { path: 'images/test-dir2/override.jpg', content: '1', mode: 0o666 })
156+
.then(() => cy.readFile('tests/System/fixtures/com_media/test-image-2.jpg', 'binary'))
145157
.then((data) => cy.api_patch(
146-
'/media/files/local-images:/test-dir/override.jpg',
147-
{ path: 'local-images:/test-dir/override.jpg', content: Buffer.from(data, 'binary').toString('base64') },
158+
'/media/files/local-images:/test-dir2/override.jpg',
159+
{ path: 'local-images:/test-dir2/override.jpg', content: Buffer.from(data, 'binary').toString('base64') },
148160
)).then((response) => {
149161
cy.wrap(response).its('body').its('data').its('attributes')
150162
.its('name')
151163
.should('include', 'override.jpg');
152164
cy.wrap(response).its('body').its('data').its('attributes')
153165
.its('path')
154-
.should('include', 'local-images:/test-dir/override.jpg');
166+
.should('include', 'local-images:/test-dir2/override.jpg');
155167
});
156168
});
157169

158170
it('can update a folder with adapter', () => {
159-
cy.task('writeRelativeFile', { path: 'images/test-dir/override/test.jpg', content: '1' })
160-
.then(() => cy.api_patch('/media/files/local-images:/test-dir/override', { path: 'local-images:/test-dir/override-new' }))
171+
cy.task('writeRelativeFile', { path: 'images/test-dir2/override/test.jpg', content: '1', mode: 0o666 })
172+
.then(() => cy.api_patch('/media/files/local-images:/test-dir2/override', { path: 'local-images:/test-dir2/override-new' }))
161173
.then((response) => {
162174
cy.wrap(response).its('body').its('data').its('attributes')
163175
.its('name')
164176
.should('include', 'override-new');
165177
cy.wrap(response).its('body').its('data').its('attributes')
166178
.its('path')
167-
.should('include', 'local-images:/test-dir/override-new');
179+
.should('include', 'local-images:/test-dir2/override-new');
168180
});
169181
});
170182

171-
it('can delete a file without adapter', () => {
172-
cy.task('writeRelativeFile', { path: 'files/test-dir/todelete.jpg', content: '1' })
173-
.then(() => cy.api_delete('/media/files/test-dir/todelete.jpg'));
183+
it("can delete an image in 'files' without adapter", () => {
184+
cy.api_delete('/media/files/test-dir/test-image-2.jpg');
174185
});
175186

176-
it('can delete a folder without adapter', () => {
177-
cy.task('writeRelativeFile', { path: 'files/test-dir/todelete/dummy.txt', content: '1' })
178-
.then(() => cy.api_delete('/media/files/test-dir/todelete'));
187+
it("can delete a folder in 'files' without adapter", () => {
188+
cy.api_delete('/media/files/test-dir');
179189
});
180190

181-
it('can delete a file with adapter', () => {
182-
cy.task('writeRelativeFile', { path: 'images/test-dir/todelete.jpg', content: '1' })
183-
.then(() => cy.api_delete('/media/files/local-images:/test-dir/todelete.jpg'));
191+
it("can delete an image in 'images' with adapter", () => {
192+
cy.api_delete('/media/files/local-images:/test-dir2/test-image-3.jpg');
184193
});
185194

186-
it('can delete a folder with adapter', () => {
187-
cy.task('writeRelativeFile', { path: 'images/test-dir/todelete/dummy.txt', content: '1' })
188-
.then(() => cy.api_delete('/media/files/local-images:/test-dir/todelete'));
195+
it("can delete a folder in 'images' with adapter", () => {
196+
cy.api_delete('/media/files/local-images:/test-dir2');
189197
});
190198
});

0 commit comments

Comments
 (0)