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

1878 Commits

Author SHA1 Message Date
jrfnl
54c0bb9fb5 SetWordWrapTest: add @covers tags 2021-07-07 17:11:43 +02:00
jrfnl
bb8b66d0c9 SetWordWrapTest: add "no-wrapping" test
... to increase code coverage.
2021-07-07 17:11:41 +02:00
jrfnl
2c7a354857 SetWordWrapTest: actually test the wordwrapping has been applied
Previously, the test didn't actually test whether the wordwrapping had been applied, just that the message was (pre)send successfully.

Changing the assertions to actually test that the wordwrapping has been correctly applied.
2021-07-07 17:11:39 +02:00
jrfnl
42ddb107f2 SetWordWrapTest: make $WordWrap variable
Make the `WordWrap` setting variable and provide it via the data provider.
2021-07-07 17:11:37 +02:00
jrfnl
807a80b4a6 SetWordWrapTest: reorganize to use data providers
* Maintains the same test code and test cases.
* Removes code duplication.
* Makes it easier to add additional test cases in the future.
2021-07-07 17:11:35 +02:00
jrfnl
c6ed8ad0eb SetWordWrapTest: use preSend() not send()
For this test, there is no need to actually try to _send_ the message, we just need to make sure that `setWordWrap()` is triggered, which can be done by calling `preSend()` instead of `send()`.
2021-07-07 17:11:33 +02:00
jrfnl
b4ab241395 Tests/reorganize: move setWordWrap tests to own file 2021-07-07 17:11:31 +02:00
Marcus Bointon
55ad6349c9
Merge pull request #2421 from jrfnl/feature/tests-reorganize-22
Tests: move puny encoding test to own file
2021-07-07 15:35:24 +02:00
Marcus Bointon
a44e3db8d9
Merge pull request #2420 from jrfnl/feature/gitattributes-ignore-codecov-config
.gitattributes: export-ignore code coverage config file
2021-07-07 15:33:33 +02:00
Marcus Bointon
fbc5834fc5
Merge pull request #2417 from jrfnl/feature/utf8boundary-test-minor-improvement
Utf8CharBoundaryTest: switch base test case
2021-07-07 15:33:20 +02:00
Marcus Bointon
86aae5c547
Merge pull request #2416 from jrfnl/feature/tests-setup-vs-test-bootstrap
SendTestCase: error out when the testbootstrap file cannot be found
2021-07-07 15:32:53 +02:00
Marcus Bointon
a6aa3c8e12
Merge pull request #2415 from jrfnl/feature/tests-add-tests-generateID
Tests: introduce dedicated test for the `PHPMailer::generateID()` method
2021-07-07 15:32:07 +02:00
jrfnl
89af7c5074 PunyencodeAddressTest: add @covers tag 2021-07-07 05:15:27 +02:00
jrfnl
09ba11ae08 PunyencodeAddressTest: add additional test method
This new test method covers a range of cases where the `PHPMailer::punyencodeAddress()` method should (and does) return the original input value unchanged.

This test does not require the `mbstring` extension or `idn_to_ascii()` function to be available, which is why it has been set up as a separate test with a separate data provider.
2021-07-07 05:15:24 +02:00
jrfnl
7f6c882395 PunyencodeAddressTest: add additional test case
... to ensure that the `PHPMailer::punyencodeAddress()` only acts on the domain.
2021-07-07 05:15:23 +02:00
jrfnl
acb038dac3 PunyencodeAddressTest: reorganize to use data provider
* Maintains the same test code and test cases.
* Makes it easier to add additional test cases in the future.
2021-07-07 05:15:21 +02:00
jrfnl
cd563f1e99 PunyencodeAddressTest: set proper run requirements
The "fakefunctions" are all nice and dandy to get past the `idnSupported()` check, but if either of these functions is not _really_ available and therefore doesn't behave as expected, the test would still fail as the expected output of the `PHPMailer::punyencodeAddress()` function would not match.

