aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Mail/Provider/MessageTest.php
blob: 1791a03421c39f63a5e854c91207e032c3462430 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace Test\Mail\Provider;

use OCP\Mail\Provider\Address;
use OCP\Mail\Provider\Attachment;
use OCP\Mail\Provider\Message;
use Test\TestCase;

class MessageTest extends TestCase {

	/** @var Message&MockObject */
	private Message $message;
	/** @var Address&MockObject */
	private Address $address1;
	/** @var Address&MockObject */
	private Address $address2;
	/** @var Attachment&MockObject */
	private Attachment $attachment1;
	/** @var Attachment&MockObject */
	private Attachment $attachment2;

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

		$this->message = new Message(
			['id' => 'cd02ea42-feac-4863-b9d8-484d16a587ea']
		);
		$this->address1 = new Address(
			'user1@testing.com',
			'User One'
		);
		$this->address2 = new Address(
			'user2@testing.com',
			'User Two'
		);
		$this->attachment1 = new Attachment(
			'This is the contents of the first attachment',
			'example1.txt',
			'text/plain',
			false
		);
		$this->attachment2 = new Attachment(
			'This is the contents of the second attachment',
			'example1.txt',
			'text/plain',
			false
		);

	}

	public function testId(): void {
		
		// test set by constructor
		$this->assertEquals('cd02ea42-feac-4863-b9d8-484d16a587ea', $this->message->id());

	}

	public function testFrom(): void {
		
		// test not set
		$this->assertNull($this->message->getFrom());
		// test set by setter
		$this->message->setFrom($this->address1);
		$this->assertEquals($this->address1, $this->message->getFrom());

	}

	public function testReplyTo(): void {
		
		// test not set
		$this->assertNull($this->message->getReplyTo());
		// test set by setter
		$this->message->setReplyTo($this->address1);
		$this->assertEquals($this->address1, $this->message->getReplyTo());

	}

	public function testTo(): void {
		
		// test not set
		$this->assertEquals([], $this->message->getTo());
		// test set by setter single
		$this->message->setTo($this->address1);
		$this->assertEquals([$this->address1], $this->message->getTo());
		// test set by setter multiple
		$this->message->setTo($this->address1, $this->address2);
		$this->assertEquals([$this->address1, $this->address2], $this->message->getTo());

	}

	public function testCc(): void {
		
		// test not set
		$this->assertEquals([], $this->message->getCc());
		// test set by setter single
		$this->message->setCc($this->address1);
		$this->assertEquals([$this->address1], $this->message->getCc());
		// test set by setter multiple
		$this->message->setCc($this->address1, $this->address2);
		$this->assertEquals([$this->address1, $this->address2], $this->message->getCc());

	}

	public function testBcc(): void {
		
		// test not set
		$this->assertEquals([], $this->message->getBcc());
		// test set by setter single
		$this->message->setBcc($this->address1);
		$this->assertEquals([$this->address1], $this->message->getBcc());
		// test set by setter multiple
		$this->message->setBcc($this->address1, $this->address2);
		$this->assertEquals([$this->address1, $this->address2], $this->message->getBcc());

	}

	public function testSubject(): void {
		
		// test not set
		$this->assertNull($this->message->getSubject());
		// test set by setter
		$this->message->setSubject('Testing Mail Subject');
		$this->assertEquals('Testing Mail Subject', $this->message->getSubject());

	}

	public function testBody(): void {
		
		// test not set
		$this->assertNull($this->message->getBody());
		// test set by setter - text body
		$this->message->setBody('Testing Text Body', false);
		$this->assertEquals('Testing Text Body', $this->message->getBody());
		$this->message->setBodyPlain('Testing Text Body Again', false);
		$this->assertEquals('Testing Text Body Again', $this->message->getBodyPlain());
		// test set by setter - html body
		$this->message->setBody('Testing HTML Body', true);
		$this->assertEquals('Testing HTML Body', $this->message->getBody());
		$this->message->setBodyHtml('Testing HTML Body Again', false);
		$this->assertEquals('Testing HTML Body Again', $this->message->getBodyHtml());

	}

	public function testAttachments(): void {
		
		// test not set
		$this->assertEquals([], $this->message->getAttachments());
		// test set by setter single
		$this->message->setAttachments($this->attachment1);
		$this->assertEquals([$this->attachment1], $this->message->getAttachments());
		// test set by setter multiple
		$this->message->setAttachments($this->attachment1, $this->attachment2);
		$this->assertEquals([$this->attachment1, $this->attachment2], $this->message->getAttachments());

	}
}