forked from PHPMailer/PHPMailer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPHPMailerLangTest.php
73 lines (67 loc) · 2.2 KB
/
PHPMailerLangTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* PHPMailer - language file tests.
*
* PHP version 5.5.
*
* @author Marcus Bointon <[email protected]>
* @author Andy Prevost
* @copyright 2010 - 2020 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace PHPMailer\Test;
use PHPMailer\PHPMailer\PHPMailer;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
/**
* Check language files for missing or excess translations.
*/
final class PHPMailerLangTest extends TestCase
{
/**
* Holds a PHPMailer instance.
*
* @var PHPMailer
*/
private $Mail;
/**
* Run before each test is started.
*/
protected function set_up()
{
$this->Mail = new PHPMailer();
}
/**
* Test language files for missing and excess translations.
* All languages are compared with English.
*
* @group languages
*/
public function testTranslations()
{
$this->Mail->setLanguage('en');
$definedStrings = $this->Mail->getTranslations();
$err = '';
foreach (new \DirectoryIterator(__DIR__ . '/../language') as $fileInfo) {
if ($fileInfo->isDot()) {
continue;
}
$matches = [];
//Only look at language files, ignore anything else in there
if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) {
$lang = $matches[1]; //Extract language code
$PHPMAILER_LANG = []; //Language strings get put in here
include $fileInfo->getPathname(); //Get language strings
$missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG));
$extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings));
if (!empty($missing)) {
$err .= "\nMissing translations in $lang: " . implode(', ', $missing);
}
if (!empty($extra)) {
$err .= "\nExtra translations in $lang: " . implode(', ', $extra);
}
}
}
$this->assertEmpty($err, $err);
}
}