You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

urlgenerator.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 \Test\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. /**
  34. * @dataProvider provideRoutes
  35. */
  36. public function testLinkToRouteAbsolute($route, $expected) {
  37. \OC::$WEBROOT = '/owncloud';
  38. $config = $this->getMock('\OCP\IConfig');
  39. $urlGenerator = new \OC\URLGenerator($config);
  40. $result = $urlGenerator->linkToRouteAbsolute($route);
  41. $this->assertEquals($expected, $result);
  42. }
  43. public function provideRoutes() {
  44. return array(
  45. array('files_index', 'http://localhost/owncloud/index.php/apps/files/'),
  46. array('core_ajax_preview', 'http://localhost/owncloud/index.php/core/preview.png'),
  47. );
  48. }
  49. public function provideDocRootAppUrlParts() {
  50. return array(
  51. array('files', 'index.php', array(), '/index.php/apps/files'),
  52. array('files', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php/apps/files?trut=trat&dut=dat'),
  53. array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php?trut=trat&dut=dat'),
  54. );
  55. }
  56. public function provideSubDirAppUrlParts() {
  57. return array(
  58. array('files', 'index.php', array(), '/owncloud/index.php/apps/files'),
  59. array('files', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php/apps/files?trut=trat&dut=dat'),
  60. array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php?trut=trat&dut=dat'),
  61. );
  62. }
  63. /**
  64. * @small
  65. * test absolute URL construction
  66. * @dataProvider provideDocRootURLs
  67. */
  68. function testGetAbsoluteURLDocRoot($url, $expectedResult) {
  69. \OC::$WEBROOT = '';
  70. $urlGenerator = new \OC\URLGenerator(null);
  71. $result = $urlGenerator->getAbsoluteURL($url);
  72. $this->assertEquals($expectedResult, $result);
  73. }
  74. /**
  75. * @small
  76. * test absolute URL construction
  77. * @dataProvider provideSubDirURLs
  78. */
  79. function testGetAbsoluteURLSubDir($url, $expectedResult) {
  80. \OC::$WEBROOT = '/owncloud';
  81. $urlGenerator = new \OC\URLGenerator(null);
  82. $result = $urlGenerator->getAbsoluteURL($url);
  83. $this->assertEquals($expectedResult, $result);
  84. }
  85. public function provideDocRootURLs() {
  86. return array(
  87. array("index.php", "http://localhost/index.php"),
  88. array("/index.php", "http://localhost/index.php"),
  89. array("/apps/index.php", "http://localhost/apps/index.php"),
  90. array("apps/index.php", "http://localhost/apps/index.php"),
  91. );
  92. }
  93. public function provideSubDirURLs() {
  94. return array(
  95. array("index.php", "http://localhost/owncloud/index.php"),
  96. array("/index.php", "http://localhost/owncloud/index.php"),
  97. array("/apps/index.php", "http://localhost/owncloud/apps/index.php"),
  98. array("apps/index.php", "http://localhost/owncloud/apps/index.php"),
  99. );
  100. }
  101. }