1
0

SyncFederationAddressbooksTest.php 3.0 KB

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