1
0

HelperTest.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Share;
  8. /**
  9. * @group DB
  10. * Class Helper
  11. */
  12. class HelperTest extends \Test\TestCase {
  13. public function expireDateProvider() {
  14. return [
  15. // no default expire date, we take the users expire date
  16. [['defaultExpireDateSet' => false], 2000000000, 2000010000, 2000010000],
  17. // no default expire date and no user defined expire date, return false
  18. [['defaultExpireDateSet' => false], 2000000000, null, false],
  19. // unenforced expire data and no user defined expire date, return false (because the default is not enforced)
  20. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false], 2000000000, null, false],
  21. // enforced expire date and no user defined expire date, take default expire date
  22. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true], 2000000000, null, 2000086400],
  23. // unenforced expire date and user defined date > default expire date, take users expire date
  24. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false], 2000000000, 2000100000, 2000100000],
  25. // unenforced expire date and user expire date < default expire date, take users expire date
  26. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false], 2000000000, 2000010000, 2000010000],
  27. // enforced expire date and user expire date < default expire date, take users expire date
  28. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true], 2000000000, 2000010000, 2000010000],
  29. // enforced expire date and users expire date > default expire date, take default expire date
  30. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true], 2000000000, 2000100000, 2000086400],
  31. ];
  32. }
  33. /**
  34. * @dataProvider expireDateProvider
  35. */
  36. public function testCalculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate, $expected) {
  37. $result = \OC\Share\Helper::calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate);
  38. $this->assertSame($expected, $result);
  39. }
  40. /**
  41. * @dataProvider dataTestCompareServerAddresses
  42. *
  43. * @param string $server1
  44. * @param string $server2
  45. * @param bool $expected
  46. */
  47. public function testIsSameUserOnSameServer($user1, $server1, $user2, $server2, $expected) {
  48. $this->assertSame($expected,
  49. \OC\Share\Helper::isSameUserOnSameServer($user1, $server1, $user2, $server2)
  50. );
  51. }
  52. public function dataTestCompareServerAddresses() {
  53. return [
  54. ['user1', 'http://server1', 'user1', 'http://server1', true],
  55. ['user1', 'https://server1', 'user1', 'http://server1', true],
  56. ['user1', 'http://serVer1', 'user1', 'http://server1', true],
  57. ['user1', 'http://server1/', 'user1', 'http://server1', true],
  58. ['user1', 'server1', 'user1', 'http://server1', true],
  59. ['user1', 'http://server1', 'user1', 'http://server2', false],
  60. ['user1', 'https://server1', 'user1', 'http://server2', false],
  61. ['user1', 'http://serVer1', 'user1', 'http://serer2', false],
  62. ['user1', 'http://server1/', 'user1', 'http://server2', false],
  63. ['user1', 'server1', 'user1', 'http://server2', false],
  64. ['user1', 'http://server1', 'user2', 'http://server1', false],
  65. ['user1', 'https://server1', 'user2', 'http://server1', false],
  66. ['user1', 'http://serVer1', 'user2', 'http://server1', false],
  67. ['user1', 'http://server1/', 'user2', 'http://server1', false],
  68. ['user1', 'server1', 'user2', 'http://server1', false],
  69. ];
  70. }
  71. }