phpmailerLangTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * PHPMailer - language file tests
  4. * Requires PHPUnit 3.3 or later.
  5. *
  6. * PHP version 5.0.0
  7. *
  8. * @package PHPMailer
  9. * @author Andy Prevost
  10. * @author Marcus Bointon <phpmailer@synchromedia.co.uk>
  11. * @copyright 2004 - 2009 Andy Prevost
  12. * @copyright 2010 Marcus Bointon
  13. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  14. */
  15. require_once 'PHPUnit/Autoload.php';
  16. require_once '../PHPMailerAutoload.php';
  17. /**
  18. * PHPMailer - PHP email transport unit test class
  19. * Performs authentication tests
  20. */
  21. class PHPMailerLangTest extends PHPUnit_Framework_TestCase
  22. {
  23. /**
  24. * Holds a phpmailer instance.
  25. * @private
  26. * @var PHPMailer
  27. */
  28. public $Mail;
  29. /**
  30. * @var string Default include path
  31. */
  32. public $INCLUDE_DIR = '../';
  33. /**
  34. * Run before each test is started.
  35. */
  36. public function setUp()
  37. {
  38. $this->Mail = new PHPMailer;
  39. }
  40. /**
  41. * Test language files for missing and excess translations
  42. * All languages are compared with English
  43. * @group languages
  44. */
  45. public function testTranslations()
  46. {
  47. $this->Mail->setLanguage('en');
  48. $definedStrings = $this->Mail->getTranslations();
  49. $err = '';
  50. foreach (new DirectoryIterator('../language') as $fileInfo) {
  51. if ($fileInfo->isDot()) {
  52. continue;
  53. }
  54. $matches = array();
  55. //Only look at language files, ignore anything else in there
  56. if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) {
  57. $lang = $matches[1]; //Extract language code
  58. $PHPMAILER_LANG = array(); //Language strings get put in here
  59. include $fileInfo->getPathname(); //Get language strings
  60. $missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG));
  61. $extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings));
  62. if (!empty($missing)) {
  63. $err .= "\nMissing translations in $lang: " . implode(', ', $missing);
  64. }
  65. if (!empty($extra)) {
  66. $err .= "\nExtra translations in $lang: " . implode(', ', $extra);
  67. }
  68. }
  69. }
  70. $this->assertEmpty($err, $err);
  71. }
  72. }