wordpress-develop/tests/phpunit/tests/formatting/ent2ncr.php
Gary Pendergast 8f95800d52 Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
2017-11-30 23:09:33 +00:00

38 lines
884 B
PHP

<?php
/**
* @group formatting
*/
class Tests_Formatting_Ent2NCR extends WP_UnitTestCase {
/**
* @dataProvider entities
*/
function test_converts_named_entities_to_numeric_character_references( $entity, $ncr ) {
$entity = '&' . $entity . ';';
$ncr = '&#' . $ncr . ';';
$this->assertEquals( $ncr, ent2ncr( $entity ), $entity );
}
/**
* Get test data from files, one test per line.
* Comments start with "###".
*/
function entities() {
$entities = file( DIR_TESTDATA . '/formatting/entities.txt' );
$data_provided = array();
foreach ( $entities as $line ) {
// comment
$commentpos = strpos( $line, '###' );
if ( false !== $commentpos ) {
$line = trim( substr( $line, 0, $commentpos ) );
if ( ! $line ) {
continue;
}
}
$data_provided[] = array_map( 'trim', explode( '|', $line ) );
}
return $data_provided;
}
}