NotGettextedTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Tests for not-gettexted.php
  4. *
  5. * @package wordpress-i18n
  6. * @subpackage tools
  7. */
  8. error_reporting( E_ALL );
  9. require_once dirname( dirname( __FILE__ ) ) . '/not-gettexted.php';
  10. class NotGettextedTest extends PHPUnit_Framework_TestCase {
  11. function __construct() {
  12. $this->ng = new NotGettexted;
  13. }
  14. function test_make_string_aggregator() {
  15. global $baba;
  16. $f = $this->ng->make_string_aggregator( 'baba', 'baba.php' );
  17. call_user_func( $f, 'x', 'y', 'z' );
  18. call_user_func( $f, 'a', 'b', 'c' );
  19. $this->assertEquals( array( array( 'x', 'y', 'baba.php', 'z'), array( 'a', 'b', 'baba.php', 'c' ) ), $baba );
  20. }
  21. function test_walk() {
  22. $code = '
  23. <?php
  24. $s = 8;
  25. echo /* WP_I18N_GUGU*/ "yes" /* /WP_I18N_UGU */;
  26. if ($x == "18181") { wp_die(sprintf(/*WP_I18N_DIE*/\'We died %d times!\'/*WP_I18N_DIE*/)); }
  27. ?>';
  28. $tokens = token_get_all($code);
  29. $this->assertEquals( '', $this->ng->walk_tokens( $tokens, array($this->ng, 'ignore_token'), array($this->ng, 'ignore_token') ) );
  30. $this->assertEquals( '"yes"\'We died %d times!\'', $this->ng->walk_tokens( $tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'ignore_token') ) );
  31. $this->assertEquals( $code, $this->ng->walk_tokens( $tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'unchanged_token') ) );
  32. $this->assertEquals( $code, $this->ng->walk_tokens( $tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'unchanged_token') ) );
  33. }
  34. function test_replace() {
  35. # copy to a new file, so that we don't corrupt the old one
  36. copy( 'data/not-gettexted-0.php', 'data/not-gettexted-0-work.php' );
  37. $this->ng->command_replace( 'data/not-gettexted-0.mo', 'data/not-gettexted-0-work.php' );
  38. $this->assertEquals( file_get_contents( 'data/not-gettexted-0-result.php' ), file_get_contents( 'data/not-gettexted-0-work.php' ) );
  39. unlink( 'data/not-gettexted-0-work.php' );
  40. }
  41. }