|
10 | 10 | * @covers ::_canonical_charset |
11 | 11 | */ |
12 | 12 | class Tests_Functions_CanonicalCharset extends WP_UnitTestCase { |
13 | | - |
14 | | - public function test_utf_8_lower() { |
15 | | - $this->assertSame( 'UTF-8', _canonical_charset( 'utf-8' ) ); |
16 | | - } |
17 | | - |
18 | | - public function test_utf_8_upper() { |
19 | | - $this->assertSame( 'UTF-8', _canonical_charset( 'UTF-8' ) ); |
20 | | - } |
21 | | - |
22 | | - public function test_utf_8_mixxed() { |
23 | | - $this->assertSame( 'UTF-8', _canonical_charset( 'Utf-8' ) ); |
24 | | - } |
25 | | - |
26 | | - public function test_utf_8() { |
27 | | - $this->assertSame( 'UTF-8', _canonical_charset( 'UTF8' ) ); |
28 | | - } |
29 | | - |
30 | | - public function test_iso_lower() { |
31 | | - $this->assertSame( 'ISO-8859-1', _canonical_charset( 'iso-8859-1' ) ); |
32 | | - } |
33 | | - |
34 | | - public function test_iso_upper() { |
35 | | - $this->assertSame( 'ISO-8859-1', _canonical_charset( 'ISO-8859-1' ) ); |
36 | | - } |
37 | | - |
38 | | - public function test_iso_mixxed() { |
39 | | - $this->assertSame( 'ISO-8859-1', _canonical_charset( 'Iso8859-1' ) ); |
40 | | - } |
41 | | - |
42 | | - public function test_iso() { |
43 | | - $this->assertSame( 'ISO-8859-1', _canonical_charset( 'ISO8859-1' ) ); |
44 | | - } |
45 | | - |
46 | | - public function test_random() { |
47 | | - $this->assertSame( 'random', _canonical_charset( 'random' ) ); |
| 13 | + /** |
| 14 | + * Ensures that charset variants for common encodings normalize to the expected form. |
| 15 | + * |
| 16 | + * @ticket 61182 |
| 17 | + * |
| 18 | + * @dataProvider data_charset_normalizations |
| 19 | + * |
| 20 | + * @param string $given_charset Potential charset provided by user. |
| 21 | + * @param string $normalized_charset Expected normalized form of charset. |
| 22 | + */ |
| 23 | + public function test_properly_normalizes_charset_variants( $given_charset, $normalized_charset ) { |
| 24 | + $this->assertSame( |
| 25 | + $normalized_charset, |
| 26 | + _canonical_charset( $given_charset ), |
| 27 | + 'Did not properly transform the provided charset into its normalized form.' |
| 28 | + ); |
48 | 29 | } |
49 | 30 |
|
50 | | - public function test_empty() { |
51 | | - $this->assertSame( '', _canonical_charset( '' ) ); |
| 31 | + /** |
| 32 | + * Data provider. |
| 33 | + * |
| 34 | + * @return array[]. |
| 35 | + */ |
| 36 | + public static function data_charset_normalizations() { |
| 37 | + return array( |
| 38 | + // UTF-8 family. |
| 39 | + array( 'UTF-8', 'UTF-8' ), |
| 40 | + array( 'Utf-8', 'UTF-8' ), |
| 41 | + array( 'Utf-8', 'UTF-8' ), |
| 42 | + array( 'UTF8', 'UTF-8' ), |
| 43 | + |
| 44 | + // Almost UTF-8. |
| 45 | + array( 'UTF-8*', 'UTF-8*' ), |
| 46 | + array( 'UTF.8', 'UTF.8' ), |
| 47 | + array( 'UTF88', 'UTF88' ), |
| 48 | + array( 'UTF-7', 'UTF-7' ), |
| 49 | + array( 'X-UTF-8', 'X-UTF-8' ), |
| 50 | + |
| 51 | + // ISO-8859-1 family. |
| 52 | + array( 'iso-8859-1', 'ISO-8859-1' ), |
| 53 | + array( 'ISO-8859-1', 'ISO-8859-1' ), |
| 54 | + array( 'Iso-8859-1', 'ISO-8859-1' ), |
| 55 | + array( 'ISO8859-1', 'ISO-8859-1' ), |
| 56 | + |
| 57 | + // Other charset slugs should not be adjusted. |
| 58 | + array( 'random', 'random' ), |
| 59 | + array( '', '' ), |
| 60 | + ); |
52 | 61 | } |
53 | 62 |
|
54 | 63 | /** |
|
0 commit comments