Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AutoCompleteServiceTest.php « Autocompletion « Service « Unit « tests - github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9bd24bec7ec0135a7c5e5ba8148120c2676578dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php

/**
 * @author Christoph Wurst <christoph@winzerhof-wurst.at>
 * @author Matthias Rella <mrella@pisys.eu>
 *
 * Mail
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OCA\Mail\Tests\Unit\Service\Autocompletion;

use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Db\CollectedAddress;
use OCA\Mail\Service\AutoCompletion\AutoCompleteService;
use OCA\Mail\Service\AutoCompletion\AddressCollector;
use OCA\Mail\Service\ContactsIntegration;
use OCA\Mail\Service\GroupsIntegration;

class AutoCompleteServiceTest extends TestCase {

	private $contactsIntegration;
	private $groupsIntegration;
	private $addressCollector;
	private $service;

	protected function setUp(): void {
		parent::setUp();

		$this->contactsIntegration = $this->createMock(ContactsIntegration::class);
		$this->groupsIntegration = $this->createMock(GroupsIntegration::class);
		$this->addressCollector = $this->createMock(AddressCollector::class);

		$this->service = new AutoCompleteService($this->contactsIntegration,
			$this->groupsIntegration,
			$this->addressCollector);
	}

	public function testFindMatches() {
		$term = 'jo';

		$contactsResult = [
			['id' => 12, 'label' => '"john doe" <john@doe.cz>', 'email' => 'john@doe.cz'],
			['id' => 13, 'label' => '"joe doe" <joe@doe.se>', 'email' => 'joe@doe.se'],
		];
		$john = new CollectedAddress();
		$john->setId(1234);
		$john->setEmail('john@doe.com');
		$john->setDisplayName('John Doe');
		$john->setUserId('testuser');
		$collectedResult = [
			$john,
		];

		$groupsResult = [
			['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists']
		];

		$this->contactsIntegration->expects($this->once())
			->method('getMatchingRecipient')
			->with($term)
			->will($this->returnValue($contactsResult));
		$this->groupsIntegration->expects($this->once())
			->method('getMatchingGroups')
			->with($term)
			->will($this->returnValue($groupsResult));
		$this->addressCollector->expects($this->once())
			->method('searchAddress')
			->with($term)
			->will($this->returnValue($collectedResult));

		$response = $this->service->findMatches($term);

		$expected = [
			['id' => 12, 'label' => '"john doe" <john@doe.cz>', 'email' => 'john@doe.cz'],
			['id' => 13, 'label' => '"joe doe" <joe@doe.se>', 'email' => 'joe@doe.se'],
			['id' => 1234, 'label' => 'John Doe', 'email' => 'john@doe.com'],
			['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists'],
		];
		$this->assertEquals($expected, $response);
	}

}