HooksTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. }