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

457 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Marcus Bointon
fbf2eea0e9
Merge pull request #2430 from jrfnl/feature/tests-add-tests-ispermittedpath
Tests: introduce dedicated tests for the `PHPMailer::isPermittedPath()` method
2021-07-09 11:38:37 +02:00
jrfnl
49bcd4a035 Tests: introduce dedicated tests for the PHPMailer::fileIsAccessible() method
So far, this method did not have dedicated tests.

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

There is one particular test case missing. This is annotated in the class docblock.

While this method is quite simple, testing it separately means that the tests for methods _using_ this method don't have to _also_ test the functioning of this method, which means they can be more focussed on their own logic.
2021-07-09 09:36:36 +02:00
jrfnl
f5b54c2bb5 Tests: introduce dedicated tests for the PHPMailer::isPermittedPath() method
So far, this method did not have dedicated tests.

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

While this method is quite simple, testing it separately means that the tests for methods _using_ this method don't have to _also_ test the functioning of this method, which means they can be more focussed on their own logic.
2021-07-09 09:30:39 +02:00
jrfnl
59f82c7db5 AddStringAttachmentTest: add @covers tags 2021-07-08 11:37:17 +02:00
jrfnl
404ba09b64 AddStringAttachmentTest: add additional "fail to attach" test method
This commit:
* Adds a new `testFailToAttach()` test method to test the behaviour of the `PHPMailer::addStringAttachment()` 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-08 11:37:15 +02:00
jrfnl
384e291092 AddStringAttachmentTest: refactor the "fail to attach" test case
This commit:
* Renames the `testStringAttachmentEncodingException()` test to `testFailToAttachException()`.
* Reworks the test to use a data provider.
* Adds testing of the exception message to the `testFailToAttachException()` method.
2021-07-08 11:37:13 +02:00
jrfnl
40a4fa39b7 AddStringAttachmentTest: improve original test
This expands the assertions executed in this test to cover the code under test more comprehensively.
2021-07-08 11:37:12 +02:00
jrfnl
41af61ab2f AddStringAttachmentTest: 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-08 11:37:10 +02:00
jrfnl
0bc3dfb96b Tests/reorganize: move addStringAttachment tests to own file 2021-07-08 11:37:08 +02:00
jrfnl
73b4ec5bea AddEmbeddedImageTest: add @covers tags 2021-07-07 19:27:02 +02:00
jrfnl
90c98c3c1c AddEmbeddedImageTest: fully test exceptions for "fail to attach" test cases
This commit:
* Adds an `exceptionMessage` index to the `dataFailToAttach()` data provider.
* Renames the `testEmbeddedImageEncodingException()` method to `testFailToAttachException()`.
* Sets the `testFailToAttachException()` method up to use the `dataFailToAttach()` data provider.
* Adds testing of the exception message to the `testFailToAttachException()` method.

With this change, the "fail to attach" test cases are now fully tested for both a `PHPMailer` instance without exceptions enabled, as well as for an instance _with_ exceptions enabled.
2021-07-07 19:27:01 +02:00
jrfnl
eb666a7e5d AddEmbeddedImageTest: add extra test case for testFailToAttach() method
... mirroring the same test in the `testEmbeddedImageEncodingException()` method.
2021-07-07 19:26:59 +02:00
jrfnl
028b503624 AddEmbeddedImageTest: improve original test [2]
This expands the assertions executed in this test to cover the code under test more comprehensively.
2021-07-07 19:26:58 +02:00
jrfnl
cbecbc956b AddEmbeddedImageTest: improve original test [1]
The test code remaining in the `testEmbeddedImage()` constitutes one test.

This commit:
* Renames the test method and improves the description in the docblock.
* Removes the redundant call to `PHPMailer::clearAttachments()`.
    This call was previously needed as multiple situations were being tested in one test method.
    Now each test case has its own test method, the call to `PHPMailer::clearAttachments()` is no longer needed as each test method will receive a fresh, clean instance of the `PHPMailer` class.
* 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.
2021-07-07 19:26:56 +02:00
jrfnl
d034bef136 AddEmbeddedImageTest: split off "missing name" test
The test case when a file was attached without explicitly adding a filename wasn't actually being tested at all as no assertion was used.

This commit:
* Moves that particular test case to a separate test method.
* Adds relevant assertions to actually test the test case.
2021-07-07 19:26:54 +02:00
jrfnl
e5b07ba3c3 AddEmbeddedImageTest: split off failure test
The "failure" case when a non-existent file was being passed, wasn't actually being tested at all as no assertion was used.

This commit:
* Moves the particular failure test case to a separate test method with a data provider (to allow for more failure test cases to be added).
* Uses an assertion on the call to `addEmbeddedImage()` to actually test that the method return a failure state.
* Verifies that no attachment for an inline image was added by adding a second assertion with a call to `PHPMailer::inlineImageExists()`.
2021-07-07 19:26:53 +02:00
jrfnl
a866bc9eda AddEmbeddedImageTest: switch to preSend()
The actual "attaching" of the images happens within `createBody()` which is called from `preSend()`, so this test doesn't actually need to call `send()`.
2021-07-07 19:26:51 +02:00
jrfnl
8e76e48afb Tests/reorganize: move addEmbeddedImage 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-07 19:26:49 +02:00
jrfnl
da01dc50e0 CustomHeaderTest: add @covers tags 2021-07-07 17:42:47 +02:00
jrfnl
611c58c134 CustomHeaderTest: add extra test cases for testAddCustomHeaderInvalid() method 2021-07-07 17:42:45 +02:00
jrfnl
07be3bc7ff CustomHeaderTest: add extra test cases for testAddAndGetCustomHeader() method 2021-07-07 17:42:43 +02:00
jrfnl
d2a1a20097 CustomHeaderTest: reorganize rest to use data provider
* Maintains (largely) the same test cases.
* Prevent one failing assertion hiding a potential second failure.
* Makes it easier to add additional test cases in the future.

Note:
This removes the intermittent calls to `clearCustomHeaders()` from this test. This is now tested via a separate method and as each test case will receive a fresh instance of the `PHPMailer` class, there is no need to clear the set custom headers between tests.
2021-07-07 17:42:41 +02:00
jrfnl
fb81ccc224 CustomHeaderTest: add dedicated test for clearCustomHeaders() method
Includes adding an assertion to ensure that the `PHPMailer::CustomHeader` property is still in array format after clearing it out.
2021-07-07 17:42:40 +02:00
jrfnl
a7d9416e24 CustomHeaderTest: move "failure" tests to own method with data provider 2021-07-07 17:42:38 +02:00
jrfnl
22ba72fd99 CustomHeaderTest: rename exception test and improve
... by also testing that the exception message matches the expected message.
2021-07-07 17:42:36 +02:00
jrfnl
ce0c31cea7 Tests/reorganize: move custom header tests to own file 2021-07-07 17:42:34 +02:00
Marcus Bointon
2aa2614e5d
Merge pull request #2423 from jrfnl/feature/tests-haslinelongerthan-switch-to-presend
HasLineLongerThanMaxTest: switch to preSend()
2021-07-07 17:26:23 +02:00
jrfnl
6e0193958d HasLineLongerThanMaxTest: switch to preSend()
The line length adjustments are executed within `createBody()` which is called from `preSend()`, so this test doesn't actually need to call `send()`.

I also wonder if this test can be further improved by having more targeted tests for `PHPMailer::hasLineLongerThanMax()` and whether these more extensive tests can be included in a test class which is more targeted at the `createBody()` and/or `preSend()` methods, but that is for later.
2021-07-07 17:12:16 +02:00
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
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
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
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