SystemPrincipalBackendTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Tests\unit\DAV;
  8. use OCA\DAV\DAV\SystemPrincipalBackend;
  9. use Test\TestCase;
  10. class SystemPrincipalBackendTest extends TestCase {
  11. /**
  12. * @dataProvider providesPrefix
  13. * @param $expected
  14. * @param $prefix
  15. */
  16. public function testGetPrincipalsByPrefix($expected, $prefix): void {
  17. $backend = new SystemPrincipalBackend();
  18. $result = $backend->getPrincipalsByPrefix($prefix);
  19. $this->assertEquals($expected, $result);
  20. }
  21. public function providesPrefix() {
  22. return [
  23. [[], ''],
  24. [[[
  25. 'uri' => 'principals/system/system',
  26. '{DAV:}displayname' => 'system',
  27. ],
  28. [
  29. 'uri' => 'principals/system/public',
  30. '{DAV:}displayname' => 'public',
  31. ]
  32. ], 'principals/system'],
  33. ];
  34. }
  35. /**
  36. * @dataProvider providesPath
  37. * @param $expected
  38. * @param $path
  39. */
  40. public function testGetPrincipalByPath($expected, $path): void {
  41. $backend = new SystemPrincipalBackend();
  42. $result = $backend->getPrincipalByPath($path);
  43. $this->assertEquals($expected, $result);
  44. }
  45. public function providesPath() {
  46. return [
  47. [null, ''],
  48. [null, 'principals'],
  49. [null, 'principals/system'],
  50. [[
  51. 'uri' => 'principals/system/system',
  52. '{DAV:}displayname' => 'system',
  53. ], 'principals/system/system'],
  54. ];
  55. }
  56. /**
  57. * @dataProvider providesPrincipalForGetGroupMemberSet
  58. *
  59. * @param string $principal
  60. * @throws \Sabre\DAV\Exception
  61. */
  62. public function testGetGroupMemberSetExceptional($principal): void {
  63. $this->expectException(\Sabre\DAV\Exception::class);
  64. $this->expectExceptionMessage('Principal not found');
  65. $backend = new SystemPrincipalBackend();
  66. $backend->getGroupMemberSet($principal);
  67. }
  68. public function providesPrincipalForGetGroupMemberSet() {
  69. return [
  70. [null],
  71. ['principals/system'],
  72. ];
  73. }
  74. /**
  75. * @throws \Sabre\DAV\Exception
  76. */
  77. public function testGetGroupMemberSet(): void {
  78. $backend = new SystemPrincipalBackend();
  79. $result = $backend->getGroupMemberSet('principals/system/system');
  80. $this->assertEquals(['principals/system/system'], $result);
  81. }
  82. /**
  83. * @dataProvider providesPrincipalForGetGroupMembership
  84. *
  85. * @param string $principal
  86. * @throws \Sabre\DAV\Exception
  87. */
  88. public function testGetGroupMembershipExceptional($principal): void {
  89. $this->expectException(\Sabre\DAV\Exception::class);
  90. $this->expectExceptionMessage('Principal not found');
  91. $backend = new SystemPrincipalBackend();
  92. $backend->getGroupMembership($principal);
  93. }
  94. public function providesPrincipalForGetGroupMembership() {
  95. return [
  96. ['principals/system/a'],
  97. ];
  98. }
  99. /**
  100. * @throws \Sabre\DAV\Exception
  101. */
  102. public function testGetGroupMembership(): void {
  103. $backend = new SystemPrincipalBackend();
  104. $result = $backend->getGroupMembership('principals/system/system');
  105. $this->assertEquals([], $result);
  106. }
  107. }