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

[Cypress] PHP Backend Notice com_media/Files #44976

Merged
merged 5 commits into from
Feb 28, 2025

Conversation

muhme
Copy link
Contributor

@muhme muhme commented Feb 22, 2025

Summary of Changes

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 are in the overall Joomla System Tests.

And 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:

[Tue Feb 25 15:40:25.066140 2025] [php:warn] [pid 19962] [client 127.0.0.1:50234] PHP Warning:  file_put_contents(/home/hlu/Desktop/joomla-cms/files/test-dir/override.jpg): Failed to open stream: Permission denied in /home/hlu/Desktop/joomla-cms/libraries/vendor/joomla/filesystem/src/File.php on line 265

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.

Testing Instructions

In an Joomla System Tests env run

npx cypress run --spec tests/System/integration/api/com_media/Files.cy.js

Actual result BEFORE applying this Pull Request

Before the patch you see the 8 notices in PHP backend (e.g. on macOS brew installed Apache in file /usr/local/var/log/httpd/error_log).

Note: JBT >= 2.1.21 shows the PHP backend error, warning and notice

Expected result AFTER applying this Pull Request

After installing the PR the notice messages and the overwrite warning messages are gone and the Joomla System Test is still running w/o errors.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

Sorry, something went wrong.

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.
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
```
@brianteeman
Copy link
Contributor

CypressError: `cy.task('copyRelativeFile')` failed with the following error:

> ENOENT: no such file or directory, copyfile 'D:\repos\D:\repos\j51\tests\System\fixtures\com_media\test-image-1.jpg' -> 'D:\repos\j51\files\test-image-1.jpg'

@brianteeman
Copy link
Contributor

I have tested this item 🔴 unsuccessfully on acf4f58


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44976.

@laoneo
Copy link
Member

laoneo commented Feb 24, 2025

Can you explain why you changed the folder to fixtures?

@alikon
Copy link
Contributor

alikon commented Feb 24, 2025

i've got similar result as @brianteeman
image

i guess some windows filesystem issue ?

@brianteeman
Copy link
Contributor

i guess some windows filesystem issue ?

check your php error logs you will see the faulty path in full

@muhme
Copy link
Contributor Author

muhme commented Feb 27, 2025

I can confirm the ENOENT: no such file or directory problem on Windows, have a fix and see one more small new problem with file override.jpg on Ubuntu and Windows, as it is created read-only:

[Tue Feb 25 15:40:25.066140 2025] [php:warn] [pid 19962] [client 127.0.0.1:50234] PHP Warning:  file_put_contents(/home/hlu/Desktop/joomla-cms/files/test-dir/override.jpg): Failed to open stream: Permission denied in /home/hlu/Desktop/joomla-cms/libraries/vendor/joomla/filesystem/src/File.php on line 265

I'm in getting it to work in Windows, Ubuntu, macOS and Docker Debian. I want to test all platforms first ...

@muhme
Copy link
Contributor Author

muhme commented Feb 27, 2025

Can you explain why you changed the folder to fixtures?

The fixtures folder is the default in Cypress and is configured via the fixturesFolder setting in the Cypress config. As I did a bit of refactoring and the two PNG images were not in use, I moved the remaining JPG to fixtures. I would also recommend (and plan to) move the last file, data/com_newsfeed/joomla.org.xml, to fixtures/com_newsfeed, which would remove the data folder entirely. ok?

@muhme muhme marked this pull request as draft February 27, 2025 06:28
- 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`
@muhme
Copy link
Contributor Author

muhme commented Feb 27, 2025

Fixed the Windows path problem and additional the problem with overwrite files created read-only. Tested successfully on:

  • macOS 15.3.1 Intel
  • macOS 15.3.1 Apple Silicon
  • Windows 11 24H2
  • Ubuntu 24.04
  • Docker based Debian 11

@brianteeman and @alikon Could you please retest? ☺️

@muhme Remember yourself, always if something file-system based is changed, you have to test on all platforms! 😠

@muhme muhme marked this pull request as ready for review February 27, 2025 18:31
@brianteeman
Copy link
Contributor

I have tested this item ✅ successfully on 92ee23f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44976.

@alikon
Copy link
Contributor

alikon commented Feb 27, 2025

I have tested this item ✅ successfully on 92ee23f

on windows 11


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44976.

@alikon
Copy link
Contributor

alikon commented Feb 27, 2025

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/44976.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Feb 27, 2025
@laoneo laoneo merged commit 6af88f5 into joomla:5.3-dev Feb 28, 2025
3 checks passed
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Feb 28, 2025
@laoneo
Copy link
Member

laoneo commented Feb 28, 2025

Thanks!

@laoneo laoneo added this to the Joomla! 5.3.0 milestone Feb 28, 2025
@muhme muhme deleted the cypress-com-media branch February 28, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants