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

AutoCompleteServiceTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 55
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[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\Tests\Service\Autocompletion;
23
24
use PHPUnit_Framework_TestCase;
25
use OCA\Mail\Service\AutoCompletion\AutoCompleteService;
26
27
class AutoCompleteServiceTest extends PHPUnit_Framework_TestCase {
28
29
	private $contactsIntegration;
30
	private $addressCollector;
31
	private $service;
32
33
	protected function setUp() {
34
		parent::setUp();
35
36
		$this->contactsIntegration = $this->getMockBuilder('\OCA\Mail\Service\ContactsIntegration')
37
			->disableOriginalConstructor()
38
			->getMock();
39
		$this->addressCollector = $this->getMockBuilder('\OCA\Mail\Service\AutoCompletion\AddressCollector')
40
			->disableOriginalConstructor()
41
			->getMock();
42
43
		$this->service = new AutoCompleteService($this->contactsIntegration,
44
			$this->addressCollector);
45
	}
46
47
	public function testFindMatches() {
48
		$term = 'jo';
49
50
		$contactsResult = [
51
			['id' => 12, 'label' => 'john doe', 'value' => 'john doe'],
52
			['id' => 13, 'label' => 'joe doe', 'value' => 'joe doe'],
53
		];
54
		$john = new \OCA\Mail\Db\CollectedAddress();
55
		$john->setId(1234);
56
		$john->setEmail('[email protected]');
57
		$john->setUserId('testuser');
58
		$collectedResult = [
59
			$john,
60
		];
61
62
		$this->contactsIntegration->expects($this->once())
63
			->method('getMatchingRecipient')
64
			->with($term)
65
			->will($this->returnValue($contactsResult));
66
		$this->addressCollector->expects($this->once())
67
			->method('searchAddress')
68
			->with($term)
69
			->will($this->returnValue($collectedResult));
70
71
		$response = $this->service->findMatches($term);
72
73
		$expected = [
74
			['id' => 12, 'label' => 'john doe', 'value' => 'john doe'],
75
			['id' => 13, 'label' => 'joe doe', 'value' => 'joe doe'],
76
			['id' => 1234, 'label' => '[email protected]', 'value' => '[email protected]'],
77
		];
78
		$this->assertEquals($expected, $response);
79
	}
80
81
}
82