SystemPrincipalBackendTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Citharel <nextcloud@tcit.fr>
  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\DAV\Tests\unit\DAV;
  27. use OCA\DAV\DAV\SystemPrincipalBackend;
  28. use Test\TestCase;
  29. class SystemPrincipalBackendTest extends TestCase {
  30. /**
  31. * @dataProvider providesPrefix
  32. * @param $expected
  33. * @param $prefix
  34. */
  35. public function testGetPrincipalsByPrefix($expected, $prefix) {
  36. $backend = new SystemPrincipalBackend();
  37. $result = $backend->getPrincipalsByPrefix($prefix);
  38. $this->assertEquals($expected, $result);
  39. }
  40. public function providesPrefix() {
  41. return [
  42. [[], ''],
  43. [[[
  44. 'uri' => 'principals/system/system',
  45. '{DAV:}displayname' => 'system',
  46. ],
  47. [
  48. 'uri' => 'principals/system/public',
  49. '{DAV:}displayname' => 'public',
  50. ]
  51. ], 'principals/system'],
  52. ];
  53. }
  54. /**
  55. * @dataProvider providesPath
  56. * @param $expected
  57. * @param $path
  58. */
  59. public function testGetPrincipalByPath($expected, $path) {
  60. $backend = new SystemPrincipalBackend();
  61. $result = $backend->getPrincipalByPath($path);
  62. $this->assertEquals($expected, $result);
  63. }
  64. public function providesPath() {
  65. return [
  66. [null, ''],
  67. [null, 'principals'],
  68. [null, 'principals/system'],
  69. [[
  70. 'uri' => 'principals/system/system',
  71. '{DAV:}displayname' => 'system',
  72. ], 'principals/system/system'],
  73. ];
  74. }
  75. /**
  76. * @dataProvider providesPrincipalForGetGroupMemberSet
  77. *
  78. * @param string $principal
  79. * @throws \Sabre\DAV\Exception
  80. */
  81. public function testGetGroupMemberSetExceptional($principal) {
  82. $this->expectException(\Sabre\DAV\Exception::class);
  83. $this->expectExceptionMessage('Principal not found');
  84. $backend = new SystemPrincipalBackend();
  85. $backend->getGroupMemberSet($principal);
  86. }
  87. public function providesPrincipalForGetGroupMemberSet() {
  88. return [
  89. [null],
  90. ['principals/system'],
  91. ];
  92. }
  93. /**
  94. * @throws \Sabre\DAV\Exception
  95. */
  96. public function testGetGroupMemberSet() {
  97. $backend = new SystemPrincipalBackend();
  98. $result = $backend->getGroupMemberSet('principals/system/system');
  99. $this->assertEquals(['principals/system/system'], $result);
  100. }
  101. /**
  102. * @dataProvider providesPrincipalForGetGroupMembership
  103. *
  104. * @param string $principal
  105. * @throws \Sabre\DAV\Exception
  106. */
  107. public function testGetGroupMembershipExceptional($principal) {
  108. $this->expectException(\Sabre\DAV\Exception::class);
  109. $this->expectExceptionMessage('Principal not found');
  110. $backend = new SystemPrincipalBackend();
  111. $backend->getGroupMembership($principal);
  112. }
  113. public function providesPrincipalForGetGroupMembership() {
  114. return [
  115. ['principals/system/a'],
  116. ];
  117. }
  118. /**
  119. * @throws \Sabre\DAV\Exception
  120. */
  121. public function testGetGroupMembership() {
  122. $backend = new SystemPrincipalBackend();
  123. $result = $backend->getGroupMembership('principals/system/system');
  124. $this->assertEquals([], $result);
  125. }
  126. }