In other words, this test should not use the `fakefunctions`, but should have a hard requirement for the `mbstring` extension (for the `mb_check_encoding()` and the `mb_convert_encoding()` function calls) and a check for the `idn_to_ascii()` function.
2021-07-07 05:15:20 +02:00
jrfnl
3a62fe304b Tests/reorganize: move puny encoding test to own file 2021-07-07 05:15:18 +02:00
jrfnl
a01cc9ba82 .gitattributes: export-ignore code coverage config file
Follow up on 2407.
2021-07-07 05:01:23 +02:00
Marcus Bointon
6dc419aead
Merge pull request #2414 from jrfnl/feature/tests-reorganize-21
Tests: move denial of service tests to own file
2021-07-06 21:49:33 +02:00
jrfnl
8e8fdbf5cb Utf8CharBoundaryTest: switch base test case
Follow up on 2389 and 2412

Now the base `TestCase` has been simplified and only presets the bare minimum of properties in the `PHPMailer` class, the `Utf8CharBoundaryTest` can actually use it.
2021-07-06 21:41:35 +02:00
jrfnl
ef35c0daa5 SendTestCase: error out when the testbootstrap file cannot be found
The `PHPMailerTest` class contained a `testBootstrap()` method to verify that the `testbootstrap.php` file exists as the first test in the class.
As the order in which tests are run is not predefined, this is not reliable.

Additionally, the check for the `testbootstrap.php` file is checking a pre-requisite for tests using the `PHPMailer::send()` method, so it would be better to verify via a condition in the `set_up()`.

Now, using such a condition, there is choice: the test can either be marked as "skipped" when the `testbootstrap.php` file can not be found, or be marked as an "error".

As the tests _should_ run, skipping them would hide an error in the dev-user test setup, so showing these tests as errors seems more appropriate.

To that end, the `testBootstrap()` method has been removed and a check for the `testbootstrap.php` file has been added to the `SendTestCase::set_up()` which will now throw an appropriate `Exception` when the file is not found.

Oops... also removes a stray `parent::set_up()` at the start of the local `set_up()` which should have been removed in 218fd13c88
2021-07-06 21:39:41 +02:00
jrfnl
63e9bf5604 Tests: introduce dedicated test for the PHPMailer::generateID() method
Note: as the `PHPMailer::generateID()` method is `protected`, a round-about way of testing this is needed, but this test does verify the functioning of the method.

Take note of the notes in the test docblock - the GH Actions scripts running CI, should make sure that each of these scenarios is encountered/tested.
This will be addressed in a separate PR at the end of this round of test changes.
2021-07-06 21:37:29 +02:00
jrfnl
eb6dca5521 SecurityDenialOfServiceVectorsTest: various test tweaks
Minor test tweaks:
* Add `@coversNothing` tag.
* Rename the first test (add a number).
* Use `@link` instead of `@see` for links.
* Minor comment punctuation.
2021-07-06 21:28:02 +02:00
jrfnl
6b95da3e65 Tests/reorganize: move denial of service tests to own file 2021-07-06 21:28:00 +02:00
Marcus Bointon
e372a5e85b
Merge pull request #2412 from jrfnl/feature/tests-split-and-improve-testcase
Tests: split `TestCase` class into three base test case classes and make more flexible
2021-07-06 20:17:43 +02:00
Marcus Bointon
336b6976b6
Merge pull request #2410 from jrfnl/feature/tests-reorganize-20
Tests: move host validation tests to own file
2021-07-06 20:16:47 +02:00
jrfnl
55c54e46b0 TestCase::checkChanges(): make dynamic
The `TestCase::checkChanges()` method is a way of exposing what properties in the `PHPMailer` class have a changed value compared to their default value in a particular test situation. The method is used for debugging tests.

As things were, the `TestCase::checkChanges()` method would check against a limited set of hard-coded values to determine whether the default value of a property has been updated.

This is unstable as:
1. Default values may change in the `PHPMailer` class and the values within this method would need to be updated to match, which is easily forgotten.
2. New properties may be introduced in the `PHPMailer` class and be relevant to this debug changelog.
    Again, it would require manually adding these new properties to this method to start tracking them.
3. Property values may be changed in the `set_up()` method, which would be a "known change" for a certain test.
    In part such "expected" changes were taken into account in this method based on the previously hard-coded setting changes in `set_up()`.
    With the logic for the property setting from the `set_up()` method now being more flexible, the pre-setting of properties having been reduced to the bare minimum, but also allowing individual test clases to set their own additional changes, keeping track of what is a "known" change by checking against hard-coded values is no longer stable.

