mapper.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Thomas Müller
  6. * @copyright 2013 Thomas Müller thomas.mueller@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. */
  22. namespace Test\Files;
  23. class Mapper extends \Test\TestCase {
  24. /**
  25. * @var \OC\Files\Mapper
  26. */
  27. private $mapper = null;
  28. protected function setUp() {
  29. parent::setUp();
  30. $this->mapper = new \OC\Files\Mapper('D:/');
  31. }
  32. public function slugifyPathData() {
  33. return array(
  34. // with extension
  35. array('D:/text.txt', 'D:/text.txt'),
  36. array('D:/text-2.txt', 'D:/text.txt', 2),
  37. array('D:/a/b/text.txt', 'D:/a/b/text.txt'),
  38. // without extension
  39. array('D:/text', 'D:/text'),
  40. array('D:/text-2', 'D:/text', 2),
  41. array('D:/a/b/text', 'D:/a/b/text'),
  42. // with double dot
  43. array('D:/text.text.txt', 'D:/text.text.txt'),
  44. array('D:/text.text-2.txt', 'D:/text.text.txt', 2),
  45. array('D:/a/b/text.text.txt', 'D:/a/b/text.text.txt'),
  46. // foldername and filename with periods
  47. array('D:/folder.name.with.periods', 'D:/folder.name.with.periods'),
  48. array('D:/folder.name.with.periods/test-2.txt', 'D:/folder.name.with.periods/test.txt', 2),
  49. array('D:/folder.name.with.periods/test.txt', 'D:/folder.name.with.periods/test.txt'),
  50. // foldername and filename with periods and spaces
  51. array('D:/folder.name.with.peri-ods', 'D:/folder.name.with.peri ods'),
  52. array('D:/folder.name.with.peri-ods/te-st-2.t-x-t', 'D:/folder.name.with.peri ods/te st.t x t', 2),
  53. array('D:/folder.name.with.peri-ods/te-st.t-x-t', 'D:/folder.name.with.peri ods/te st.t x t'),
  54. /**
  55. * If a foldername is empty, after we stripped out some unicode and other characters,
  56. * the resulting name must be reproducable otherwise uploading a file into that folder
  57. * will not write the file into the same folder.
  58. */
  59. array('D:/' . md5('ありがとう'), 'D:/ありがとう'),
  60. array('D:/' . md5('ありがとう') . '/issue6722.txt', 'D:/ありがとう/issue6722.txt'),
  61. array('D:/' . md5('.htaccess'), 'D:/.htaccess'),
  62. array('D:/' . md5('.htaccess.'), 'D:/.htaccess.'),
  63. array('D:/' . md5('.htAccess'), 'D:/.htAccess'),
  64. array('D:/' . md5('.htAccess\\…\\') . '/a', 'D:/.htAccess\…\/とa'),
  65. array('D:/' . md5('.htaccess-'), 'D:/.htaccess-'),
  66. array('D:/' . md5('.htaあccess'), 'D:/.htaあccess'),
  67. array('D:/' . md5(' .htaccess'), 'D:/ .htaccess'),
  68. array('D:/' . md5('.htaccess '), 'D:/.htaccess '),
  69. array('D:/' . md5(' .htaccess '), 'D:/ .htaccess '),
  70. );
  71. }
  72. /**
  73. * @dataProvider slugifyPathData
  74. */
  75. public function testSlugifyPath($slug, $path, $index = null) {
  76. $this->assertEquals($slug, $this->mapper->slugifyPath($path, $index));
  77. }
  78. }