mapper.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 \PHPUnit_Framework_TestCase {
  24. /**
  25. * @var \OC\Files\Mapper
  26. */
  27. private $mapper = null;
  28. public function setUp() {
  29. $this->mapper = new \OC\Files\Mapper('D:/');
  30. }
  31. public function testSlugifyPath() {
  32. // with extension
  33. $this->assertEquals('D:/text.txt', $this->mapper->slugifyPath('D:/text.txt'));
  34. $this->assertEquals('D:/text-2.txt', $this->mapper->slugifyPath('D:/text.txt', 2));
  35. $this->assertEquals('D:/a/b/text.txt', $this->mapper->slugifyPath('D:/a/b/text.txt'));
  36. // without extension
  37. $this->assertEquals('D:/text', $this->mapper->slugifyPath('D:/text'));
  38. $this->assertEquals('D:/text-2', $this->mapper->slugifyPath('D:/text', 2));
  39. $this->assertEquals('D:/a/b/text', $this->mapper->slugifyPath('D:/a/b/text'));
  40. // with double dot
  41. $this->assertEquals('D:/text.text.txt', $this->mapper->slugifyPath('D:/text.text.txt'));
  42. $this->assertEquals('D:/text.text-2.txt', $this->mapper->slugifyPath('D:/text.text.txt', 2));
  43. $this->assertEquals('D:/a/b/text.text.txt', $this->mapper->slugifyPath('D:/a/b/text.text.txt'));
  44. // foldername and filename with periods
  45. $this->assertEquals('D:/folder.name.with.periods', $this->mapper->slugifyPath('D:/folder.name.with.periods'));
  46. $this->assertEquals('D:/folder.name.with.periods/test-2.txt', $this->mapper->slugifyPath('D:/folder.name.with.periods/test.txt', 2));
  47. $this->assertEquals('D:/folder.name.with.periods/test.txt', $this->mapper->slugifyPath('D:/folder.name.with.periods/test.txt'));
  48. // foldername and filename with periods and spaces
  49. $this->assertEquals('D:/folder.name.with.peri-ods', $this->mapper->slugifyPath('D:/folder.name.with.peri ods'));
  50. $this->assertEquals('D:/folder.name.with.peri-ods/te-st-2.t-x-t', $this->mapper->slugifyPath('D:/folder.name.with.peri ods/te st.t x t', 2));
  51. $this->assertEquals('D:/folder.name.with.peri-ods/te-st.t-x-t', $this->mapper->slugifyPath('D:/folder.name.with.peri ods/te st.t x t'));
  52. }
  53. }