Skip to content

Commit 2ad57e1

Browse files
committed
Tests: Cover special character entity decoding.
Test `wp_specialchars_decode()` with its default quote handling, explicit quote modes, named and numeric entities, and zero-padded numeric entities. Preserve literal expectations for each decoded result. Developed in: #14659 Props shailu25, huzaifaalmesbah, mukesh27. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@64758 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8dd36d0 commit 2ad57e1

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 &amp; B &lt;C&gt;', 'A & B <C>' ),
39+
'default leaves double quotes' => array( '&quot;quoted&quot;', '&quot;quoted&quot;' ),
40+
'default leaves single quotes' => array( '&#039;quoted&#039;', '&#039;quoted&#039;' ),
41+
'ENT_QUOTES decodes both quotes' => array( '&quot;&#039;hi&#039;&quot;', '"\'hi\'"', ENT_QUOTES ),
42+
'ENT_COMPAT decodes doubles' => array( '&quot;hi&#039;', '"hi&#039;', ENT_COMPAT ),
43+
'double style decodes doubles' => array( '&quot;hi&#039;', '"hi&#039;', 'double' ),
44+
'single style decodes singles' => array( '&quot;&#039;hi&#039;', '&quot;\'hi\'', 'single' ),
45+
'numeric amp entity' => array( '&#038;', '&' ),
46+
'hex amp entity' => array( '&#x26;', '&' ),
47+
'padded decimal amp' => array( '&#0038;', '&' ),
48+
'padded hex amp' => array( '&#x0026;', '&' ),
49+
);
50+
}
51+
}

0 commit comments

Comments
 (0)