HelperTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Bjoern Schiessle
  6. * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. namespace Test\Share;
  22. /**
  23. * @group DB
  24. * Class Helper
  25. */
  26. class HelperTest extends \Test\TestCase {
  27. public function expireDateProvider() {
  28. return [
  29. // no default expire date, we take the users expire date
  30. [['defaultExpireDateSet' => false], 2000000000, 2000010000, 2000010000],
  31. // no default expire date and no user defined expire date, return false
  32. [['defaultExpireDateSet' => false], 2000000000, null, false],
  33. // unenforced expire data and no user defined expire date, return false (because the default is not enforced)
  34. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false], 2000000000, null, false],
  35. // enforced expire date and no user defined expire date, take default expire date
  36. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true], 2000000000, null, 2000086400],
  37. // unenforced expire date and user defined date > default expire date, take users expire date
  38. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false], 2000000000, 2000100000, 2000100000],
  39. // unenforced expire date and user expire date < default expire date, take users expire date
  40. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false], 2000000000, 2000010000, 2000010000],
  41. // enforced expire date and user expire date < default expire date, take users expire date
  42. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true], 2000000000, 2000010000, 2000010000],
  43. // enforced expire date and users expire date > default expire date, take default expire date
  44. [['defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true], 2000000000, 2000100000, 2000086400],
  45. ];
  46. }
  47. /**
  48. * @dataProvider expireDateProvider
  49. */
  50. public function testCalculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate, $expected) {
  51. $result = \OC\Share\Helper::calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate);
  52. $this->assertSame($expected, $result);
  53. }
  54. /**
  55. * @dataProvider dataTestCompareServerAddresses
  56. *
  57. * @param string $server1
  58. * @param string $server2
  59. * @param bool $expected
  60. */
  61. public function testIsSameUserOnSameServer($user1, $server1, $user2, $server2, $expected) {
  62. $this->assertSame($expected,
  63. \OC\Share\Helper::isSameUserOnSameServer($user1, $server1, $user2, $server2)
  64. );
  65. }
  66. public function dataTestCompareServerAddresses() {
  67. return [
  68. ['user1', 'http://server1', 'user1', 'http://server1', true],
  69. ['user1', 'https://server1', 'user1', 'http://server1', true],
  70. ['user1', 'http://serVer1', 'user1', 'http://server1', true],
  71. ['user1', 'http://server1/', 'user1', 'http://server1', true],
  72. ['user1', 'server1', 'user1', 'http://server1', true],
  73. ['user1', 'http://server1', 'user1', 'http://server2', false],
  74. ['user1', 'https://server1', 'user1', 'http://server2', false],
  75. ['user1', 'http://serVer1', 'user1', 'http://serer2', false],
  76. ['user1', 'http://server1/', 'user1', 'http://server2', false],
  77. ['user1', 'server1', 'user1', 'http://server2', false],
  78. ['user1', 'http://server1', 'user2', 'http://server1', false],
  79. ['user1', 'https://server1', 'user2', 'http://server1', false],
  80. ['user1', 'http://serVer1', 'user2', 'http://server1', false],
  81. ['user1', 'http://server1/', 'user2', 'http://server1', false],
  82. ['user1', 'server1', 'user2', 'http://server1', false],
  83. ];
  84. }
  85. }