Skip to content

Commit

Permalink
Tests: introduce dedicated tests for text localization
Browse files Browse the repository at this point in the history
So far, the methods related to text localization - `PHPMailer::setLanguage()`, `PHPMailer::getTranslations()` and `PHPMailer::lang()` - did not have dedicated tests.

The test file this commit introduces, tests all aspects of these methods, including the changes introduced in response to 2418 and 2419, as well as documents the current behaviour of the methods for specific, outlier situations.
  • Loading branch information
jrfnl committed Jul 13, 2021
1 parent 4ba1380 commit 913fb55
Show file tree
Hide file tree
Showing 12 changed files with 601 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-fr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test overruling an existing translation
* file with a custom one by passing in a `$langPath` parameter.
*/

$PHPMAILER_LANG['empty_message'] = "Custom path test success (fr)";
10 changes: 10 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-nl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test overruling an existing translation
* file with a custom one by passing in a `$langPath` parameter.
*/

$PHPMAILER_LANG['empty_message'] = 'Custom path test success (nl)';
9 changes: 9 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-xa_scri_cc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test the fall-back logic.
*/

$PHPMAILER_LANG['empty_message'] = 'XA Lang-script-country file found';
9 changes: 9 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-xb_scri.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test the fall-back logic.
*/

$PHPMAILER_LANG['empty_message'] = 'XB Lang-script file found';
9 changes: 9 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-xc_cc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test the fall-back logic.
*/

$PHPMAILER_LANG['empty_message'] = 'XC Lang-country file found';
9 changes: 9 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-xd_cc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test the fall-back logic.
*/

$PHPMAILER_LANG['empty_message'] = 'XD Lang-country file found';
9 changes: 9 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-xd_scri.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test the fall-back logic.
*/

$PHPMAILER_LANG['empty_message'] = 'XD Lang-script file found';
9 changes: 9 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-xe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test the fall-back logic.
*/

$PHPMAILER_LANG['empty_message'] = 'XE Lang file found';
9 changes: 9 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-xx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest`.
*/

$PHPMAILER_LANG['empty_message'] = 'This file should not be loaded as the path is passed incorrectly';
17 changes: 17 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-yy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test that arbitrary code in translation files is disregarded.
*/

$composer = file_get_contents(__DIR__ . '/../../../composer.json');

echo $composer;

$PHPMAILER_LANG['extension_missing'] = 'Confirming that test fixture was loaded correctly (yy).';
$PHPMAILER_LANG['empty_message'] = $composer;
$PHPMAILER_LANG['encoding'] = `ls -l`;
$PHPMAILER_LANG['execute'] = exec('some harmful command');
$PHPMAILER_LANG['signing'] = "Double quoted but not interpolated $composer";
20 changes: 20 additions & 0 deletions test/Fixtures/LocalizationTest/phpmailer.lang-zz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* Test fixture.
*
* Used in the `PHPMailer\LocalizationTest` to test that language strings not
* set via a fixed, known group of array index keys are disregarded.
*/

$PHPMAILER_LANG['extension_missing'] = 'Confirming that test fixture was loaded correctly (zz).';

// Keys not in the original array.
$PHPMAILER_LANG['unknown'] = 'Unknown text.';
$PHPMAILER_LANG['invalid'] = 'Invalid text.';

// Keys which exist in the original array, but use the wrong letter case or space instead of underscore.
$PHPMAILER_LANG['Authenticate'] = 'Overruled text, index not same case';
$PHPMAILER_LANG['CONNECT_HOST'] = 'Overruled text, index not same case';
$PHPMAILER_LANG['Data_Not_Accepted'] = 'Overruled text, index not same case';
$PHPMAILER_LANG['empty message'] = 'Overruled text, index not same case';
Loading

0 comments on commit 913fb55

Please sign in to comment.