|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of the Propel package. |
| 5 | + * For the full copyright and license information, please view the LICENSE |
| 6 | + * file that was distributed with this source code. |
| 7 | + * |
| 8 | + * @license MIT License |
| 9 | + */ |
| 10 | + |
| 11 | +use Propel\Generator\Util\PhpParser; |
| 12 | +use \Propel\Tests\TestCase; |
| 13 | + |
| 14 | +/** |
| 15 | + * |
| 16 | + */ |
| 17 | +class IconvTransliterationTest extends TestCase |
| 18 | +{ |
| 19 | + |
| 20 | + /** |
| 21 | + * Excerpt from http://php.net/manual/en/function.iconv.php#74101 |
| 22 | + * "Please note that iconv('UTF-8', 'ASCII//TRANSLIT', ...) doesn't work properly when locale category LC_CTYPE is set to C or POSIX. You must choose another locale otherwise all non-ASCII characters will be replaced with question marks." |
| 23 | + */ |
| 24 | + public function testIconvSupportedLocale($in, $out) |
| 25 | + { |
| 26 | + if (!function_exists('iconv')) { |
| 27 | + $this->markTestSkipped(); |
| 28 | + } |
| 29 | + $LC_CTYPE = setlocale(LC_CTYPE, 0); |
| 30 | + $this->assertNotEquals('C', $LC_CTYPE, 'iconv transliteration does not work properly when locale category LC_CTYPE is set to C or POSIX'); |
| 31 | + $this->assertNotEquals('POSIX', $LC_CTYPE, 'iconv transliteration does not work properly when locale category LC_CTYPE is set to C or POSIX'); |
| 32 | + } |
| 33 | + |
| 34 | + public static function iconvTransliterationSlugProvider() |
| 35 | + { |
| 36 | + return [ |
| 37 | + ['foo', 'foo'], |
| 38 | + ['fôo', 'foo'], |
| 39 | + ['€', 'EUR'], |
| 40 | + ['CŠŒŽšœžŸµÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝßàáâãäåæçèéêëìíîïñòóôõöùúûüýÿ', 'CSOEZsoezYuAAAAAAAECEEEEIIIINOOOOOUUUUYssaaaaaaaeceeeeiiiinoooooouuuuyy'], |
| 41 | + ['ø', 'oe'], |
| 42 | + ['Ø', 'OE'], |
| 43 | + ['¥Ðð', '???'], |
| 44 | + ]; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @dataProvider iconvTransliterationSlugProvider |
| 49 | + */ |
| 50 | + public function testIconvTransliteration($in, $out) |
| 51 | + { |
| 52 | + if (!function_exists('iconv')) { |
| 53 | + $this->markTestSkipped(); |
| 54 | + } |
| 55 | + $translit = iconv('utf-8', 'us-ascii//TRANSLIT', $in); |
| 56 | + $this->assertEquals($out, $translit, 'iconv transliteration behaves as expected'); |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments