Commit Graph

2010 Commits

Author SHA1 Message Date
jrfnl 1e874999d1 PHPMailer::parseAddresses(): replace use of extension_loaded
The `extension_loaded()` PHP function is sometimes disabled by shared hosts as a form of "security by obscurity".
This would lead to a fatal "Function not available" error.

With that in mind, replacing the `extension_loaded()` checks in the `PHPMailer::parseAddresses()` function with a check for the `MB_CASE_UPPER` constant being defined. This _should_ be reliable enough to determine whether the Mbstring extension is available, though has its own drawbacks as when the extension is not available, the constant _could_ be polyfilled by userland code (and sometimes is).

The `MB_CASE_UPPER` constant was chosen as it is one of the few Mbstring constants which is actually available cross-version in PHP 5.5-current.

Refs:
* https://www.php.net/manual/en/mbstring.constants.php
* https://php-legacy-docs.zend.com/manual/php5/en/mbstring.constants
2021-07-12 15:20:28 +02:00
Marcus Bointon 1265af38ea
Merge pull request #2444 from jrfnl/feature/tests-reorganize-31
Tests: move setFrom tests to own file
2021-07-12 15:14:08 +02:00
jrfnl 64312a5eed SetFromTest: add `@covers` tag 2021-07-12 14:56:38 +02:00
jrfnl 2410465e9c SetFromTest: add extra test for passing an unacceptable email address 2021-07-12 14:56:37 +02:00
jrfnl 74e3d8e8f4 SetFromTest::testSetFromFail(): add additional test cases
... which should be handled correctly based on the code in the method under test.
2021-07-12 14:56:35 +02:00
jrfnl c6bfd49b8b SetFromTest: add extra failure test
... to test that passing an invalid email address in combination with an instance of the `PHPMailer` class which was instantiated with `$exceptions = true` results in an exception.

Includes reworking the `testSetFromFail()` method to a data provider and letting both the `testSetFromFail()` and the new `testInvalidAddressException()` method use the same data provider.
2021-07-12 14:56:34 +02:00
jrfnl 5e912a792d SetFromTest: improve the testSetFromFail() test
Make the failure test more comprehensive by verifying that when the method fails, the values for the `From`, `FromName` and `Sender` properties, _really_ haven't changed.
2021-07-12 14:56:32 +02:00
jrfnl 76e14b34be SetFromTest: add new test for not overruling existing Sender
Based on the code in the method, any existing, previously set `Sender` should not be overruled, even when the `$auto` parameter is set to `true`.

This method tests that specific situation.
2021-07-12 14:56:31 +02:00
jrfnl baee96b604 SetFromTest::testSetFromSuccess(): add additional test cases
... which should be handled correctly based on the code in the method under test.
2021-07-12 14:56:29 +02:00
jrfnl 97f82e5993 SetFromTest: replaces the last of the `testAddressing()` method
... with a dedicated test to verify that the `Sender` is not overruled when the `$auto` parameter is set to `false`.
2021-07-12 14:56:27 +02:00
jrfnl d7cf5c6de7 SetFromTest: reorganize success tests to use data providers
* Merges the two "success" tests from the `testAddressing()` and the `testAddressing2()` methods into one `testSetFromSuccess()` method.
* Adds additional assertions to more comprehensively verify that the method did what was expected, i.e. set the `From`, `FromName` and `Sender` properties.
* Maintains the same test cases.
* Makes it easier to add additional test cases in the future.
2021-07-12 14:56:25 +02:00
jrfnl 23f0238eed SetFromTest: split off failure test
This commit moves the "invalid email address" test case to a separate test method.
2021-07-12 14:56:24 +02:00
jrfnl 4988ca1927 Tests/reorganize: move setFrom tests to own file 2021-07-12 14:56:22 +02:00
Marcus Bointon 76767b4de1
Merge pull request #2443 from jrfnl/feature/tests-reorganize-30
Tests: move error recording test to own file
2021-07-12 14:31:51 +02:00
jrfnl 214c415266 SetErrorTest: add `@covers` tags 2021-07-12 13:58:19 +02:00
jrfnl 058ded57b8 SetErrorTest: add additional tests for the `PHPMailer::setError()` and `PHPMailer::isError()` methods
So far, these methods were only tested in the most perfunctory manner.

The additional tests this commit introduces, test all aspects of the methods as well as documents the current behaviour of the methods.

