|
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\Service\AutoCompletion\AutoCompleteService; |
|
17
|
|
|
|
|
18
|
|
|
class AutoCompleteServiceTest extends PHPUnit_Framework_TestCase { |
|
19
|
|
|
|
|
20
|
|
|
private $contactsIntegration; |
|
21
|
|
|
private $addressCollector; |
|
22
|
|
|
private $service; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() { |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
|
|
27
|
|
|
$this->contactsIntegration = $this->getMockBuilder('\OCA\Mail\Service\ContactsIntegration') |
|
28
|
|
|
->disableOriginalConstructor() |
|
29
|
|
|
->getMock(); |
|
30
|
|
|
$this->addressCollector = $this->getMockBuilder('\OCA\Mail\Service\AutoCompletion\AddressCollector') |
|
31
|
|
|
->disableOriginalConstructor() |
|
32
|
|
|
->getMock(); |
|
33
|
|
|
|
|
34
|
|
|
$this->service = new AutoCompleteService($this->contactsIntegration, |
|
35
|
|
|
$this->addressCollector); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testFindMatches() { |
|
39
|
|
|
$term = 'jo'; |
|
40
|
|
|
|
|
41
|
|
|
$contactsResult = [ |
|
42
|
|
|
['id' => 12, 'label' => 'john doe', 'value' => 'john doe'], |
|
43
|
|
|
['id' => 13, 'label' => 'joe doe', 'value' => 'joe doe'], |
|
44
|
|
|
]; |
|
45
|
|
|
$john = new \OCA\Mail\Db\CollectedAddress(); |
|
46
|
|
|
$john->setId(1234); |
|
47
|
|
|
$john->setEmail('[email protected]'); |
|
48
|
|
|
$john->setUserId('testuser'); |
|
49
|
|
|
$collectedResult = [ |
|
50
|
|
|
$john, |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
$this->contactsIntegration->expects($this->once()) |
|
54
|
|
|
->method('getMatchingRecipient') |
|
55
|
|
|
->with($term) |
|
56
|
|
|
->will($this->returnValue($contactsResult)); |
|
57
|
|
|
$this->addressCollector->expects($this->once()) |
|
58
|
|
|
->method('searchAddress') |
|
59
|
|
|
->with($term) |
|
60
|
|
|
->will($this->returnValue($collectedResult)); |
|
61
|
|
|
|
|
62
|
|
|
$response = $this->service->findMatches($term); |
|
63
|
|
|
|
|
64
|
|
|
$expected = [ |
|
65
|
|
|
['id' => 12, 'label' => 'john doe', 'value' => 'john doe'], |
|
66
|
|
|
['id' => 13, 'label' => 'joe doe', 'value' => 'joe doe'], |
|
67
|
|
|
['id' => 1234, 'label' => '[email protected]', 'value' => '[email protected]'], |
|
68
|
|
|
]; |
|
69
|
|
|
$this->assertEquals($expected, $response); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|