With this in mind, I propose to make the `TestCase::checkChanges()` method dynamic.

To that end, this commit:
* Retrieves the default values of all properties of the `PHPMailer` class via the PHP native `get_class_vars()` function.
* Will automatically check for changes in *all* properties, with only a limited set of _exclusions_, effectively changing the changelog from an "inclusion list" to an "exclusion list".
    A select list of properties is excluded from being listed in the changelog via the `TestCase::$changelogExclude` property.
    See the inline documentation in the property for the reasoning behind excluding certain properties from the changelog.
* The value of static properties will always be compared to their default value as registered in the `TestCase::$PHPMailerStaticProps` method and will be listed when different.
    _Note: as documented, this list has to be hard-coded due to Reflection (as well as `get_class_vars()`) not handling default values for static properties correctly._
* The value of non-static properties will be compared to both the known changes made in the `set_up()` method and if the property was not changed in `set_up()`, to their default value. The property will be listed in the changelog when the value is different from the "expected" value, i.e. not a known change from `set_up()` and not the default value.

In addition to this, the representation of the properties will now be created via `var_export()`, which allows for listing `null` and boolean values as well.
2021-07-06 20:05:35 +02:00
jrfnl
218fd13c88 SendTestCase: implement use of the $propertyChanges property
The `SendTestCase` gets the values of the properties to be set from the `testbootstrap.php` file.

This introduces a `private` property to map the field names used in `$_REQUEST` to the properties in the `PHPMailer` class and adds logic to the overloaded `set_up()` method to fill the `$propertyChanges` TestCase property. The actual setting of the properties in the `PHPMailer` instance is deferred to the underlying `TestCase` parent class.

Includes adding support for presetting the `bcc` value for feature completeness.

Overloading and/or adding to the `$propertyChanges` array from concrete test cases is, of course, supported, so if individual tests need additional presetting of properties, the same logic as mentioned in the previous commit can be used.
2021-07-06 20:05:35 +02:00
jrfnl
f9ce138ff7 PreSendTestCase: reduce amount of properties being preset
After some investigation, it turns out that barely any of these properties are actually needed for the `PHPMailer::preSend()` method to succeed.

This commit removes all presetting of properties for the PHPMailer instance created by the `PreSendTestCase`, save for the bare minimum.

Overloading and/or adding to the `$propertyChanges` array from concrete test cases is, of course, supported, so if individual tests need additional presetting of properties, the same logic as mentioned in the previous commit can be used.
2021-07-06 20:05:35 +02:00
jrfnl
f4bb4d7b63 PreSendTestCase: implement use of the $propertyChanges property 2021-07-06 20:05:35 +02:00
jrfnl
5620c873d9 TestCase: make the property pre-setting more flexible
This commit makes the property setting in the `TestCase::set_up()` more flexible by combining an overloadable property `$propertyChanges` and a `foreach` loop to set the actual property values.

Concrete test classes can either overload the `$propertyChanges` property with their own version or can add to the default setup using the following pattern:
```php
protected function set_up()
{
    $this->propertyChanges['additional_key'] = 'value';
    // Add more properties...

    parent::set_up();
}
```
2021-07-06 20:05:35 +02:00
jrfnl
d7b048cf64 TestCase: split into three different TestCases
The `TestCase::set_up()` was setting quite a number of properties in the `PHPMailer` class.

This makes testing more difficult for the following reasons:
1. The tests can no longer presume the properties in the `PHPMailer` class will have their default values
    This means that tests are not "transparent" (clearly show what is being tested), nor isolated (only target what is specifically being tested).
2. Any changes to the values set in the `set_up()` method may have a ripple effect and create a need for individual test expectations to be adjusted.
3. As the `set_up()` is changing a number of the properties using methods in the `PHPMailer()` class and methods called during the `set_up()` are included in code coverage visualizations, code coverage cannot fully be trusted and it is more difficult to verify that each piece of code has tests covering that code path.

With this in mind, I'm proposing splitting the `TestCase` into three distinct abstract `TestCase`s:
* A basic `TestCase` containing the utility methods and a minimal `set_up()` and `tear_down()`.
* A `PreSendTestCase` for use with tests using the `preSend()` method which requires a few properties to be set.
* A `SendTestCase` for use with tests actually testing the sending of mail using the `send()` method, which needs yet more properties and uses the `testbootstrap.php` file to retrieve the values of those variables.

