|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Tests for wp_specialchars_decode(). |
| 5 | + * |
| 6 | + * @group formatting |
| 7 | + * |
| 8 | + * @covers ::wp_specialchars_decode |
| 9 | + */ |
| 10 | +class Tests_Formatting_wpSpecialcharsDecode extends WP_UnitTestCase { |
| 11 | + |
| 12 | + /** |
| 13 | + * @ticket 65819 |
| 14 | + * |
| 15 | + * @dataProvider data_wp_specialchars_decode |
| 16 | + * |
| 17 | + * @param string $text Text to decode. |
| 18 | + * @param string $expected Expected decoded text. |
| 19 | + * @param string|int|null $quote_style Optional quote style. Null omits the argument so the helper default is used. |
| 20 | + */ |
| 21 | + public function test_wp_specialchars_decode( $text, $expected, $quote_style = null ) { |
| 22 | + if ( null === $quote_style ) { |
| 23 | + $this->assertSame( $expected, wp_specialchars_decode( $text ) ); |
| 24 | + } else { |
| 25 | + $this->assertSame( $expected, wp_specialchars_decode( $text, $quote_style ) ); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Data provider. |
| 31 | + * |
| 32 | + * @return array[] |
| 33 | + */ |
| 34 | + public static function data_wp_specialchars_decode() { |
| 35 | + return array( |
| 36 | + 'empty string' => array( '', '' ), |
| 37 | + 'no entities fast path' => array( 'hello world', 'hello world' ), |
| 38 | + 'default decodes amp lt gt' => array( 'A & B <C>', 'A & B <C>' ), |
| 39 | + 'default leaves double quotes' => array( '"quoted"', '"quoted"' ), |
| 40 | + 'default leaves single quotes' => array( ''quoted'', ''quoted'' ), |
| 41 | + 'ENT_QUOTES decodes both quotes' => array( '"'hi'"', '"\'hi\'"', ENT_QUOTES ), |
| 42 | + 'ENT_COMPAT decodes doubles' => array( '"hi'', '"hi'', ENT_COMPAT ), |
| 43 | + 'double style decodes doubles' => array( '"hi'', '"hi'', 'double' ), |
| 44 | + 'single style decodes singles' => array( '"'hi'', '"\'hi\'', 'single' ), |
| 45 | + 'numeric amp entity' => array( '&', '&' ), |
| 46 | + 'hex amp entity' => array( '&', '&' ), |
| 47 | + 'padded decimal amp' => array( '&', '&' ), |
| 48 | + 'padded hex amp' => array( '&', '&' ), |
| 49 | + ); |
| 50 | + } |
| 51 | +} |
0 commit comments