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.

HooksTest.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. *
  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;
  24. use OCA\Federation\Hooks;
  25. use OCA\Federation\TrustedServers;
  26. use Test\TestCase;
  27. class HooksTest extends TestCase {
  28. /** @var \PHPUnit_Framework_MockObject_MockObject | TrustedServers */
  29. private $trustedServers;
  30. /** @var Hooks */
  31. private $hooks;
  32. public function setUp() {
  33. parent::setUp();
  34. $this->trustedServers = $this->getMockBuilder('OCA\Federation\TrustedServers')
  35. ->disableOriginalConstructor()->getMock();
  36. $this->hooks = new Hooks($this->trustedServers);
  37. }
  38. /**
  39. * @dataProvider dataTestAddServerHook
  40. *
  41. * @param bool $autoAddEnabled is auto-add enabled
  42. * @param bool $isTrustedServer is the server already in the list of trusted servers
  43. * @param bool $addServer should the server be added
  44. */
  45. public function testAddServerHook($autoAddEnabled, $isTrustedServer, $addServer) {
  46. $this->trustedServers->expects($this->any())->method('getAutoAddServers')
  47. ->willReturn($autoAddEnabled);
  48. $this->trustedServers->expects($this->any())->method('isTrustedServer')
  49. ->with('url')->willReturn($isTrustedServer);
  50. if ($addServer) {
  51. $this->trustedServers->expects($this->once())->method('addServer')
  52. ->with('url');
  53. } else {
  54. $this->trustedServers->expects($this->never())->method('addServer');
  55. }
  56. $this->hooks->addServerHook(['server' => 'url']);
  57. }
  58. public function dataTestAddServerHook() {
  59. return [
  60. [true, true, false],
  61. [false, true, false],
  62. [true, false, true],
  63. [false, false, false],
  64. ];
  65. }
  66. }