0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00
Commit Graph

2019 Commits

Author SHA1 Message Date
Marcus Bointon
d16053c51c
Merge pull request #2440 from jrfnl/feature/parseaddresses-bug-fix-1-missing-extension-check
PHPMailer::parseAddresses(): bug fix [1] - extension availability not checked (consistently)
2021-07-12 21:26:26 +02:00
Marcus Bointon
7d57e6c078
Merge pull request #2446 from eltociear/patch-1
EncodeQTest: fix typo
2021-07-12 16:51:04 +02:00
Ikko Ashimine
4c1adf79f3
EncodeQTest: fix typo
containg -> contains
2021-07-12 23:10:59 +09:00
jrfnl
63da073183 SetTest: add @covers tag 2021-07-12 15:24:18 +02:00
jrfnl
8fe8b5634c SetTest::testSetValidProperty(): add additional test case
This commit:
* Adds one extra test case.
* Documents why there is no test case for a `private` property.
2021-07-12 15:24:16 +02:00
jrfnl
3d9a99802a SetTest: reorganize success test to use a data provider
* Renames the method to a more descriptive name.
* Maintains the same test case.
* Makes it easier to add additional test cases in the future.
2021-07-12 15:24:14 +02:00
jrfnl
628d56927e SetTest: split off value toggling test
This commit moves the "set a property to null and then back" test to a separate test method.

Note: based on the code in the method, this test doesn't really add any value, but I also see no reason to remove it.
2021-07-12 15:24:12 +02:00
jrfnl
eef6f4e52a SetTest: split off failure test
This commit moves the "failed to set the property" test case to a separate test method.
2021-07-12 15:24:10 +02:00
jrfnl
d4ff9fdd54 Tests/reorganize: move property setting tests to own file 2021-07-12 15:24:08 +02:00
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