WordPress.org

Make WordPress Core

#26155 closed defect (bug) (fixed)

Tests_Image_Functions failures

Reported by: SergeyBiryukov Owned by: SergeyBiryukov
Milestone: 3.8 Priority: normal
Severity: normal Version:
Component: Unit Tests Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Three image tests are failing if both fileinfo PHP extension and mime_content_type() function are missing:

1) Tests_Image_Functions::test_wp_save_image_file
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'image/jpeg'
+''

S:\home\wordpress\develop\tests\phpunit\tests\image\functions.php:142
S:\usr\local\php5\phpunit:46

2) Tests_Image_Functions::test_mime_overrides_filename
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'image/gif'
+''

S:\home\wordpress\develop\tests\phpunit\tests\image\functions.php:180
S:\usr\local\php5\phpunit:46

3) Tests_Image_Functions::test_inferred_mime_types
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'image/jpeg'
+''

S:\home\wordpress\develop\tests\phpunit\tests\image\functions.php:225

We should skip these tests if the extension is not loaded, like we do in Tests_Image_Meta:
tags/3.7.1/tests/phpunit/tests/image/meta.php#L8.

Attachments (3)

26155.patch (754 bytes) - added by SergeyBiryukov 17 months ago.
26155.2.patch (1.6 KB) - added by SergeyBiryukov 17 months ago.
ticket-26155-php52-mime.patch (1.7 KB) - added by bpetty 16 months ago.

Download all attachments as: .zip

Change History (7)

@SergeyBiryukov17 months ago

comment:1 @SergeyBiryukov17 months ago

  • Description modified (diff)

@SergeyBiryukov17 months ago

comment:2 @SergeyBiryukov17 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 26318:

Skip image mime type tests if both fileinfo PHP extension and mime_content_type() function are missing.

fixes #26155.

comment:3 @bpetty16 months ago

  • Cc bpetty added
  • Keywords commit removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

These tests still continue to fail under many PHP 5.2 environments (including Travis).

The tests are there to ensure the files saved using the appropriate image format, and it actually turns out that they have (as run under one of these environments):

$ file /tmp/1386267844.jpg
/tmp/1386267844.jpg: JPEG image data, JFIF standard 1.01, comment: "CREATOR: gd-jpeg v1.0 (using IJ"

Tests_Image_Functions::get_mime_type() relies on either the fileinfo extension (which was only built into PHP by default in 5.3+), or uses mime_content_type() to take a stab at guessing what it is. The latter is what is being used in these 5.2 configurations.

However, using mime_content_type() requires that the mime_magic.magicfile INI setting has been configured with a hacked up version of "magic.mime". This file is loosely based on libmagic format, but PHP never supported the full format, you can find an old incomplete version in mime_magic's unit tests, do not confuse this with Apache's mime.type file.

Anyway, this INI setting and magic file is not distributed or configured with PHP 5.2 by default, and this is why these tests fail in those environments.

The fact that a file was still saved with the appropriate file extension is probably a good enough test here, and we actually have a few other unit tests that still check that, so I'm just suggesting we skip attempting to use the mime_content_type() at all for these tests in ticket-26155-php52-mime.patch. This just effectively skips the tests on PHP 5.2.

comment:4 @nacin16 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 26705:

Unit Tests: Avoid using mime_content_type() as it fails miserably in PHP 5.2.

props bpetty.
fixes #26155.

Note: See TracTickets for help on using tickets.