1
0

helper.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. class Test_Share_Helper extends \Test\TestCase {
  22. public function expireDateProvider() {
  23. return array(
  24. // no default expire date, we take the users expire date
  25. array(array('defaultExpireDateSet' => false), 2000000000, 2000010000, 2000010000),
  26. // no default expire date and no user defined expire date, return false
  27. array(array('defaultExpireDateSet' => false), 2000000000, null, false),
  28. // unenforced expire data and no user defined expire date, return false (because the default is not enforced)
  29. array(array('defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false), 2000000000, null, false),
  30. // enforced expire date and no user defined expire date, take default expire date
  31. array(array('defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true), 2000000000, null, 2000086400),
  32. // unenforced expire date and user defined date > default expire date, take users expire date
  33. array(array('defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false), 2000000000, 2000100000, 2000100000),
  34. // unenforced expire date and user expire date < default expire date, take users expire date
  35. array(array('defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => false), 2000000000, 2000010000, 2000010000),
  36. // enforced expire date and user expire date < default expire date, take users expire date
  37. array(array('defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true), 2000000000, 2000010000, 2000010000),
  38. // enforced expire date and users expire date > default expire date, take default expire date
  39. array(array('defaultExpireDateSet' => true, 'expireAfterDays' => 1, 'enforceExpireDate' => true), 2000000000, 2000100000, 2000086400),
  40. );
  41. }
  42. /**
  43. * @dataProvider expireDateProvider
  44. */
  45. public function testCalculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate, $expected) {
  46. $result = \OC\Share\Helper::calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate);
  47. $this->assertSame($expected, $result);
  48. }
  49. public function fixRemoteURLInShareWithData() {
  50. $userPrefix = ['test@', 'na/me@'];
  51. $protocols = ['', 'http://', 'https://'];
  52. $remotes = [
  53. 'localhost',
  54. 'test:foobar@localhost',
  55. 'local.host',
  56. 'dev.local.host',
  57. 'dev.local.host/path',
  58. '127.0.0.1',
  59. '::1',
  60. '::192.0.2.128',
  61. ];
  62. $testCases = [
  63. ['test', 'test'],
  64. ['na/me', 'na/me'],
  65. ['na/me/', 'na/me'],
  66. ['na/index.php', 'na/index.php'],
  67. ['http://localhost', 'http://localhost'],
  68. ['http://localhost/', 'http://localhost'],
  69. ['http://localhost/index.php', 'http://localhost/index.php'],
  70. ['http://localhost/index.php/s/token', 'http://localhost/index.php/s/token'],
  71. ['http://test:foobar@localhost', 'http://test:foobar@localhost'],
  72. ['http://test:foobar@localhost/', 'http://test:foobar@localhost'],
  73. ['http://test:foobar@localhost/index.php', 'http://test:foobar@localhost'],
  74. ['http://test:foobar@localhost/index.php/s/token', 'http://test:foobar@localhost'],
  75. ];
  76. foreach ($userPrefix as $user) {
  77. foreach ($remotes as $remote) {
  78. foreach ($protocols as $protocol) {
  79. $baseUrl = $user . $protocol . $remote;
  80. $testCases[] = [$baseUrl, $baseUrl];
  81. $testCases[] = [$baseUrl . '/', $baseUrl];
  82. $testCases[] = [$baseUrl . '/index.php', $baseUrl];
  83. $testCases[] = [$baseUrl . '/index.php/s/token', $baseUrl];
  84. }
  85. }
  86. }
  87. return $testCases;
  88. }
  89. /**
  90. * @dataProvider fixRemoteURLInShareWithData
  91. */
  92. public function testFixRemoteURLInShareWith($remote, $expected) {
  93. $this->assertSame($expected, \OC\Share\Helper::fixRemoteURLInShareWith($remote));
  94. }
  95. }