request.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
  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_Request extends PHPUnit_Framework_TestCase {
  9. public function setUp() {
  10. OC_Config::setValue('overwritewebroot', '/domain.tld/ownCloud');
  11. }
  12. public function tearDown() {
  13. OC_Config::setValue('overwritewebroot', '');
  14. }
  15. public function testScriptNameOverWrite() {
  16. $_SERVER['REMOTE_ADDR'] = '10.0.0.1';
  17. $_SERVER["SCRIPT_FILENAME"] = __FILE__;
  18. $scriptName = OC_Request::scriptName();
  19. $this->assertEquals('/domain.tld/ownCloud/tests/lib/request.php', $scriptName);
  20. }
  21. /**
  22. * @dataProvider rawPathInfoProvider
  23. * @param $expected
  24. * @param $requestUri
  25. * @param $scriptName
  26. */
  27. public function testRawPathInfo($expected, $requestUri, $scriptName) {
  28. $_SERVER['REQUEST_URI'] = $requestUri;
  29. $_SERVER['SCRIPT_NAME'] = $scriptName;
  30. $rawPathInfo = OC_Request::getRawPathInfo();
  31. $this->assertEquals($expected, $rawPathInfo);
  32. }
  33. function rawPathInfoProvider() {
  34. return array(
  35. array('/core/ajax/translations.php', 'index.php/core/ajax/translations.php', 'index.php'),
  36. array('/core/ajax/translations.php', '/index.php/core/ajax/translations.php', '/index.php'),
  37. array('/core/ajax/translations.php', '//index.php/core/ajax/translations.php', '/index.php'),
  38. array('', '/oc/core', '/oc/core/index.php'),
  39. array('', '/oc/core/', '/oc/core/index.php'),
  40. array('', '/oc/core/index.php', '/oc/core/index.php'),
  41. array('/core/ajax/translations.php', '/core/ajax/translations.php', 'index.php'),
  42. array('/core/ajax/translations.php', '//core/ajax/translations.php', '/index.php'),
  43. array('/core/ajax/translations.php', '/oc/core/ajax/translations.php', '/oc/index.php'),
  44. array('/1', '/oc/core/1', '/oc/core/index.php'),
  45. );
  46. }
  47. /**
  48. * @dataProvider rawPathInfoThrowsExceptionProvider
  49. * @expectedException Exception
  50. *
  51. * @param $requestUri
  52. * @param $scriptName
  53. */
  54. public function testRawPathInfoThrowsException($requestUri, $scriptName) {
  55. $_SERVER['REQUEST_URI'] = $requestUri;
  56. $_SERVER['SCRIPT_NAME'] = $scriptName;
  57. OC_Request::getRawPathInfo();
  58. }
  59. function rawPathInfoThrowsExceptionProvider() {
  60. return array(
  61. array('/oc/core1', '/oc/core/index.php'),
  62. );
  63. }
  64. }