Debian Codegraph @

tests/phpunit/integration/includes/mail/EmailerTest.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Tests\Integration\Mail;
22
23 use MailAddress;
24 use MediaWiki\Mail\Emailer;
25 use MediaWikiIntegrationTestCase;
26
27 /**
28 * @group Mail
29 * @covers \MediaWiki\Mail\Emailer
30 * @covers \UserMailer
31 */
32 class EmailerTest extends MediaWikiIntegrationTestCase {
33
34 /**
35 * Tests the send method with a good address and good parameters.
36 * @dataProvider provideSend
37 */
38 public function testSend( $to, MailAddress $from, string $subject, string $bodyText, ?string $bodyHtml = null,
39 array $options = [] ) {
40 $emailer = new Emailer();
41 $status = $emailer->send( $to, $from, $subject, $bodyText, $bodyHtml, $options );
42 // The test is successful if the status is good.
43 $this->assertTrue( $status->isGood() );
44 }
45
46 public function testSendWithBadAddress() {
47 // Create a new Emailer object.
48 $emailer = new Emailer();
49 // Send an email.
50 $status = $emailer->send(
51 new MailAddress( ' ', 'Sender', 'Real name' ),
52 new MailAddress( ' ', 'Recipient', 'Real name' ),
53 '',
54 '',
55 );
56 // The test is successful if the status is not good.
57 $this->assertFalse( $status->isGood() );
58 }
59
60 public function provideSend(): array {
61 $from = new MailAddress( '[email protected]', 'UserName', 'Real name' );
62 $to = new MailAddress( '[email protected]', 'UserName', 'Real name' );
63 $bodyHtml = '<p>Hello, World!</p>';
64 return [
65 [ $to, $from, 'Test subject', 'Hello, World!' ],
66 [ $to, $from, 'Test subject', 'Hello, World!', $bodyHtml ],
67 [ $to, $from, 'Test subject', 'Hello, World!', $bodyHtml, [ 'cc' => [ $from ] ] ],
68 ];
69 }
70 }