|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Christoph Wurst <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* ownCloud - 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\Tests\Db; |
|
23
|
|
|
|
|
24
|
|
|
use Test\TestCase; |
|
25
|
|
|
use OCA\Mail\Db\CollectedAddressMapper; |
|
26
|
|
|
use OCA\Mail\Db\CollectedAddress; |
|
27
|
|
|
|
|
28
|
|
|
class CollectedAddressMapperTest extends TestCase { |
|
29
|
|
|
|
|
30
|
|
|
/** @var OCP\IDBConnection */ |
|
31
|
|
|
private $db; |
|
32
|
|
|
private $userId = 'testuser'; |
|
33
|
|
|
private $mapper; |
|
34
|
|
|
private $address1; |
|
35
|
|
|
private $address2; |
|
36
|
|
|
|
|
37
|
|
|
protected function setUp() { |
|
38
|
|
|
parent::setUp(); |
|
39
|
|
|
|
|
40
|
|
|
$this->db = \OC::$server->getDatabaseConnection(); |
|
41
|
|
|
$this->mapper = new CollectedAddressMapper($this->db); |
|
42
|
|
|
|
|
43
|
|
|
$this->address1 = new CollectedAddress(); |
|
44
|
|
|
$this->address1->setEmail('[email protected]'); |
|
45
|
|
|
$this->address1->setUserId($this->userId); |
|
46
|
|
|
|
|
47
|
|
|
$this->address2 = new CollectedAddress(); |
|
48
|
|
|
$this->address2->setEmail('[email protected]'); |
|
49
|
|
|
$this->address2->setUserId($this->userId); |
|
50
|
|
|
|
|
51
|
|
|
$sql = 'INSERT INTO *PREFIX*mail_collected_addresses (`email`, `user_id`) VALUES (?, ?)'; |
|
52
|
|
|
$stmt = $this->db->prepare($sql); |
|
53
|
|
|
|
|
54
|
|
|
$stmt->execute([ |
|
55
|
|
|
$this->address1->getEmail(), |
|
56
|
|
|
$this->address1->getUserId(), |
|
57
|
|
|
]); |
|
58
|
|
|
$this->address1->setId($this->db->lastInsertId()); |
|
59
|
|
|
$stmt->execute([ |
|
60
|
|
|
$this->address2->getEmail(), |
|
61
|
|
|
$this->address2->getUserId(), |
|
62
|
|
|
]); |
|
63
|
|
|
$this->address2->setId($this->db->lastInsertId()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function tearDown() { |
|
67
|
|
|
parent::tearDown(); |
|
68
|
|
|
|
|
69
|
|
|
$sql = 'DELETE FROM *PREFIX*mail_collected_addresses WHERE `id` = ?'; |
|
70
|
|
|
$stmt = $this->db->prepare($sql); |
|
71
|
|
|
$stmt->execute([$this->address1->getId()]); |
|
72
|
|
|
$stmt->execute([$this->address2->getId()]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function matchingData() { |
|
76
|
|
|
return [ |
|
77
|
|
|
['[email protected]', ['[email protected]']], |
|
78
|
|
|
['ser', ['[email protected]', '[email protected]']], |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @dataProvider matchingData |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testFindMatching($query, $result) { |
|
86
|
|
|
$matches = $this->mapper->findMatching($this->userId, $query); |
|
87
|
|
|
|
|
88
|
|
|
$this->assertCount(count($result), $matches); |
|
89
|
|
|
$i = 0; |
|
90
|
|
|
foreach ($matches as $match) { |
|
91
|
|
|
$this->assertInstanceOf('\OCA\Mail\Db\CollectedAddress', $match); |
|
92
|
|
|
$this->assertTrue(in_array($match->getEmail(), $result)); |
|
93
|
|
|
$this->assertEquals($this->userId, $match->getUserId()); |
|
94
|
|
|
$i++; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function existsData() { |
|
99
|
|
|
return [ |
|
100
|
|
|
['[email protected]', true], |
|
101
|
|
|
['[email protected]', false], |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @dataProvider existsData |
|
107
|
|
|
*/ |
|
108
|
|
|
public function testExists($email, $expected) { |
|
109
|
|
|
$actual = $this->mapper->exists($this->userId, $email); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertSame($expected, $actual); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|