Skip to content

Commit 388c50d

Browse files
committed
PR Feedback
1 parent 96bebe4 commit 388c50d

4 files changed

Lines changed: 44 additions & 14 deletions

File tree

src/wp-includes/class-wp-token-map.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,20 @@
3636
* '😕' === $smilies->read_token( 'Not sure :?.', 9, $bytes_skipped );
3737
* 2 === $bytes_skipped;
3838
*
39-
* echo $smilies->precomputed_php_source_table( ' ' );
40-
* // Output.
39+
* ## Precomputing the Token Map.
40+
*
41+
* Creating the class involves some work sorting and organizing the tokens and their
42+
* replacement values. In order to skip this, it's possible for the class to export
43+
* its state and be used as actual PHP source code.
44+
*
45+
* Example:
46+
*
47+
* // Export with four spaces as the indent, only for the sake of this docblock.
48+
* // The default indent is a tab character.
49+
* $indent = ' ';
50+
* echo $smilies->precomputed_php_source_table( $indent );
51+
*
52+
* // Output, to be pasted into a PHP source file:
4153
* WP_Token_Map::from_precomputed_table(
4254
* 2,
4355
* "",
@@ -253,7 +265,7 @@ public static function from_array( $mappings, $key_length = 2 ) {
253265
_doing_it_wrong(
254266
__METHOD__,
255267
__( 'Token Map tokens and substitutions must all be shorter than 256 bytes.' ),
256-
'6. .0'
268+
'6.6.0'
257269
);
258270
return null;
259271
}

src/wp-includes/html-api/html5-named-character-references.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
* for an ambiguous ampersand govern whether the following text is
2727
* to be interpreted as a character reference or not.
2828
*
29+
* The list of entities is sourced directly from the WHATWG server
30+
* and cached in the test directory to avoid needing to download it
31+
* every time this file is updated.
32+
*
2933
* @link https://html.spec.whatwg.org/entities.json.
3034
*/
3135
$html5_named_character_references = WP_Token_Map::from_precomputed_table(

tests/phpunit/tests/html-api/generate-html5-named-character-references.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
* for an ambiguous ampersand govern whether the following text is
6767
* to be interpreted as a character reference or not.
6868
*
69+
* The list of entities is sourced directly from the WHATWG server
70+
* and cached in the test directory to avoid needing to download it
71+
* every time this file is updated.
72+
*
6973
* @link https://html.spec.whatwg.org/entities.json.
7074
*/
7175
\$html5_named_character_references = {$html5_map->precomputed_php_source_table()};

tests/phpunit/tests/wp-token-map/wpTokenMap.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99
* @coversDefaultClass WP_Token_map
1010
*/
1111
class Tests_WpTokenMap extends WP_UnitTestCase {
12+
/**
13+
* Small test array matching names to Emoji.
14+
*
15+
* @var array.
16+
*/
17+
const ANIMAL_EMOJI = array(
18+
'cat' => '🐈',
19+
'dog' => '🐶',
20+
'fish' => '🐟',
21+
'mammoth' => '🦣',
22+
'seal' => '🦭',
23+
);
24+
1225
/**
1326
* Returns an associative array whose keys are tokens to replace and
1427
* whose values are the replacement strings for those tokens.
@@ -17,6 +30,11 @@ class Tests_WpTokenMap extends WP_UnitTestCase {
1730
* For example, the HTML5 dataset is very large and best served as a
1831
* separate file.
1932
*
33+
* The HTML5 named character reference list is pulled directly from the
34+
* WHATWG spec and stored in the tests directory so it doesn't need to
35+
* be downloaded on every test run. By specification, it cannot change
36+
* and will not be updated.
37+
*
2038
* @ticket 60698.
2139
*
2240
* @param string $dataset_name Which dataset to return.
@@ -31,7 +49,7 @@ private static function get_test_input_array( $dataset_name ) {
3149

3250
case 'HTML5':
3351
if ( ! isset( $html5_character_references ) ) {
34-
$dataset = json_decode( file_get_contents( __DIR__ . '/../../data/html5-entities.json' ), JSON_OBJECT_AS_ARRAY ); // phpcs:ignore.
52+
$dataset = wp_json_file_decode( __DIR__ . '/../../data/html5-entities.json', JSON_OBJECT_AS_ARRAY );
3553

3654
$html5_character_references = array();
3755
foreach ( $dataset as $name => $value ) {
@@ -48,7 +66,7 @@ private static function get_test_input_array( $dataset_name ) {
4866
*
4967
* @return array[].
5068
*/
51-
public static function data_input_arrays() {
69+
private static function data_input_arrays() {
5270
$dataset_names = array(
5371
'ANIMALS',
5472
'HTML5',
@@ -357,7 +375,7 @@ public static function data_html5_test_dataset() {
357375
*
358376
* @return WP_Token_Map
359377
*/
360-
public static function get_html5_token_map() {
378+
private static function get_html5_token_map() {
361379
static $html5_token_map = null;
362380

363381
if ( ! isset( $html5_token_map ) ) {
@@ -366,12 +384,4 @@ public static function get_html5_token_map() {
366384

367385
return $html5_token_map;
368386
}
369-
370-
const ANIMAL_EMOJI = array(
371-
'cat' => '🐈',
372-
'dog' => '🐶',
373-
'fish' => '🐟',
374-
'mammoth' => '🦣',
375-
'seal' => '🦭',
376-
);
377387
}

0 commit comments

Comments
 (0)