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.

138 lines
3.9 KiB

12 years ago
12 years ago
  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. /**
  65. * @dataProvider userAgentProvider
  66. */
  67. public function testUserAgent($testAgent, $userAgent, $matches) {
  68. $_SERVER['HTTP_USER_AGENT'] = $testAgent;
  69. $this->assertEquals($matches, OC_Request::isUserAgent($userAgent));
  70. }
  71. function userAgentProvider() {
  72. return array(
  73. array(
  74. 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
  75. OC_Request::USER_AGENT_IE,
  76. true
  77. ),
  78. array(
  79. 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0',
  80. OC_Request::USER_AGENT_IE,
  81. false
  82. ),
  83. array(
  84. 'Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36',
  85. OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
  86. true
  87. ),
  88. array(
  89. 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
  90. OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
  91. false
  92. ),
  93. // test two values
  94. array(
  95. 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
  96. array(
  97. OC_Request::USER_AGENT_IE,
  98. OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
  99. ),
  100. true
  101. ),
  102. array(
  103. 'Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36',
  104. array(
  105. OC_Request::USER_AGENT_IE,
  106. OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
  107. ),
  108. true
  109. ),
  110. array(
  111. 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0',
  112. OC_Request::USER_AGENT_FREEBOX,
  113. false
  114. ),
  115. array(
  116. 'Mozilla/5.0',
  117. OC_Request::USER_AGENT_FREEBOX,
  118. true
  119. ),
  120. array(
  121. 'Fake Mozilla/5.0',
  122. OC_Request::USER_AGENT_FREEBOX,
  123. false
  124. ),
  125. );
  126. }
  127. }