Unit testing to support Unicode

I am trying to convert to unicode and create some unit tests to ensure unicode is working.

Here is my current code that crashes in the mb_detect_encoding () line, and which I am also not sure if it is a valid unicode support test:

    function testMultiLingualEncodings(){
        // Create this string via a heredoc.
        $original = '
        A good day, World!
Schönen Tag, Welt!
Une bonne journée, tout le monde!
يوم جيد، العالم
좋은 일, 세계!
Một ngày tốt lành, thế giới!
こんにちは、世界!
'; // Contains international characters from utf-8
        $this->assertTrue(mb_detect_encoding($original, 'UTF-8', true) === true); // Fails regardless of whether strict is true or not.
        $returned = query_item("select :multi limit 10", array(':multi'=>$original)); // Select this exact string, parameterized, from the database
        //debug($returned, string_diff($returned, $original));
        $this->assertTrue((bool)$original); // test original isn't null.
        $this->assertTrue((bool)$returned); // Test returned string isn't null.
        $this->assertTrue($original === $returned); // Test original exactly matches returned string
    }

So mb_detect_encoding () says the start line above is not UTF-8. I am also trying to pass this string to the database and get it, and then compare with the original string. However, I'm not sure if this is a valid test for encoding a database connection.

In general, how can I create unit test support for utf-8, and the method is higher than what can be changed to solve this?

+1
1

, . . , , , . mb_detect_encoding. : "abcde". ASCII UTF-8. , . - , .

//EDIT

$this->assertTrue(mb_detect_encoding($original, 'UTF-8') === 'UTF-8')

+3

Source: https://habr.com/ru/post/1528769/


All Articles