1 | <?php |
||
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 |