sharingcheckmiddleware.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @copyright Copyright (c) 2015, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_Sharing\Middleware;
  25. /**
  26. * @package OCA\Files_Sharing\Middleware\SharingCheckMiddleware
  27. */
  28. class SharingCheckMiddlewareTest extends \Test\TestCase {
  29. /** @var \OCP\IConfig */
  30. private $config;
  31. /** @var \OCP\App\IAppManager */
  32. private $appManager;
  33. /** @var SharingCheckMiddleware */
  34. private $sharingCheckMiddleware;
  35. protected function setUp() {
  36. $this->config = $this->getMockBuilder('\OCP\IConfig')
  37. ->disableOriginalConstructor()->getMock();
  38. $this->appManager = $this->getMockBuilder('\OCP\App\IAppManager')
  39. ->disableOriginalConstructor()->getMock();
  40. $this->sharingCheckMiddleware = new SharingCheckMiddleware('files_sharing', $this->config, $this->appManager);
  41. }
  42. public function testIsSharingEnabledWithEverythingEnabled() {
  43. $this->appManager
  44. ->expects($this->once())
  45. ->method('isEnabledForUser')
  46. ->with('files_sharing')
  47. ->will($this->returnValue(true));
  48. $this->config
  49. ->expects($this->once())
  50. ->method('getAppValue')
  51. ->with('core', 'shareapi_allow_links', 'yes')
  52. ->will($this->returnValue('yes'));
  53. $this->assertTrue(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
  54. }
  55. public function testIsSharingEnabledWithAppDisabled() {
  56. $this->appManager
  57. ->expects($this->once())
  58. ->method('isEnabledForUser')
  59. ->with('files_sharing')
  60. ->will($this->returnValue(false));
  61. $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
  62. }
  63. public function testIsSharingEnabledWithSharingDisabled() {
  64. $this->appManager
  65. ->expects($this->once())
  66. ->method('isEnabledForUser')
  67. ->with('files_sharing')
  68. ->will($this->returnValue(true));
  69. $this->config
  70. ->expects($this->once())
  71. ->method('getAppValue')
  72. ->with('core', 'shareapi_allow_links', 'yes')
  73. ->will($this->returnValue('no'));
  74. $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
  75. }
  76. }