Permalink
Browse files

Merge pull request #24 from brandonsavage/bouncer-tests

Bouncer tests
  • Loading branch information...
2 parents 0650c81 + 2d8b031 commit e7b78a1ad7b92503f3b6fdcdade435afa11427c0 @brandonsavage brandonsavage committed Jan 10, 2013
Showing with 25,064 additions and 21,390 deletions.
  1. +189 −0 bouncer/php/functions.php
  2. +7 −233 bouncer/php/index.php
  3. +2 −1 bouncer/php/lib/sdo.php
  4. +44 −0 bouncer/tests/functions.php
  5. +21 −0 bouncer/tests/mocks/sdo.php
  6. +1 −1 bouncer/tests/sdo.php
  7. +53 −2 bouncer/tests/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE
  8. 0 bouncer/tests/simpletest/LICENSE
  9. +42 −48 bouncer/tests/simpletest/README
  10. +1 −1 bouncer/tests/simpletest/VERSION
  11. +224 −0 bouncer/tests/simpletest/arguments.php
  12. +215 −216 bouncer/tests/simpletest/authentication.php
  13. +88 −50 bouncer/tests/simpletest/autorun.php
  14. +1,026 −979 bouncer/tests/simpletest/browser.php
  15. +106 −106 bouncer/tests/simpletest/collector.php
  16. +145 −152 bouncer/tests/simpletest/compatibility.php
  17. +344 −344 bouncer/tests/simpletest/cookies.php
  18. +151 −84 bouncer/tests/simpletest/default_reporter.php
  19. +79 −79 bouncer/tests/simpletest/detached.php
  20. +51 −46 bouncer/tests/simpletest/docs/en/authentication_documentation.html
  21. +199 −126 bouncer/tests/simpletest/docs/en/browser_documentation.html
  22. +3 −3 bouncer/tests/simpletest/docs/en/docs.css
  23. +107 −62 bouncer/tests/simpletest/docs/en/expectation_documentation.html
  24. +82 −47 bouncer/tests/simpletest/docs/en/form_testing_documentation.html
  25. +115 −264 bouncer/tests/simpletest/docs/en/group_test_documentation.html
  26. +221 −182 bouncer/tests/simpletest/docs/en/index.html
  27. +530 −430 bouncer/tests/simpletest/docs/en/mock_objects_documentation.html
  28. +126 −130 bouncer/tests/simpletest/docs/en/overview.html
  29. +113 −121 bouncer/tests/simpletest/docs/en/partial_mocks_documentation.html
  30. +175 −112 bouncer/tests/simpletest/docs/en/reporter_documentation.html
  31. +102 −79 bouncer/tests/simpletest/docs/en/unit_test_documentation.html
  32. +144 −108 bouncer/tests/simpletest/docs/en/web_tester_documentation.html
  33. +131 −56 bouncer/tests/simpletest/docs/fr/authentication_documentation.html
  34. +256 −118 bouncer/tests/simpletest/docs/fr/browser_documentation.html
  35. +1 −1 bouncer/tests/simpletest/docs/fr/docs.css
  36. +230 −81 bouncer/tests/simpletest/docs/fr/expectation_documentation.html
  37. +158 −63 bouncer/tests/simpletest/docs/fr/form_testing_documentation.html
  38. +147 −200 bouncer/tests/simpletest/docs/fr/group_test_documentation.html
  39. +359 −165 bouncer/tests/simpletest/docs/fr/index.html
  40. +724 −325 bouncer/tests/simpletest/docs/fr/mock_objects_documentation.html
  41. +65 −76 bouncer/tests/simpletest/docs/fr/overview.html
  42. +255 −149 bouncer/tests/simpletest/docs/fr/partial_mocks_documentation.html
  43. +354 −146 bouncer/tests/simpletest/docs/fr/reporter_documentation.html
  44. +0 −315 bouncer/tests/simpletest/docs/fr/server_stubs_documentation.html
  45. +222 −114 bouncer/tests/simpletest/docs/fr/unit_test_documentation.html
  46. +269 −132 bouncer/tests/simpletest/docs/fr/web_tester_documentation.html
  47. +373 −326 bouncer/tests/simpletest/dumper.php
  48. +280 −156 bouncer/tests/simpletest/eclipse.php
  49. +613 −485 bouncer/tests/simpletest/encoding.php
  50. +215 −233 bouncer/tests/simpletest/errors.php
  51. +191 −157 bouncer/tests/simpletest/exceptions.php
  52. +827 −738 bouncer/tests/simpletest/expectation.php
  53. +13 −15 bouncer/tests/simpletest/extensions/pear_test_case.php
  54. +0 −96 bouncer/tests/simpletest/extensions/phpunit_test_case.php
  55. +18 −7 bouncer/tests/simpletest/extensions/testdox.php
  56. +11 −10 bouncer/tests/simpletest/extensions/testdox/test.php
  57. +115 −105 bouncer/tests/simpletest/form.php
  58. +125 −129 bouncer/tests/simpletest/frames.php
  59. +596 −592 bouncer/tests/simpletest/http.php
  60. +118 −118 bouncer/tests/simpletest/invoker.php
  61. +761 −426 bouncer/tests/simpletest/mock_objects.php
  62. +127 −568 bouncer/tests/simpletest/page.php
  63. +509 −222 bouncer/tests/simpletest/{parser.php → php_parser.php}
  64. +101 −0 bouncer/tests/simpletest/recorder.php
  65. +116 −116 bouncer/tests/simpletest/reflection_php4.php
  66. +333 −313 bouncer/tests/simpletest/reflection_php5.php
  67. +95 −97 bouncer/tests/simpletest/remote.php
  68. +398 −385 bouncer/tests/simpletest/reporter.php
  69. +763 −751 bouncer/tests/simpletest/scorer.php
  70. +111 −103 bouncer/tests/simpletest/selector.php
  71. +297 −300 bouncer/tests/simpletest/shell_tester.php
  72. +329 −416 bouncer/tests/simpletest/simpletest.php
  73. +275 −179 bouncer/tests/simpletest/socket.php
  74. +1,419 −1,310 bouncer/tests/simpletest/tag.php
  75. +351 −193 bouncer/tests/simpletest/test/acceptance_test.php
  76. +2 −29 bouncer/tests/simpletest/test/adapter_test.php
  77. 0 bouncer/tests/simpletest/test/all_tests.php
  78. +82 −0 bouncer/tests/simpletest/test/arguments_test.php
  79. +16 −16 bouncer/tests/simpletest/test/authentication_test.php
  80. +23 −0 bouncer/tests/simpletest/test/autorun_test.php
  81. 0 bouncer/tests/simpletest/test/bad_test_suite.php
  82. +174 −151 bouncer/tests/simpletest/test/browser_test.php
  83. +16 −17 bouncer/tests/simpletest/test/collector_test.php
  84. 0 bouncer/tests/simpletest/test/command_line_test.php
  85. +7 −17 bouncer/tests/simpletest/test/compatibility_test.php
  86. +1 −1 bouncer/tests/simpletest/test/cookies_test.php
  87. +3 −3 bouncer/tests/simpletest/test/detached_test.php
  88. +1 −1 bouncer/tests/simpletest/test/dumper_test.php
  89. +2 −2 bouncer/tests/simpletest/test/eclipse_test.php
  90. +82 −33 bouncer/tests/simpletest/test/encoding_test.php
  91. +19 −90 bouncer/tests/simpletest/test/errors_test.php
  92. +82 −19 bouncer/tests/simpletest/test/exceptions_test.php
  93. +124 −52 bouncer/tests/simpletest/test/expectation_test.php
  94. +79 −44 bouncer/tests/simpletest/test/form_test.php
  95. +103 −103 bouncer/tests/simpletest/test/frames_test.php
  96. +436 −371 bouncer/tests/simpletest/test/http_test.php
  97. +24 −21 bouncer/tests/simpletest/test/interfaces_test.php
  98. +14 −0 bouncer/tests/simpletest/test/interfaces_test_php5_1.php
  99. +4 −4 bouncer/tests/simpletest/test/live_test.php
  100. +431 −280 bouncer/tests/simpletest/test/mock_objects_test.php
  101. +58 −795 bouncer/tests/simpletest/test/page_test.php
  102. +1 −1 bouncer/tests/simpletest/test/parse_error_test.php
  103. +642 −0 bouncer/tests/simpletest/test/parsing_test.php
  104. +176 −207 bouncer/tests/simpletest/test/{parser_test.php → php_parser_test.php}
  105. +23 −0 bouncer/tests/simpletest/test/recorder_test.php
  106. +0 −61 bouncer/tests/simpletest/test/reflection_php4_test.php
  107. +5 −13 bouncer/tests/simpletest/test/reflection_php5_test.php
  108. +3 −4 bouncer/tests/simpletest/test/remote_test.php
  109. +3 −3 bouncer/tests/simpletest/test/shell_test.php
  110. +13 −13 bouncer/tests/simpletest/test/shell_tester_test.php
  111. +8 −8 bouncer/tests/simpletest/test/simpletest_test.php
  112. +6 −0 bouncer/tests/simpletest/test/site/file.html
  113. +4 −4 bouncer/tests/simpletest/test/socket_test.php
  114. 0 bouncer/tests/simpletest/test/support/collector/collectable.1
  115. 0 bouncer/tests/simpletest/test/support/collector/collectable.2
  116. 0 bouncer/tests/simpletest/test/support/empty_test_file.php
  117. +9 −0 bouncer/tests/simpletest/test/support/failing_test.php
  118. 0 bouncer/tests/simpletest/test/support/latin1_sample
  119. +9 −0 bouncer/tests/simpletest/test/support/passing_test.php
  120. +14 −0 bouncer/tests/simpletest/test/support/recorder_sample.php
  121. +1 −1 bouncer/tests/simpletest/test/support/spl_examples.php
  122. 0 bouncer/tests/simpletest/test/support/supplementary_upload_sample.txt
  123. +7 −0 bouncer/tests/simpletest/test/support/test1.php
  124. 0 bouncer/tests/simpletest/test/support/upload_sample.txt
  125. +94 −94 bouncer/tests/simpletest/test/tag_test.php
  126. +1 −1 bouncer/tests/simpletest/test/test_with_parse_error.php
  127. +14 −8 bouncer/tests/simpletest/test/unit_tester_test.php
  128. +10 −15 bouncer/tests/simpletest/test/unit_tests.php
  129. +114 −14 bouncer/tests/simpletest/test/url_test.php
  130. +109 −119 bouncer/tests/simpletest/test/user_agent_test.php
  131. +405 −405 bouncer/tests/simpletest/test/visual_test.php
  132. +1 −2 bouncer/tests/simpletest/test/web_tester_test.php
  133. +30 −30 bouncer/tests/simpletest/test/xml_test.php
  134. +571 −582 bouncer/tests/simpletest/test_case.php
  135. +382 −0 bouncer/tests/simpletest/tidy_parser.php
  136. +381 −385 bouncer/tests/simpletest/unit_tester.php
  137. +518 −494 bouncer/tests/simpletest/url.php
  138. +304 −309 bouncer/tests/simpletest/user_agent.php
  139. +1,494 −1,503 bouncer/tests/simpletest/web_tester.php
  140. +572 −572 bouncer/tests/simpletest/xml.php