This commit executes the initial split. Follow-on commits will streamline this further.

Includes adjusting the `TestCase` being extended for select existing unit test classes.
2021-07-06 20:05:35 +02:00
Marcus Bointon
ea8bd9373a
Merge pull request #2413 from jrfnl/feature/ghactions-retry-postfix-install-on-fail
GH Actions: automatically retry postfix install on failure
2021-07-06 20:03:19 +02:00
jrfnl
5aa58f8c49 PHPMailer::isValidHost: minor regex tweak
A `]` is a special character in a regex and should be escaped when the literal is intended. While it was not problematic in this case, it is still recommended to escape it.
2021-07-06 20:02:42 +02:00
jrfnl
ca11260085 IsValidHostTest: add @covers tags 2021-07-06 20:02:42 +02:00
jrfnl
e2dec4508c IsValidHostTest: 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 actually tested quite fully.
2021-07-06 20:02:37 +02:00
jrfnl
79d7cc0757 IsValidHostTest: minor reordering of data provider
... for easier scanning what's covered reading.
2021-07-06 19:59:49 +02:00
jrfnl
9291bf2db8 IsValidHostTest: reorganize to use data providers
* Split the test into two tests with each a dedicated data provider
* Maintains the same test code and test cases.
* Makes it easier to add additional test cases in the future.

**Note**: the data set description may need some improvement, I've described them based on my best guess of what they were testing.
2021-07-06 19:59:49 +02:00
jrfnl
aa36b51cf3 Tests/reorganize: move host validation tests to own file
As this test does not actually need an instantiated PHPMailer object, this class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` instead of the `PHPMailer\Test\TestCase`.
2021-07-06 19:59:49 +02:00
jrfnl
44d195a060 GH Actions: automatically retry postfix install on failure
The postfix installation step fails regularly, resulting in failed CI builds which have to be restarted, while the failure is not due to anything in the PR.

This commit introduces a new action runner for the postfix install, which will automatically retry the install up to 3 times.

If it works as I expect it to, this should eliminate failed CI builds due to postfix installs erroring out.

Ref: https://github.com/marketplace/actions/retry-step
2021-07-06 19:56:26 +02:00
Marcus Bointon
58282fb4ff
Merge pull request #2411 from jrfnl/feature/tests-add-tests-quotedstring
Tests: introduce dedicated tests for the `PHPMailer::quotedString()` method
2021-07-06 19:12:00 +02:00
jrfnl
641b4c2391 Tests: introduce dedicated tests for the PHPMailer::quotedString() method
So far, this method did not have dedicated tests, though the `PHPMailerTest::testAttachmentNaming()` test covered this partially.

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

Test cases largely inspired by the tests in the `PHPMailerTest::testAttachmentNaming()` method.
2021-07-06 15:51:16 +02:00
Marcus Bointon
7c862d35da
Update codecov badge 2021-07-06 09:43:04 +02:00
Marcus Bointon
0374a85778
Merge pull request #2408 from jrfnl/feature/tests-reorganize-19
Tests: move mime type test(s) to own file
2021-07-06 09:36:34 +02:00
Marcus Bointon
7fe5bcad1d
Merge pull request #2407 from jrfnl/feature/enable-codecoverage-monitoring-codecov
GH Actions: set up code coverage monitoring via codecov
2021-07-06 09:28:51 +02:00
jrfnl
abc401485e MimeTypesTest: add @covers tag 2021-07-04 15:13:23 +02:00
jrfnl
55e0813d04 MimeTypesTest: add additional test cases
Including test cases with:
* Different text case.
* An extension not in the list.
* Passing an empty string
2021-07-04 15:13:18 +02:00
jrfnl
6ee8e17c33 MimeTypesTest: reorganize to use data provider
* Maintains the same test code and test case.
* Makes it easier to add additional test cases in the future.
2021-07-04 15:09:05 +02:00
jrfnl
0a84d20565 Tests/reorganize: move mime type tests to own file
As this test does not actually need an instantiated PHPMailer object, this class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` instead of the `PHPMailer\Test\TestCase`.

Note: this doesn't move the complete test from the original test file, just select parts of the test method.
2021-07-04 15:09:03 +02:00