[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/tests/ -> bootstrap.php (source)

   1  <?php
   2  /**
   3   * YOURLS Unit Test. No, I don't know what I'm doing.
   4   */
   5  
   6  // Globalize some YOURLS variables because PHPUnit loads this inside a function
   7  // See https://github.com/sebastianbergmann/phpunit/issues/325
   8  // This has to be done before including any file
   9  global $yourls_user_passwords, $yourls_reserved_URL,          // main object & config file
  10         $yourls_filters, $yourls_actions,                      // used by plugin API
  11         $yourls_locale, $yourls_l10n, $yourls_locale_formats,  // used by L10N API
  12         $yourls_allowedentitynames, $yourls_allowedprotocols;  // used by KSES
  13  
  14  require_once  __DIR__ . '/includes/utils.php';
  15  require_once  __DIR__ . '/includes/install.php';
  16  
  17  // Include relevant config file
  18  define('YOURLS_CONFIGFILE', yut_find_config());
  19  echo "Using config file: " . YOURLS_CONFIGFILE . "\n";
  20  require_once YOURLS_CONFIGFILE;
  21  
  22  // Bootstrap YOURLS
  23  require_once  YOURLS_ABSPATH . '/includes/vendor/autoload.php';
  24  define('YOURLS_TESTDATA_DIR', __DIR__ . '/data');
  25  define('YOURLS_LANG_DIR', YOURLS_TESTDATA_DIR.'/pomo');
  26  define('YOURLS_PLUGINDIR', YOURLS_TESTDATA_DIR.'/plugins');
  27  define('YOURLS_PAGEDIR', YOURLS_TESTDATA_DIR.'/pages');
  28  $config = new \YOURLS\Config\Config(YOURLS_CONFIGFILE);
  29  $config->define_core_constants();
  30  
  31  // Define YOURLS actions upon new instance
  32  $init = new \YOURLS\Config\InitDefaults;
  33  $init->check_maintenance_mode        = false;
  34  $init->fix_request_uri               = false;
  35  $init->redirect_ssl                  = false;
  36  $init->redirect_to_install           = false;
  37  $init->check_if_upgrade_needed       = false;
  38  $init->load_plugins                  = false; // do not attempt to load (no DB yet to store data), but do send the 'plugins_loaded' action (some code depend on it)
  39  $init->get_all_options               = false;
  40  $init->check_new_version             = false;
  41  new \YOURLS\Config\Init($init);
  42  
  43  // All set -- install
  44  yut_install_yourls();
  45  
  46  // All set -- instantiate the rest
  47  yourls_get_all_options();
  48  yourls_load_plugins();
  49  
  50  // At this point, tests will start
  51  
  52  // Simplify yourls_die() when running unit tests
  53  yourls_add_action( 'pre_yourls_die', function($params) {
  54      printf("\n\nCalling yourls_die(). %s : %s (%s)\n\n", $params[1], $params[0], $params[2]);
  55      echo "Last 10 Backtrace:\n";
  56      $trace = debug_backtrace();
  57      foreach( array_slice($trace, 0, 10) as $t ) {
  58          printf("** %s:%d %s() with args\n%s\n", $t['file'], $t['line'], $t['function'], var_export($t['args'], true));
  59      }
  60  
  61      die(1);
  62  } );
  63  
  64  echo "YOURLS installed, starting PHPUnit\n\n";
  65  
  66  require_once  __DIR__ . "/tests/auth/AbstractLoginTestCase.php";
  67  require_once  __DIR__ . "/tests/auth/LoginAssertionTrait.php";


Generated: Wed Nov 5 05:10:36 2025 Cross-referenced by PHPXref 0.7.1