Completed
Pull Request — master (#1276)
by Thomas
04:23
created

AutoCompleteServiceTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 55
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 13 1
B testFindMatches() 0 33 1
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