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.

UrlGeneratorTest.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. namespace Test;
  9. /**
  10. * Class UrlGeneratorTest
  11. *
  12. * @group DB
  13. */
  14. class UrlGeneratorTest extends \Test\TestCase {
  15. /**
  16. * @small
  17. * test linkTo URL construction
  18. * @dataProvider provideDocRootAppUrlParts
  19. */
  20. public function testLinkToDocRoot($app, $file, $args, $expectedResult) {
  21. \OC::$WEBROOT = '';
  22. $config = $this->getMock('\OCP\IConfig');
  23. $cacheFactory = $this->getMock('\OCP\ICacheFactory');
  24. $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
  25. $result = $urlGenerator->linkTo($app, $file, $args);
  26. $this->assertEquals($expectedResult, $result);
  27. }
  28. /**
  29. * @small
  30. * test linkTo URL construction in sub directory
  31. * @dataProvider provideSubDirAppUrlParts
  32. */
  33. public function testLinkToSubDir($app, $file, $args, $expectedResult) {
  34. \OC::$WEBROOT = '/owncloud';
  35. $config = $this->getMock('\OCP\IConfig');
  36. $cacheFactory = $this->getMock('\OCP\ICacheFactory');
  37. $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
  38. $result = $urlGenerator->linkTo($app, $file, $args);
  39. $this->assertEquals($expectedResult, $result);
  40. }
  41. /**
  42. * @dataProvider provideRoutes
  43. */
  44. public function testLinkToRouteAbsolute($route, $expected) {
  45. \OC::$WEBROOT = '/owncloud';
  46. $config = $this->getMock('\OCP\IConfig');
  47. $cacheFactory = $this->getMock('\OCP\ICacheFactory');
  48. $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
  49. $result = $urlGenerator->linkToRouteAbsolute($route);
  50. $this->assertEquals($expected, $result);
  51. }
  52. public function provideRoutes() {
  53. return array(
  54. array('files_ajax_list', 'http://localhost/owncloud/index.php/apps/files/ajax/list.php'),
  55. array('core_ajax_preview', 'http://localhost/owncloud/index.php/core/preview.png'),
  56. );
  57. }
  58. public function provideDocRootAppUrlParts() {
  59. return array(
  60. array('files', 'ajax/list.php', array(), '/index.php/apps/files/ajax/list.php'),
  61. array('files', 'ajax/list.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'),
  62. array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php?trut=trat&dut=dat'),
  63. );
  64. }
  65. public function provideSubDirAppUrlParts() {
  66. return array(
  67. array('files', 'ajax/list.php', array(), '/owncloud/index.php/apps/files/ajax/list.php'),
  68. array('files', 'ajax/list.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'),
  69. array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php?trut=trat&dut=dat'),
  70. );
  71. }
  72. /**
  73. * @small
  74. * test absolute URL construction
  75. * @dataProvider provideDocRootURLs
  76. */
  77. function testGetAbsoluteURLDocRoot($url, $expectedResult) {
  78. \OC::$WEBROOT = '';
  79. $config = $this->getMock('\OCP\IConfig');
  80. $cacheFactory = $this->getMock('\OCP\ICacheFactory');
  81. $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
  82. $result = $urlGenerator->getAbsoluteURL($url);
  83. $this->assertEquals($expectedResult, $result);
  84. }
  85. /**
  86. * @small
  87. * test absolute URL construction
  88. * @dataProvider provideSubDirURLs
  89. */
  90. function testGetAbsoluteURLSubDir($url, $expectedResult) {
  91. \OC::$WEBROOT = '/owncloud';
  92. $config = $this->getMock('\OCP\IConfig');
  93. $cacheFactory = $this->getMock('\OCP\ICacheFactory');
  94. $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
  95. $result = $urlGenerator->getAbsoluteURL($url);
  96. $this->assertEquals($expectedResult, $result);
  97. }
  98. public function provideDocRootURLs() {
  99. return array(
  100. array("index.php", "http://localhost/index.php"),
  101. array("/index.php", "http://localhost/index.php"),
  102. array("/apps/index.php", "http://localhost/apps/index.php"),
  103. array("apps/index.php", "http://localhost/apps/index.php"),
  104. );
  105. }
  106. public function provideSubDirURLs() {
  107. return array(
  108. array("index.php", "http://localhost/owncloud/index.php"),
  109. array("/index.php", "http://localhost/owncloud/index.php"),
  110. array("/apps/index.php", "http://localhost/owncloud/apps/index.php"),
  111. array("apps/index.php", "http://localhost/owncloud/apps/index.php"),
  112. );
  113. }
  114. }