Completed
Push — master ( 45aa1e...841b62 )
by Thomas
19:35
created

AccountTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 91
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 * @author Clement Wong <[email protected]>
6
 * @author Jan-Christoph Borchardt <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 *
9
 * Mail
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
namespace OCA\Mail\Tests\Imap;
25
26
class AccountTest extends AbstractTest {
27
28
	/**
29
	 * @dataProvider providesMailBoxNames
30
	 * @param $name
31
	 */
32
	public function testCreateAndDelete($name) {
33
		$name = uniqid($name);
34
		$this->createMailBox($name);
35
		$this->assertMailBoxExists($name);
36
37
		$this->getTestAccount()->deleteMailbox($name);
38
		$this->assertMailBoxNotExists($name);
39
	}
40
41
	public function providesMailBoxNames() {
42
		return [
43
			['boxbox'],
44
			['box box'],
45
			['äöü']
46
		];
47
	}
48
49
	/**
50
	 * @dataProvider providesMailBoxNames
51
	 * @param $name
52
	 */
53
	public function testListMailBoxes($name) {
54
		$name = uniqid($name);
55
		$this->createMailBox($name);
56
		$mailBoxes = $this->getTestAccount()->getListArray();
57
		$this->assertInternalType('array', $mailBoxes);
58
59
		$m = array_filter($mailBoxes['folders'], function($item) use ($name) {
60
			return $item['name'] === $name;
61
		});
62
		$this->assertTrue(count($m) === 1);
63
	}
64
65
	/**
66
	 * @dataProvider providesMailBoxNames
67
	 * @param $name
68
	 */
69
	public function testListMessages($name) {
70
		$name = uniqid($name);
71
		$newMailBox = parent::createMailBox($name);
72
		$count = $newMailBox->getTotalMessages();
73
		$this->assertEquals(0, $count);
74
		$messages = $newMailBox->getMessages();
75
		$this->assertInternalType('array', $messages);
76
		$this->assertEquals(0, count($messages));
77
		$this->createTestMessage($newMailBox);
78
		$count = $newMailBox->getTotalMessages();
79
		$this->assertEquals(1, $count);
80
		$messages = $newMailBox->getMessages();
81
		$this->assertInternalType('array', $messages);
82
		$this->assertEquals(1, count($messages));
83
	}
84
85
	/**
86
	 * @dataProvider providesMailBoxNames
87
	 * @param $name
88
	 */
89
	public function testGetChangedMailboxes($name) {
90
		$name = uniqid($name);
91
		$newMailBox = parent::createMailBox($name);
92
		$status = $newMailBox->getStatus();
93
		$changedMailBoxes = $this->getTestAccount()->getChangedMailboxes([
94
			$newMailBox->getFolderId() => [ 'uidvalidity' => $status['uidvalidity'], 'uidnext' => $status['uidnext'] ]
95
		]);
96
97
		$this->assertEquals(0, count($changedMailBoxes));
98
99
		$this->createTestMessage($newMailBox);
100
101
		$changedMailBoxes = $this->getTestAccount()->getChangedMailboxes([
102
			$newMailBox->getFolderId() => [ 'uidvalidity' => $status['uidvalidity'], 'uidnext' => $status['uidnext'] ]
103
		]);
104
105
		$this->assertEquals(1, count($changedMailBoxes));
106
		$this->assertEquals(1, count($changedMailBoxes[$newMailBox->getFolderId()]['messages']));
107
	}
108
109
	public function testGetChangedMailboxesForNotExisting() {
110
		$changedMailBoxes = $this->getTestAccount()->getChangedMailboxes([
111
			'you-dont-know-me' => ['uidvalidity' => 0, 'uidnext' => 0]
112
		]);
113
114
		$this->assertEquals(0, count($changedMailBoxes));
115
	}
116
}
117