Take note of the "text merging"/readability issues for the SMTP error messages. There may be room for improvement there.
2021-07-12 13:58:10 +02:00
jrfnl caa1d15eec SetErrorTest: replace the original test
... by a much simpler test which effectively tests the same thing, i.e.:
* No errors to start with.
* Trigger an error.
* Verify that `PHPMailer::isError()` returns `true`.
* Verify that the error message is as expected.
2021-07-12 13:58:08 +02:00
jrfnl 2c570af805 Tests/reorganize: move error recording test to own file 2021-07-12 13:57:56 +02:00
Marcus Bointon 56e7d2a0fd
Merge pull request #2439 from jrfnl/feature/tests-reorganize-29
Tests: move encodeQ tests to own file
2021-07-12 08:45:40 +02:00
jrfnl 5cbd8f9f62 ParseAddressesTest: add additional test for when Mbstring is not available
What with the previous commit adding a requirement for the `Mbstring` extension to the existing tests, it becomes clear that the "Mbstring extension not available" code path was not covered by the tests.

This commit fixes that by:
* Adding two new test methods which explicitly expect the Mbstring extension to **not** be available.
* Changing the data provider "expected(Imap)" keys.
    The `expected` key in the array will now be an array of arrays.
    A `default` key can be used for when the output across configurations will be the same.
    Any differences across configurations can be provided in separate sub-keys of the `expected` array, using the `native+mbstring`, `imap+mbstring`, `native--mbstring` and/or `imap--mbstring` keys, which match the four test methods which are now in place.
    Additionally, an `native` and/or `imap` key can be used for setting the output expectations for the two native implementation or the two IMAP implementation tests, if the Mbstring extension makes no difference.
2021-07-11 18:30:59 +02:00
jrfnl 8827c9b3ce PHPMailer::parseAddresses(): bug fix [1] - extension availability not checked
Follow up to #2266

Bug fix

In both "arms" (imap vs native implementation) of the `PHPMailer::parseAddresses()` method, the `mb_decode_mimeheader()` function is used to decoded a (utf-8) encoded name.

In the IMAP "arm", a check was in place for the Mbstring extension being available before using it. This check was missing from the "native implementation" "arm".

Existing Tests

This also means that both currently existing tests have a requirement for the MbString extension being available. This was previously not made explicit in the tests.
Fixed now.
2021-07-11 18:30:57 +02:00
jrfnl 8fd56f335e ParseAddressesTest: split off expectation verification 2021-07-11 18:30:56 +02:00
jrfnl e67ed991e3 ParseAddressesTest: minor correction to test case description 2021-07-11 18:30:54 +02:00
jrfnl ca1f2cfea7 EncodeQTest: add `@covers` tag 2021-07-11 11:17:15 +02:00
jrfnl 3984ac2839 EncodeQTest: add additional test cases
... which should be handled correctly based on the code in the method under test.
2021-07-11 11:17:13 +02:00
jrfnl e6af3c80b4 EncodeQTest: reorganize to use data providers
* Maintains (largely) the same test code and exactly the same test cases.
* Makes it easier to add additional test cases in the future.
2021-07-11 11:17:11 +02:00
jrfnl 167c81a2cf Tests/reorganize: move encodeQ tests to own file 2021-07-11 11:17:08 +02:00
Marcus Bointon 904dc698ea
Merge pull request #2435 from jrfnl/feature/tests-reorganize-28
Tests: move encodeString tests to own file
2021-07-11 09:09:08 +02:00
Marcus Bointon ddb89f7239
Merge pull request #2436 from jrfnl/feature/2418-gettranslations-always-available
PHPmailer::getTranslations():  translations should always be available
2021-07-11 09:07:43 +02:00
jrfnl 123c0aac84 PHPmailer::getTranslations(): translations should always be available
If the language has not been set yet, it should return the English text strings.

Fixes 2419
2021-07-09 21:14:47 +02:00
jrfnl d003985774 HasLineLongerThanMaxTest: remove a `@covers` tag
As the `PHPMailer::encodeString()` method is now fully covered by dedicated tests, this `@covers` tag can be removed.
2021-07-09 21:13:21 +02:00
jrfnl 5a29b1916b EncodeStringTest: add extra test for passing an invalid encoding
... in combination with an instance of the `PHPMailer` class which was instantiated with `$exceptions = true`.
2021-07-09 21:13:20 +02:00
jrfnl 0d071ba5c0 EncodeStringTest: improve the testInvalidEncoding() test
* Ensure that the return value of the call to `PHPMailer::encodeString()` is an empty string.
* Ensure that the error count and info is correctly set.
2021-07-09 21:13:18 +02:00
jrfnl a00826debe EncodeStringTest: add additional test cases
... which should be handled correctly based on the code in the method under test.

