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.

SyncFederationAddressbooksTest.php 3.5KB

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