Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ignitetch
GitHub Repository: ignitetch/advphishing
Path: blob/master/PHPMailer/test/PHPMailerLangTest.php
738 views
1
<?php
2
/**
3
* PHPMailer - language file tests.
4
*
5
* PHP version 5.5.
6
*
7
* @author Marcus Bointon <[email protected]>
8
* @author Andy Prevost
9
* @copyright 2010 - 2020 Marcus Bointon
10
* @copyright 2004 - 2009 Andy Prevost
11
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
12
*/
13
14
namespace PHPMailer\Test;
15
16
use PHPMailer\PHPMailer\PHPMailer;
17
use PHPUnit\Framework\TestCase;
18
19
/**
20
* Check language files for missing or excess translations.
21
*/
22
final class PHPMailerLangTest extends TestCase
23
{
24
/**
25
* Holds a PHPMailer instance.
26
*
27
* @var PHPMailer
28
*/
29
private $Mail;
30
31
/**
32
* Run before each test is started.
33
*/
34
protected function setUp()
35
{
36
$this->Mail = new PHPMailer();
37
}
38
39
/**
40
* Test language files for missing and excess translations.
41
* All languages are compared with English.
42
*
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(__DIR__ . '/../language') as $fileInfo) {
51
if ($fileInfo->isDot()) {
52
continue;
53
}
54
$matches = [];
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 = []; //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
}
73
74