With these additional test cases, the method now has 100% code coverage and is fully tested.
2021-07-09 21:13:17 +02:00
jrfnl fa43806486 EncodeStringTest: reorganize to use data providers
* Maintains the same test code and test cases.
* Makes it easier to add additional test cases in the future.

Includes adding `@covers` tag.
2021-07-09 21:13:15 +02:00
jrfnl d96d944631 EncodeStringTest: split off failure test
This commit moves the "incorrect encoding" test case to a separate test method.
2021-07-09 21:13:13 +02:00
jrfnl 2380a16f5e EncodeStringTest: fix incorrect assertion
Using a regex assertion with arbitrary input data which is not regex escaped, makes this test suspect.
From the looks of it, the test _should_ be testing that the output is the _same_, so let's use that assertion.
2021-07-09 21:13:11 +02:00
jrfnl 7c8d3f21b2 Tests/reorganize: move encodeString tests to own file
Note: this doesn't move the complete test from the original test file, just select parts of the test method.
2021-07-09 21:13:08 +02:00
Marcus Bointon 687521c5ff
Merge pull request #2428 from jrfnl/feature/localization-add-missing-text-strings
Localization: allow for more text strings to be translated
2021-07-09 18:43:41 +02:00
Marcus Bointon 5106624d2a
Merge pull request #2434 from jrfnl/feature/tests-reorganize-27
Tests: move addStringEmbeddedImage tests to own file
2021-07-09 16:54:47 +02:00
jrfnl 3fc3a2c7ca AddStringEmbeddedImageTest: add `@covers` tags 2021-07-09 15:08:27 +02:00
jrfnl 996136e978 AddStringEmbeddedImageTest: add additional "fail to attach" test method
This commit:
* Adds a new `testFailToAttach()` test method to test the behaviour of the `PHPMailer::AddStringEmbeddedImageTest()` method when the `PHPMailer` class has been instantiated with `$exceptions` disabled.
* This new test method uses the same data provider - introduced in the previous commit - as the `testFailToAttachException()` method.
2021-07-09 15:08:25 +02:00
jrfnl 70828f6dca AddStringEmbeddedImageTest: refactor the "fail to attach" test case
This commit:
* Renames the `testStringEmbeddedImageEncodingException()` test to `testFailToAttachException()`.
* Reworks the test to use a data provider.
* Adds testing of the exception message to the `testFailToAttachException()` method.
2021-07-09 15:08:24 +02:00
jrfnl 3efe0352f4 AddStringEmbeddedImageTest: improve original test [2]
This expands the assertions executed in this test to cover the code under test more comprehensively.
2021-07-09 15:08:22 +02:00
jrfnl cd3416bc2d AddStringEmbeddedImageTest: improve original test [1]
This commit:
* Improves the test name and the description in the docblock.
* Replace a redundant condition and "forced" failure assertion with an assertion actually testing the result of the method call.
* Removes the redundant `return` - if an assertion fails, the rest of the code within the test method will not be executed anyway.
* Minor inline comment tweaks.
2021-07-09 15:08:20 +02:00
jrfnl e416c949d8 AddStringEmbeddedImageTest: switch to preSend()
The actual "attaching" of the string attachment happens within `createBody()` which is called from `preSend()`, so this test doesn't actually need to call `send()`.
2021-07-09 15:08:19 +02:00
jrfnl 3645ec3e87 Tests/reorganize: move addStringEmbeddedImage tests to own file 2021-07-09 15:08:17 +02:00
jrfnl 683a5039d2 Translations: update the Dutch translation 2021-07-09 15:04:18 +02:00
jrfnl a550adc872 Localization: allow for more text strings to be translated
In a number of places in the code base I came across hard-code error messages, which were not set up to be translatable.

For those I found, I've now fixed this.

Note: I've not added the labels used for logging errors via the `PHPMailer:edebug()` method. If so desired, that could be added in a future iteration.

Existing translation files have not been updated. Translators may need to be pinged before the next release to update the translation(s) they maintain.

Includes a minor tweak to the PHPCS configuration to allow lines in language files to exceed the "120 chars line max" as using concatenation for text strings in translation files will not work with the current way of loading these files and the new "buggy PHP" message is a long text which would result in nearly all translation files throwing the warning.
2021-07-09 15:01:11 +02:00
Marcus Bointon 1a2e462b9d
Merge pull request #2431 from jrfnl/feature/tests-add-tests-fileisaccessible
Tests: introduce dedicated tests for the `PHPMailer::fileIsAccessible()` method
2021-07-09 11:39:25 +02:00