Debian Codegraph @

tests/phpunit/unit/includes/mail/UserMailerTest.php

raw symbols SCIP
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 /**
6 * @group Mail
7 * @covers \UserMailer
8 */
9 class UserMailerTest extends MediaWikiUnitTestCase {
10
11 public function testQuotedPrintable() {
12 $this->assertEquals(
13 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
14 UserMailer::quotedPrintable( "\xc4\x88u legebla?", "UTF-8" )
15 );
16
17 $this->assertEquals(
18 "=?UTF-8?Q?F=C3=B6o=2EBar?=",
19 UserMailer::quotedPrintable( "Föo.Bar", "UTF-8" )
20 );
21
22 $this->assertEquals(
23 "Foo.Bar",
24 UserMailer::quotedPrintable( "Foo.Bar", "UTF-8" )
25 );
26 }
27
28 /**
29 * @dataProvider provideRecipientDomains
30 */
31 public function testRecipientDomains( array $addresses, string $expected ) {
32 $to = array_map( static fn ( string $address ) => new MailAddress( $address ), $addresses );
33 $this->assertSame(
34 $expected,
35 TestingAccessWrapper::newFromClass( UserMailer::class )->recipientDomains( $to )
36 );
37 }
38
39 public static function provideRecipientDomains(): array {
40 return [
41 'single recipient' => [ [ '[email protected]' ], 'example.org' ],
42 'distinct domains, in order' => [
43 [ '[email protected]', '[email protected]' ],
44 'example.org, gmail.com',
45 ],
46 'duplicate domains collapse to one' => [
47 [ '[email protected]', '[email protected]' ],
48 'example.org',
49 ],
50 'address without @ is skipped' => [
51 [ 'invalid', '[email protected]' ],
52 'gmail.com',
53 ],
54 'no extractable domain yields empty string' => [
55 [ 'invalid', 'alsoinvalid' ],
56 '',
57 ],
58 ];
59 }
60
61 /**
62 * @dataProvider provideMailLogContext
63 */
64 public function testMailLogContext( array $toAddresses, string $fromAddress, array $expected ) {
65 $to = array_map( static fn ( string $address ) => new MailAddress( $address ), $toAddresses );
66 $from = new MailAddress( $fromAddress );
67 $this->assertSame(
68 $expected,
69 TestingAccessWrapper::newFromClass( UserMailer::class )->mailLogContext( $to, $from )
70 );
71 }
72
73 public static function provideMailLogContext(): array {
74 return [
75 'single recipient' => [
76 [ '[email protected]' ],
77 '[email protected]',
78 [
79 'to' => '[email protected]',
80 'recipient_count' => 1,
81 'recipient_domains' => 'example.org',
82 'from' => '[email protected]',
83 ],
84 ],
85 'multiple recipients log the first as {to}' => [
86 [ '[email protected]', '[email protected]' ],
87 '[email protected]',
88 [
89 'to' => '[email protected]',
90 'recipient_count' => 2,
91 'recipient_domains' => 'example.org, gmail.com',
92 'from' => '[email protected]',
93 ],
94 ],
95 ];
96 }
97 }