ent2ncr.php 883 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_Ent2NCR extends WP_UnitTestCase {
  6. /**
  7. * @dataProvider entities
  8. */
  9. function test_converts_named_entities_to_numeric_character_references( $entity, $ncr ) {
  10. $entity = '&' . $entity . ';';
  11. $ncr = '&#' . $ncr . ';';
  12. $this->assertSame( $ncr, ent2ncr( $entity ), $entity );
  13. }
  14. /**
  15. * Get test data from files, one test per line.
  16. * Comments start with "###".
  17. */
  18. function entities() {
  19. $entities = file( DIR_TESTDATA . '/formatting/entities.txt' );
  20. $data_provided = array();
  21. foreach ( $entities as $line ) {
  22. // Comment.
  23. $commentpos = strpos( $line, '###' );
  24. if ( false !== $commentpos ) {
  25. $line = trim( substr( $line, 0, $commentpos ) );
  26. if ( ! $line ) {
  27. continue;
  28. }
  29. }
  30. $data_provided[] = array_map( 'trim', explode( '|', $line ) );
  31. }
  32. return $data_provided;
  33. }
  34. }