@@ -0,0 +1,189 @@
+<?php
+
+/**
+ * Echo proper headers for ensuring no caching of redirects.
+ */
+function show_no_cache_headers() {
+ header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, private');
+ header('Pragma: no-cache');
+}
+
+/**
+ * Get a random element from an array based on weighted array values.
+ * @param array $array array of val => weight pairings
+ * @param int $sum total of added weightings
+ * @return bool value of randomly selected element
+ */
+function getRandElement( $array, $sum ) {
+ $tot_prob = $sum;
+ foreach ( $array as $element => $element_prob ) {
+ if ( mt_rand( 1, $tot_prob ) <= $element_prob ) {
+ return $element;
+ } else {
+ $tot_prob -= $element_prob;
+ }
+ }
+ return 0;
+}
+
+/**
+ * GeoIP: For a given IP address, get the associated region ID it is in.
+ * @param string $ip IP address in dotted quad format
+ * @return mixed region ID (int) or false if no region assigned or error
+ */
+function getRegionFromIP($sdo, $ip) {
+
+ $region = $sdo->get_one("
+ SELECT
+ cty.region_id
+ FROM
+ geoip_country_to_region AS cty
+ INNER JOIN
+ geoip_ip_to_country AS ip
+ ON
+ ip.country_code = cty.country_code AND
+ ip_end = ( SELECT MIN(ip_end) FROM geoip_ip_to_country WHERE ip_end >= INET_ATON('%s') LIMIT 1 ) AND
+ ip_start <= INET_ATON('%s')
+ ",array($ip, $ip));
+
+ if ($region)
+ return $region['region_id'];
+ else
+ return false;
+}
+
+/**
+ * GeoIP: For a given region id do any throttling for the region
+ * @param int $region_id a region id
+ * @return boolean should this request come from the clients region? false = yes true = no
+ */
+function throttleGeoIPRegion($sdo, $region_id) {
+
+ $region_throttle = $sdo->get_one("
+ SELECT
+ throttle
+ FROM
+ geoip_regions
+ WHERE
+ id = %d
+ ",array($region_id));
+
+ $region_throttle = $region_throttle['throttle'];
+
+ // Don't throttle the user if the throttle is invalid.
+ if ( $region_throttle == 100 || $region_throttle > 100 || $region_throttle < 0 ) {
+ return false;
+ } else {
+ /* Ex: Thottle is at 25% GeoIP
+ A random number from 1 to 100 will be less than or equal to 25 25% or the time.
+ 100 will always be greater than or equal to a random number between 1 and 100
+ 0 will never be greater than or equal to a random number between 1 and 100
+ */
+ if ( $region_throttle >= mt_rand(1,100) ) {
+ return false;
+ } else {
+ return true;
+ }
+
+ }
+
+}
+
+function getFallbackRegion($sdo, $region_id) {
+
+ $fallback = $sdo->get_one("
+ SELECT
+ fallback_id
+ FROM
+ geoip_regions
+ WHERE
+ id = %d
+ ",array($region_id));
+
+ if($fallback) {
+ return $fallback['fallback_id'];
+ } else {
+ return false;
+ }
+}
+
+function getGlobalFallbackProhibited($sdo, $region_id) {
+
+ $fallback = $sdo->get_one("
+ SELECT
+ prevent_global_fallback
+ FROM
+ geoip_regions
+ WHERE
+ id = %d
+ ",array($region_id));
+
+ if($fallback) {
+ return $fallback['prevent_global_fallback'];
+ } else {
+ return false;
+ }
+}
+
+function setHttpType($ssl_only) {
+ if ($ssl_only) {
+ $http_type = "https://";
+ } else {
+ $http_type = "http://";
+ }
+ return $http_type;
+}
+
+function queryForMirrors($sdo, $http_type, $where_lang, $location_id, $client_region = null, $recurse = false) {
+ $arguments = array($where_lang, $location_id);
+
+ // If we are using GEOIP, we need to customize the SQL accordingly.
+ if($client_region) {
+ $cr_sql = ' geoip_mirror_region_map.region_id = %d AND ';
+ $arguments[] = $client_region;
+ } else {
+ $cr_sql = null;
+ }
+
+ // If we have recursed into this function, we have failed over to unhealthy
+ // mirrors.
+ if($recurse) {
+ $healthy = 0;
+ } else {
+ $healthy = 1;
+ }
+
+ $arguments[] = $healthy;
+
+ // Let's fetch the mirrors.
+ $mirrors = $sdo->get("
+ SELECT
+ mirror_mirrors.id,
+ baseurl,
+ rating
+ FROM
+ mirror_mirrors
+ JOIN
+ mirror_location_mirror_map ON mirror_mirrors.id = mirror_location_mirror_map.mirror_id
+ LEFT JOIN
+ mirror_lmm_lang_exceptions AS lang_exc ON (mirror_location_mirror_map.id = lang_exc.location_mirror_map_id AND NOT lang_exc.language = '%s')
+ INNER JOIN
+ geoip_mirror_region_map ON (geoip_mirror_region_map.mirror_id = mirror_mirrors.id)
+ WHERE
+ mirror_location_mirror_map.location_id = %d AND
+ $cr_sql
+ mirror_mirrors.active='1' AND
+ mirror_location_mirror_map.active ='1' AND
+ mirror_location_mirror_map.healthy = '%d' AND
+ mirror_mirrors.baseurl LIKE '$http_type%%'
+ ORDER BY rating",
+ $arguments, MYSQL_ASSOC, 'id');
+
+ // If we found no mirrors and we are not in the second execution of this
+ // function, let's try finding some unhealthy mirrors.
+ if(!$mirrors && !$recurse) {
+ return queryForMirrors($sdo, $http_type, $where_lang, $location_id, $client_region, true);
+ }
+
+ return $mirrors;
+}
Oops, something went wrong.

0 comments on commit e7b78a1

Please sign in to comment.