phpmailerLangTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 '../PHPMailerAutoload.php';
  16. /**
  17. * PHPMailer - PHP email transport unit test class
  18. * Performs authentication tests
  19. */
  20. class PHPMailerLangTest extends PHPUnit_Framework_TestCase
  21. {
  22. /**
  23. * Holds a phpmailer instance.
  24. * @private
  25. * @var PHPMailer
  26. */
  27. public $Mail;
  28. /**
  29. * @var string Default include path
  30. */
  31. public $INCLUDE_DIR = '../';
  32. /**
  33. * Run before each test is started.
  34. */
  35. public function setUp()
  36. {
  37. $this->Mail = new PHPMailer;
  38. }
  39. /**
  40. * Test language files for missing and excess translations
  41. * All languages are compared with English
  42. * @group languages
  43. */
  44. public function testTranslations()
  45. {
  46. $this->Mail->setLanguage('en');
  47. $definedStrings = $this->Mail->getTranslations();
  48. $err = '';
  49. foreach (new DirectoryIterator('../language') as $fileInfo) {
  50. if ($fileInfo->isDot()) {
  51. continue;
  52. }
  53. $matches = array();
  54. //Only look at language files, ignore anything else in there
  55. if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) {
  56. $lang = $matches[1]; //Extract language code
  57. $PHPMAILER_LANG = array(); //Language strings get put in here
  58. include $fileInfo->getPathname(); //Get language strings
  59. $missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG));
  60. $extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings));
  61. if (!empty($missing)) {
  62. $err .= "\nMissing translations in $lang: " . implode(', ', $missing);
  63. }
  64. if (!empty($extra)) {
  65. $err .= "\nExtra translations in $lang: " . implode(', ', $extra);
  66. }
  67. }
  68. }
  69. $this->assertEmpty($err, $err);
  70. }
  71. }