phpmailerLangTest.php 2.2 KB

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