File: Smtp.php

package info (click to toggle)
roundcube 1.6.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,888 kB
  • sloc: javascript: 195,591; php: 76,917; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (62 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

namespace Roundcube\Tests\Framework;

use PHPUnit\Framework\TestCase;

use function Roundcube\Tests\invokeMethod;

/**
 * Test class to test rcube_smtp class
 */
class Framework_Smtp extends TestCase
{
    /**
     * Class constructor
     */
    function test_class()
    {
        $object = new \rcube_smtp();

        $this->assertInstanceOf(\rcube_smtp::class, $object, "Class constructor");
    }

    /**
     * Test preparing headers
     */
    function test_prepare_headers()
    {
        $smtp = new \rcube_smtp();

        $headers = [
            'Subject' => 'Test',
            'From' => '"John Doe" <john@domain.tld>',
            'Received' => 'from github.com ([10.48.109.45]) by smtp.github.com (Postfix) with ESMTPA id 8C9B4E0075'
                . ' for <john@domain.tld>; Sat, 28 Nov 2020 22:45:44 -0800 (PST)',
        ];

        $result = invokeMethod($smtp, '_prepare_headers', [$headers]);

        $this->assertCount(2, $result);
        $this->assertSame('john@domain.tld', $result[0]);
        $this->assertSame(
            "Received: from github.com ([10.48.109.45]) by smtp.github.com (Postfix) with ESMTPA id 8C9B4E0075"
                . " for <john@domain.tld>; Sat, 28 Nov 2020 22:45:44 -0800 (PST)\r\n"
                . "Subject: Test\r\n"
                . "From: \"John Doe\" <john@domain.tld>\r\n",
            $result[1]
        );
    }

    /**
     * Test parsing email address input
     */
    function test_parse_rfc822()
    {
        $smtp   = new \rcube_smtp();
        $input  = 'test@test1.com, "test" <test@test2.pl>, "test@test3.eu" <test@test3.uk>';
        $result = invokeMethod($smtp, '_parse_rfc822', [$input]);

        $this->assertSame(['test@test1.com', 'test@test2.pl', 'test@test3.uk'], $result);
    }
}