urlgenerator.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Bjoern Schiessle <schiessle@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. class Test_Urlgenerator extends PHPUnit_Framework_TestCase {
  9. /**
  10. * @small
  11. * test linkTo URL construction
  12. * @dataProvider provideDocRootAppUrlParts
  13. */
  14. public function testLinkToDocRoot($app, $file, $args, $expectedResult) {
  15. \OC::$WEBROOT = '';
  16. $config = $this->getMock('\OCP\IConfig');
  17. $urlGenerator = new \OC\URLGenerator($config);
  18. $result = $urlGenerator->linkTo($app, $file, $args);
  19. $this->assertEquals($expectedResult, $result);
  20. }
  21. /**
  22. * @small
  23. * test linkTo URL construction in sub directory
  24. * @dataProvider provideSubDirAppUrlParts
  25. */
  26. public function testLinkToSubDir($app, $file, $args, $expectedResult) {
  27. \OC::$WEBROOT = '/owncloud';
  28. $config = $this->getMock('\OCP\IConfig');
  29. $urlGenerator = new \OC\URLGenerator($config);
  30. $result = $urlGenerator->linkTo($app, $file, $args);
  31. $this->assertEquals($expectedResult, $result);
  32. }
  33. public function provideDocRootAppUrlParts() {
  34. return array(
  35. array('files', 'index.php', array(), '/index.php/apps/files'),
  36. array('files', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php/apps/files?trut=trat&dut=dat'),
  37. array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php?trut=trat&dut=dat'),
  38. );
  39. }
  40. public function provideSubDirAppUrlParts() {
  41. return array(
  42. array('files', 'index.php', array(), '/owncloud/index.php/apps/files'),
  43. array('files', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php/apps/files?trut=trat&dut=dat'),
  44. array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php?trut=trat&dut=dat'),
  45. );
  46. }
  47. /**
  48. * @small
  49. * test absolute URL construction
  50. * @dataProvider provideDocRootURLs
  51. */
  52. function testGetAbsoluteURLDocRoot($url, $expectedResult) {
  53. \OC::$WEBROOT = '';
  54. $urlGenerator = new \OC\URLGenerator(null);
  55. $result = $urlGenerator->getAbsoluteURL($url);
  56. $this->assertEquals($expectedResult, $result);
  57. }
  58. /**
  59. * @small
  60. * test absolute URL construction
  61. * @dataProvider provideSubDirURLs
  62. */
  63. function testGetAbsoluteURLSubDir($url, $expectedResult) {
  64. \OC::$WEBROOT = '/owncloud';
  65. $urlGenerator = new \OC\URLGenerator(null);
  66. $result = $urlGenerator->getAbsoluteURL($url);
  67. $this->assertEquals($expectedResult, $result);
  68. }
  69. public function provideDocRootURLs() {
  70. return array(
  71. array("index.php", "http://localhost/index.php"),
  72. array("/index.php", "http://localhost/index.php"),
  73. array("/apps/index.php", "http://localhost/apps/index.php"),
  74. array("apps/index.php", "http://localhost/apps/index.php"),
  75. );
  76. }
  77. public function provideSubDirURLs() {
  78. return array(
  79. array("index.php", "http://localhost/owncloud/index.php"),
  80. array("/index.php", "http://localhost/owncloud/index.php"),
  81. array("/apps/index.php", "http://localhost/owncloud/apps/index.php"),
  82. array("apps/index.php", "http://localhost/owncloud/apps/index.php"),
  83. );
  84. }
  85. }