Completed
Pull Request — master (#1638)
by Thomas
06:26
created

MailAccountMapperTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 78
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Thomas Müller <[email protected]>
5
 *
6
 * Mail
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Mail\Db;
23
24
use OC\AppFramework\Db\Db;
25
26
class MailAccountMapperTest extends \PHPUnit_Framework_TestCase {
27
28
	/**
29
	 * @var MailAccountMapper
30
	 */
31
	private $mapper;
32
33
	/**
34
	 * @var \OC\DB\Connection
35
	 */
36
	private $db;
37
38
	/**
39
	 * @var MailAccount
40
	 */
41
	private $account;
42
43
	/**
44
	 * Initialize Mapper
45
	 */
46
	public function setup(){
47
		$db = \OC::$server->getDatabaseConnection();
48
		$this->db = new Db($db);
49
		$this->mapper = new MailAccountMapper($this->db);
50
51
		$this->account = new MailAccount();
52
		$this->account->setName('Peter Parker');
53
		$this->account->setInboundHost('mail.marvel.com');
54
		$this->account->setInboundPort(159);
55
		$this->account->setInboundUser('spiderman');
56
		$this->account->setInboundPassword('xxxxxxxx');
57
		$this->account->setInboundSslMode('tls');
58
		$this->account->setEmail('[email protected]');
59
		$this->account->setOutboundHost('smtp.marvel.com');
60
		$this->account->setOutboundPort(458);
61
		$this->account->setOutboundUser('spiderman');
62
		$this->account->setOutboundPassword('xxxx');
63
		$this->account->setOutboundSslMode('ssl');
64
		$this->account->setUserId('user12345');
65
	}
66
67
	public function testFind(){
68
69
		/** @var MailAccount $b */
70
		$b = $this->mapper->insert($this->account);
71
72
		$result = $this->mapper->find($b->getUserId(), $b->getId());
73
		$this->assertEquals($b->toJson(), $result->toJson());
74
75
		$result = $this->mapper->findByUserId($b->getUserId());
76
		$c = array_filter($result, function($a) use($b){
77
			/** @var MailAccount $a */
78
			return $a->getId() === $b->getId();
79
		});
80
		$c = array_pop($c);
81
		$this->assertEquals($b->toJson(), $c->toJson());
82
	}
83
84
	public function testSave() {
85
86
		$a = $this->account;
87
88
		// test insert
89
		$b = $this->mapper->save($a);
90
		$this->assertNotNull($b);
91
		$this->assertNotNull($a->getId());
92
		$this->assertNotNull($b->getId());
93
		$this->assertEquals($a->getId(), $b->getId());
94
95
		// update the entity
96
		$b->setEmail('[email protected]');
97
		$c = $this->mapper->save($b);
98
		$this->assertNotNull($c);
99
		$this->assertNotNull($c->getId());
100
		$this->assertNotNull($b->getId());
101
		$this->assertEquals($b->getId(), $c->getId());
102
	}
103
}
104