1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ownCloud - Mail |
5
|
|
|
* |
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
7
|
|
|
* later. See the COPYING file. |
8
|
|
|
* |
9
|
|
|
* @author Christoph Wurst <[email protected]> |
10
|
|
|
* @copyright Christoph Wurst 2016 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Mail\Tests\Service\Autocompletion; |
14
|
|
|
|
15
|
|
|
use PHPUnit_Framework_TestCase; |
16
|
|
|
use OCA\Mail\Db\CollectedAddress; |
17
|
|
|
use OCA\Mail\Service\AutoCompletion\AddressCollector; |
18
|
|
|
|
19
|
|
|
class AddressCollectorTest extends PHPUnit_Framework_TestCase { |
20
|
|
|
|
21
|
|
|
private $mapper; |
22
|
|
|
private $userId = 'testuser'; |
23
|
|
|
private $logger; |
24
|
|
|
private $collector; |
25
|
|
|
|
26
|
|
|
protected function setUp() { |
27
|
|
|
parent::setUp(); |
28
|
|
|
|
29
|
|
|
$this->mapper = $this->getMockBuilder('\OCA\Mail\Db\CollectedAddressMapper') |
30
|
|
|
->disableOriginalConstructor() |
31
|
|
|
->getMock(); |
32
|
|
|
$this->logger = $this->getMockBuilder('\OCA\Mail\Service\Logger') |
33
|
|
|
->disableOriginalConstructor() |
34
|
|
|
->getMock(); |
35
|
|
|
|
36
|
|
|
$this->collector = new AddressCollector($this->mapper, $this->userId, |
37
|
|
|
$this->logger); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testAddAddresses() { |
41
|
|
|
$addresses = [ |
42
|
|
|
'[email protected]', |
43
|
|
|
'[email protected]', |
44
|
|
|
]; |
45
|
|
|
$data = array_map(function($address) { |
46
|
|
|
$ca = new CollectedAddress(); |
47
|
|
|
$ca->setEmail($address); |
48
|
|
|
$ca->setUserId($this->userId); |
49
|
|
|
return $ca; |
50
|
|
|
}, $addresses); |
51
|
|
|
|
52
|
|
|
$this->mapper->expects($this->at(0)) |
53
|
|
|
->method('exists') |
54
|
|
|
->with($this->userId, $addresses[0]) |
55
|
|
|
->will($this->returnValue(false)); |
56
|
|
|
$this->mapper->expects($this->at(1)) |
57
|
|
|
->method('insert') |
58
|
|
|
->with($data[0]); |
59
|
|
|
$this->mapper->expects($this->at(2)) |
60
|
|
|
->method('exists') |
61
|
|
|
->with($this->userId, $addresses[1]) |
62
|
|
|
->will($this->returnValue(false)); |
63
|
|
|
$this->mapper->expects($this->at(3)) |
64
|
|
|
->method('insert') |
65
|
|
|
->with($data[1]); |
66
|
|
|
|
67
|
|
|
$this->collector->addAddresses($addresses); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testAddDuplicateAddresses() { |
71
|
|
|
$addresses = [ |
72
|
|
|
'[email protected]', |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
$this->mapper->expects($this->at(0)) |
76
|
|
|
->method('exists') |
77
|
|
|
->with($this->userId, $addresses[0]) |
78
|
|
|
->will($this->returnValue(true)); |
79
|
|
|
$this->mapper->expects($this->never()) |
80
|
|
|
->method('insert'); |
81
|
|
|
|
82
|
|
|
$this->collector->addAddresses($addresses); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testSearchAddress() { |
86
|
|
|
$term = 'john'; |
87
|
|
|
$mapperResult = ['some', 'data']; |
88
|
|
|
|
89
|
|
|
$this->mapper->expects($this->once()) |
90
|
|
|
->method('findMatching') |
91
|
|
|
->with($this->userId, $term) |
92
|
|
|
->will($this->returnValue($mapperResult)); |
93
|
|
|
|
94
|
|
|
$result = $this->collector->searchAddress($term); |
|
|
|
|
95
|
|
|
|
96
|
|
|
$this->assertequals($mapperResult, $result); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: