ent2ncr.php 863 B

123456789101112131415161718192021222324252627282930313233343536
  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->assertEquals( $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. $data_provided[] = array_map( 'trim', explode( '|', $line ) );
  30. }
  31. return $data_provided;
  32. }
  33. }