SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/phpunit_bootstrap.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. use Sprout\Helpers\SubsiteSelector;
  15. use Sprout\Helpers\Pdb;
  16.  
  17.  
  18. // Report ALL THE THINGS so they can be fixed
  19.  
  20. // We are never running tests in production
  21. define('IN_PRODUCTION', FALSE);
  22.  
  23. // Timezone, needed for PHP 5.3+
  24. date_default_timezone_set('Australia/Adelaide');
  25.  
  26. // Define the front controller, docroot, and other paths
  27. $kohana_pathinfo = pathinfo(dirname(__FILE__) . '/../index.php');
  28. $kohana_application = 'sprout';
  29.  
  30. define('DOCROOT', $kohana_pathinfo['dirname'].DIRECTORY_SEPARATOR);
  31. define('KOHANA', $kohana_pathinfo['basename']);
  32.  
  33. chdir(DOCROOT);
  34.  
  35. define('APPPATH', str_replace('\\', '/', realpath($kohana_application)).'/');
  36.  
  37. /**
  38.  * Used by the config bits, see the same function in index.php
  39.  * @return string The root web path, e.g. '/' or '/my-subsite/'
  40.  * @return bool False if the path couldn't be determined
  41.  */
  42. function _privDetermineWebDirectory() {
  43. if (!empty($_SERVER['PHP_S_WEBDIR'])) return $_SERVER['PHP_S_WEBDIR'];
  44. if (! $_SERVER['DOCUMENT_ROOT']) return false;
  45.  
  46. $pos = strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT']);
  47. if ($pos === 0) {
  48. $doc_path = substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT']));
  49. $doc_path = dirname($doc_path);
  50.  
  51. if (substr($doc_path, 0, 1) != '/') $doc_path = '/' . $doc_path;
  52. if (substr($doc_path, -1, 1) != '/') $doc_path .= '/';
  53.  
  54. if ($_SERVER['REQUEST_URI'] and preg_match('!^/v[1-9]/!', $doc_path) and !preg_match('!^/v[1-9]/!', $_SERVER['REQUEST_URI'])) {
  55. $doc_path = preg_replace('!^/v[1-9]/!', '/', $doc_path);
  56. }
  57.  
  58. return $doc_path;
  59. }
  60.  
  61. return false;
  62. }
  63.  
  64. // Fake server vars when run from CLI
  65. if (empty($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  66.  
  67. // Load core files
  68. require APPPATH . 'core/utf8.php';
  69. require APPPATH . 'core/Event.php';
  70. require APPPATH . 'core/Kohana.php';
  71.  
  72. // Prepare the environment
  73. Kohana::setup();
  74. SubsiteSelector::selectSubsite();
  75.  
  76. // Allow both old and new versions of phpunit to work
  77. if (!class_exists('PHPUnit_Framework_TestCase')) {
  78. class PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase {}
  79. }
  80.  
  81. // Increase wait timeout, which is very low on Travis CI
  82. Pdb::query("SET wait_timeout=3600", [], 'null');
  83.