Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordizzy <diosmosis@users.noreply.github.com>2021-05-30 22:21:05 +0300
committerGitHub <noreply@github.com>2021-05-30 22:21:05 +0300
commit30eec9445b0a2117f80305f7a367121039f04817 (patch)
treedff6d781055417fa6754202d6aed4f7d43efd51d /tests
parent0e34030c2c29c9908f0cf2fca13db9ac54e62e8c (diff)
Allow aborting sending mails via Mail.send event. (#17635)
* Allow aborting sending mails via Mail.send event. * Add quick entry to developer changelog. * add test
Diffstat (limited to 'tests')
-rw-r--r--tests/PHPUnit/Integration/MailTest.php59
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/PHPUnit/Integration/MailTest.php b/tests/PHPUnit/Integration/MailTest.php
index 8b64543fc6..f93a94279a 100644
--- a/tests/PHPUnit/Integration/MailTest.php
+++ b/tests/PHPUnit/Integration/MailTest.php
@@ -9,9 +9,27 @@
namespace Piwik\Tests\Integration;
use Piwik\Mail;
+use Piwik\Piwik;
+use Piwik\Tests\Framework\TestCase\UnitTestCase;
-class MailTest extends \PHPUnit\Framework\TestCase
+class MailTest extends UnitTestCase
{
+ /**
+ * @var Mail[]
+ */
+ public $sentMails = [];
+
+ public function setUp(): void
+ {
+ parent::setUp();
+ $this->sentMails = [];
+ }
+
+ public function tearDown(): void
+ {
+ $this->sentMails = [];
+ parent::tearDown();
+ }
public function getEmailFilenames()
{
@@ -29,4 +47,43 @@ class MailTest extends \PHPUnit\Framework\TestCase
$mail = new Mail();
$this->assertEquals($expected, $mail->sanitiseString($raw));
}
+
+ public function test_abortSendingMail()
+ {
+ $mail = new Mail();
+ $result = $mail->send();
+
+ $this->assertTrue($result);
+ $this->assertCount(1, $this->sentMails);
+
+ Piwik::addAction('Mail.send', function (&$mail) { $mail = null; });
+
+ $mail2 = new Mail();
+ $result = $mail2->send();
+
+ $this->assertNull($result);
+ $this->assertCount(1, $this->sentMails);
+ }
+
+ protected function provideContainerConfig()
+ {
+ $mockTransport = new class($this) extends Mail\Transport {
+ private $testCase;
+
+ public function __construct(MailTest $mailTest)
+ {
+ $this->testCase = $mailTest;
+ }
+
+ public function send(Mail $mail)
+ {
+ $this->testCase->sentMails[] = $mail;
+ return true;
+ }
+ };
+
+ return [
+ Mail\Transport::class => $mockTransport,
+ ];
+ }
}