This repository has been archived by the owner on Nov 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e59e365
commit 5c86661
Showing
6 changed files
with
249 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/** | ||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* ownCloud - Mail app | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or any later version. | ||
* | ||
* This library 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 Lesser General Public | ||
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
use PHPUnit_Framework_TestCase; | ||
use OCA\Mail\Controller\AutoCompleteController; | ||
|
||
class AutoConfigControllerTest extends PHPUnit_Framework_TestCase { | ||
|
||
private $request; | ||
private $service; | ||
private $controller; | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->request = $this->getMock('OCP\IRequest'); | ||
$this->service = $this->getMockBuilder('OCA\Mail\Service\AutoCompletion\AutoCompleteService') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->controller = new AutoCompleteController('mail', $this->request, | ||
$this->service); | ||
} | ||
|
||
public function testAutoComplete() { | ||
$term = 'john d'; | ||
$result = 'johne doe'; | ||
|
||
$this->service->expects($this->once()) | ||
->method('findMatches') | ||
->with($this->equalTo($term)) | ||
->will($this->returnValue($result)); | ||
|
||
$response = $this->controller->index($term); | ||
|
||
$this->assertEquals($result, $response); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
/** | ||
* ownCloud - Mail | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* @copyright Christoph Wurst 2016 | ||
*/ | ||
|
||
namespace OCA\Mail\Tests\Service\Autocompletion; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use OCA\Mail\Db\CollectedAddress; | ||
use OCA\Mail\Service\AutoCompletion\AddressCollector; | ||
|
||
class AddressCollectorTest extends PHPUnit_Framework_TestCase { | ||
|
||
private $mapper; | ||
private $userId = 'testuser'; | ||
private $logger; | ||
private $collector; | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->mapper = $this->getMockBuilder('\OCA\Mail\Db\CollectedAddressMapper') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->logger = $this->getMockBuilder('\OCA\Mail\Service\Logger') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->collector = new AddressCollector($this->mapper, $this->userId, | ||
$this->logger); | ||
} | ||
|
||
public function testAddAddresses() { | ||
$addresses = [ | ||
'user@example.com', | ||
'example@user.com', | ||
]; | ||
$data = array_map(function($address) { | ||
$ca = new CollectedAddress(); | ||
$ca->setEmail($address); | ||
$ca->setUserId($this->userId); | ||
return $ca; | ||
}, $addresses); | ||
|
||
$this->mapper->expects($this->at(0)) | ||
->method('exists') | ||
->with($this->userId, $addresses[0]) | ||
->will($this->returnValue(false)); | ||
$this->mapper->expects($this->at(1)) | ||
->method('insert') | ||
->with($data[0]); | ||
$this->mapper->expects($this->at(2)) | ||
->method('exists') | ||
->with($this->userId, $addresses[1]) | ||
->will($this->returnValue(false)); | ||
$this->mapper->expects($this->at(3)) | ||
->method('insert') | ||
->with($data[1]); | ||
|
||
$this->collector->addAddresses($addresses); | ||
} | ||
|
||
public function testAddDuplicateAddresses() { | ||
$addresses = [ | ||
'user@example.com', | ||
]; | ||
$data = array_map(function($address) { | ||
$ca = new CollectedAddress(); | ||
$ca->setEmail($address); | ||
$ca->setUserId($this->userId); | ||
return $ca; | ||
}, $addresses); | ||
|
||
$this->mapper->expects($this->at(0)) | ||
->method('exists') | ||
->with($this->userId, $addresses[0]) | ||
->will($this->returnValue(true)); | ||
$this->mapper->expects($this->never()) | ||
->method('insert'); | ||
|
||
$this->collector->addAddresses($addresses); | ||
} | ||
|
||
public function testSearchAddress() { | ||
$term = 'john'; | ||
$mapperResult = ['some', 'data']; | ||
|
||
$this->mapper->expects($this->once()) | ||
->method('findMatching') | ||
->with($this->userId, $term) | ||
->will($this->returnValue($mapperResult)); | ||
|
||
$result = $this->collector->searchAddress($term); | ||
|
||
$this->assertequals($mapperResult, $result); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/** | ||
* ownCloud - Mail | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* @copyright Christoph Wurst 2016 | ||
*/ | ||
|
||
namespace OCA\Mail\Tests\Service\Autocompletion; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use OCA\Mail\Service\AutoCompletion\AutoCompleteService; | ||
|
||
class AutoCompleteServiceTest extends PHPUnit_Framework_TestCase { | ||
|
||
private $contactsIntegration; | ||
private $addressCollector; | ||
private $service; | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->contactsIntegration = $this->getMockBuilder('\OCA\Mail\Service\ContactsIntegration') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->addressCollector = $this->getMockBuilder('\OCA\Mail\Service\AutoCompletion\AddressCollector') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->service = new AutoCompleteService($this->contactsIntegration, | ||
$this->addressCollector); | ||
} | ||
|
||
public function testFindMatches() { | ||
$term = 'jo'; | ||
|
||
$contactsResult = [ | ||
['id' => 12, 'label' => 'john doe', 'value' => 'john doe'], | ||
['id' => 13, 'label' => 'joe doe', 'value' => 'joe doe'], | ||
]; | ||
$john = new \OCA\Mail\Db\CollectedAddress(); | ||
$john->setId(1234); | ||
$john->setEmail('john@doe.com'); | ||
$john->setUserId('testuser'); | ||
$collectedResult = [ | ||
$john, | ||
]; | ||
|
||
$this->contactsIntegration->expects($this->once()) | ||
->method('getMatchingRecipient') | ||
->with($term) | ||
->will($this->returnValue($contactsResult)); | ||
$this->addressCollector->expects($this->once()) | ||
->method('searchAddress') | ||
->with($term) | ||
->will($this->returnValue($collectedResult)); | ||
|
||
$response = $this->service->findMatches($term); | ||
|
||
$expected = [ | ||
['id' => 12, 'label' => 'john doe', 'value' => 'john doe'], | ||
['id' => 13, 'label' => 'joe doe', 'value' => 'joe doe'], | ||
['id' => 1234, 'label' => 'john@doe.com', 'value' => 'john@doe.com'], | ||
]; | ||
$this->assertEquals($expected, $response); | ||
} | ||
|
||
} |