Просмотр файла main_files/phpmailer/test/phpmailerLangTest.php

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