Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Updated: Comment #N
Problem/Motivation
\Drupal\Tests\Component\Utility\UnicodeTest
uses Windows-1250 strings to test \Drupal\Component\Utility\Unicode
. However, mbstring does not support this character encoding and fails.
Steps to reproduce
- Clone/pull the most recent Drupal core.
- Install Drupal on a host with mbstring, but not
iconv()
.
- Run PHPUnit using core's configuration and bootstrap files. There will be three test failures in
\Drupal\Tests\Component\Utility\UnicodeTest::testConvertToUtf8()
Proposed resolution
iconv()
.\Drupal\Tests\Component\Utility\UnicodeTest::testConvertToUtf8()
Use another encoding, such as Windows-1252.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#15 | drupal_2149827_15.patch | 752 bytes | Xano |
Comments
Comment #1
dawehnerIt works fine for me.
Maybe you could paste the full failure.
Comment #2
XanoThe three full failures.
Comment #3
Mile23@Xano: I'd wager you don't have iconv, mbstring, or recode installed on your PHP.
Unicode::convertToUtf8() returns FALSE in that case, and the unit tests don't account for that.
Yay! You found the edge case! :-)
This needs to happen: http://phpunit.de/manual/3.7/en/incomplete-and-skipped-tests.html#incomp...
Comment #4
Mile23A patch to solve the error, but not the testing problem.
This only checks if the conversion functions exist or not, and checks for FALSE if they don't.
The method we're checking here is this one: http://drupalcode.org/project/drupal.git/blob/HEAD:/core/lib/Drupal/Comp...
Comment #5
XanoI wonder if this is a faulty test, or a missing requirement for Drupal core.
Comment #6
Mile23It's both. :-) In this case, however, Drupal handles the case where the requirements aren't met, so we have to test that outcome.
That's why I just patched it so it would pass, with a @todo. It leads to an interesting question: Should unit tests fail if the requirements aren't met?
Comment #7
XanoWhat about this approach? We test
Unicode::check()
and make sure that passes before we test anything that depends on it.Comment #8
XanoThe assert in the previous patch was faulty. This actually works on my system that (apparently) doesn't have any PHP Unicode extension.
Comment #9
Mile23Well, that's kind of the question: Am I right in my assumptions? :-)
Make a phpinfo() page and find out if you have mbstring, iconv, and/or recode.
You can also do this as
php -i
at the command line and look to see if they're in your system.Comment #11
Xano8: drupal_2149827_8.patch queued for re-testing.
I do have mbstring locally, and so do the testbots, so this shouldn't have failed at all.
Comment #12
XanoErr, never mind that last patch. The patch from #7 is good.
Comment #14
Xanomb_convert_encoding()
saysWindows-1250
is an illegal character encoding.Edit:
mb_list_encodings()
only returns Windows-1251, Windows-1252, and Windows-1254 as Windows encodings.Comment #15
XanoThis works locally. However, there is no way of knowing which encodings
iconv()
supports as that depends on its internal library, and I haven't been able to find out which encodings are supported byrecode_string()
.Comment #16
XanoComment #17
XanoComment #18
Mile23I'm Mile23, and I approve this patch.
Comment #19
catchCommitted/pushed to 8.x, thanks!