You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.8 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Thomas Müller <thomas.mueller@tmit.eu>
  6. *
  7. * @copyright Copyright (c) 2016, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Federation\Tests\lib;
  24. use OCA\Federation\DbHandler;
  25. use OCA\Federation\SyncFederationAddressBooks;
  26. class SyncFederationAddressbooksTest extends \Test\TestCase {
  27. /** @var array */
  28. private $callBacks = [];
  29. function testSync() {
  30. /** @var DbHandler | \PHPUnit_Framework_MockObject_MockObject $dbHandler */
  31. $dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')->
  32. disableOriginalConstructor()->
  33. getMock();
  34. $dbHandler->method('getAllServer')->
  35. willReturn([
  36. [
  37. 'url' => 'https://cloud.drop.box',
  38. 'url_hash' => 'sha1',
  39. 'shared_secret' => 'iloveowncloud',
  40. 'sync_token' => '0'
  41. ]
  42. ]);
  43. $dbHandler->expects($this->once())->method('setServerStatus')->
  44. with('https://cloud.drop.box', 1, '1');
  45. $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
  46. ->disableOriginalConstructor()
  47. ->getMock();
  48. $syncService->expects($this->once())->method('syncRemoteAddressBook')
  49. ->willReturn(1);
  50. $s = new SyncFederationAddressBooks($dbHandler, $syncService);
  51. $s->syncThemAll(function($url, $ex) {
  52. $this->callBacks[] = [$url, $ex];
  53. });
  54. $this->assertEquals(1, count($this->callBacks));
  55. }
  56. function testException() {
  57. /** @var DbHandler | \PHPUnit_Framework_MockObject_MockObject $dbHandler */
  58. $dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')->
  59. disableOriginalConstructor()->
  60. getMock();
  61. $dbHandler->method('getAllServer')->
  62. willReturn([
  63. [
  64. 'url' => 'https://cloud.drop.box',
  65. 'url_hash' => 'sha1',
  66. 'shared_secret' => 'iloveowncloud',
  67. 'sync_token' => '0'
  68. ]
  69. ]);
  70. $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
  71. ->disableOriginalConstructor()
  72. ->getMock();
  73. $syncService->expects($this->once())->method('syncRemoteAddressBook')
  74. ->willThrowException(new \Exception('something did not work out'));
  75. $s = new SyncFederationAddressBooks($dbHandler, $syncService);
  76. $s->syncThemAll(function($url, $ex) {
  77. $this->callBacks[] = [$url, $ex];
  78. });
  79. $this->assertEquals(2, count($this->callBacks));
  80. }
  81. }