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

ReportEmailGeneratorTest.php « Integration « tests « ScheduledReports « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 510ad749318215a3ab681bfaa3aa1c8254e05652 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
 * Copyright (C) InnoCraft Ltd - All rights reserved.
 *
 * NOTICE:  All information contained herein is, and remains the property of InnoCraft Ltd.
 * The intellectual and technical concepts contained herein are protected by trade secret or copyright law.
 * Redistribution of this information or reproduction of this material is strictly forbidden
 * unless prior written permission is obtained from InnoCraft Ltd.
 *
 * You shall use this code only in accordance with the license agreement obtained from InnoCraft Ltd.
 *
 * @link https://www.innocraft.com/
 * @license For license details see https://www.innocraft.com/license
 */

namespace Piwik\Plugins\ScheduledReports\tests\Integration;

use Piwik\Mail;
use Piwik\Plugins\ScheduledReports\GeneratedReport;
use Piwik\Plugins\ScheduledReports\ReportEmailGenerator;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;

class TestReportEmailGenerator extends ReportEmailGenerator
{
    protected function configureEmail(Mail $mail, GeneratedReport $report)
    {
        // empty
    }
}


class ReportEmailGeneratorTest extends IntegrationTestCase
{
    /**
     * @var TestReportEmailGenerator
     */
    private $testInstance;

    public function setUp(): void
    {
        parent::setUp();

        $this->testInstance = new TestReportEmailGenerator();
    }

    public function test_makeEmail_CreatesCorrectlyConfiguredMailInstance()
    {
        $reportDetails = [];

        $generatedReport = new GeneratedReport(
            $reportDetails,
            'report',
            'pretty date',
            'report contents',
            [
                [
                    'mimeType' => 'mimetype1',
                    'encoding' => 'utf-8',
                    'content' => 'content 1',
                    'filename' => 'file1.txt',
                    'cid' => 'cid1',
                ],
                [
                    'mimeType' => 'mimetype2',
                    'encoding' => 'utf-8',
                    'content' => 'content 2',
                    'filename' => 'file2.txt',
                    'cid' => 'cid2',
                ],
            ]
        );

        $mail = $this->testInstance->makeEmail($generatedReport);

        $this->assertEquals('General_Report report - pretty date', $mail->getSubject());

        $parts = array_map(function (\Zend_Mime_Part $part) {
            return [
                'content' => $part->getContent(),
                'headers' => $part->getHeaders(),
            ];
        }, $mail->getParts());
        $this->assertEquals([
            [
                'content' => 'content 1',
                'headers' => 'Content-Type: mimetype1
Content-Transfer-Encoding: utf-8
Content-ID: <cid1>
Content-Disposition: inline; filename="file1.txt"
',
            ],
            [
                'content' => 'content 2',
                'headers' => 'Content-Type: mimetype2
Content-Transfer-Encoding: utf-8
Content-ID: <cid2>
Content-Disposition: inline; filename="file2.txt"
',
            ],
        ], $parts);
    }

    public function test_makeEmail_UsesCustomReplyTo_IfSupplied()
    {
        $reportDetails = [];

        $generatedReport = new GeneratedReport(
            $reportDetails,
            'report',
            'pretty date',
            'report contents',
            []
        );

        $mail = $this->testInstance->makeEmail($generatedReport, [
            'email' => 'test@testytesterson.com',
            'alias' => 'test person',
        ]);

        $this->assertEquals('General_Report report - pretty date', $mail->getSubject());
        $this->assertEquals('test@testytesterson.com', $mail->getReplyTo());
        $this->assertEquals([
            'From' => [
                0 => 'TagManager_MatomoTagName <noreply@localhost>',
                'append' => true,
            ],
            'Subject' => [
                0 => 'General_Report report - pretty date',
            ],
            'Reply-To' => [
                0 => 'test person <test@testytesterson.com>',
                'append' => true,
            ],
        ], $mail->getHeaders());
        $this->assertEquals([], $mail->getParts());
    }
}