Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bootstrap.php « tests - github.com/YOURLS/YOURLS.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aaa066935db0985a85b7ed31c775fe01f7c64b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
 * YOURLS Unit Test. No, I don't know what I'm doing.
 */

// Globalize some YOURLS variables because PHPUnit loads this inside a function
// See https://github.com/sebastianbergmann/phpunit/issues/325
// This has to be done before including any file
global $yourls_user_passwords, $yourls_reserved_URL,          // main object & config file
       $yourls_filters, $yourls_actions,                      // used by plugin API
       $yourls_locale, $yourls_l10n, $yourls_locale_formats,  // used by L10N API
       $yourls_allowedentitynames, $yourls_allowedprotocols;  // used by KSES

require_once dirname( __FILE__ ) . '/includes/utils.php';
require_once dirname( __FILE__ ) . '/includes/install.php';

// Include relevant config file
define('YOURLS_CONFIGFILE', yut_find_config());
require_once YOURLS_CONFIGFILE;

// Bootstrap YOURLS
require_once YOURLS_ABSPATH . '/includes/vendor/autoload.php';
define('YOURLS_TESTDATA_DIR', dirname( __FILE__ ) . '/data');
define('YOURLS_LANG_DIR', YOURLS_TESTDATA_DIR.'/pomo');
define('YOURLS_PLUGINDIR', YOURLS_TESTDATA_DIR.'/plugins');
define('YOURLS_PAGEDIR', YOURLS_TESTDATA_DIR.'/pages');
$config = new \YOURLS\Config\Config(YOURLS_CONFIGFILE);
$config->define_core_constants();

// Define YOURLS actions upon new instance
$init = new \YOURLS\Config\InitDefaults;
$init->check_maintenance_mode        = false;
$init->fix_request_uri               = false;
$init->redirect_ssl                  = false;
$init->redirect_to_install           = false;
$init->check_if_upgrade_needed       = false;
$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)
$init->get_all_options               = false;
$init->check_new_version             = false;
$init->include_install_upgrade_funcs = true;
new \YOURLS\Config\Init($init);

// All set -- install
yut_install_yourls();

// All set -- instantiate the rest
yourls_get_all_options();
yourls_load_plugins();

// At this point, tests will start

// Simplify yourls_die() when running unit tests
yourls_add_action( 'pre_yourls_die', function($params) {
    printf("\n\nCalling yourls_die(). %s : %s (%s)\n\n", $params[1], $params[0], $params[2]);
    echo "Last 10 Backtrace:\n";
    $trace = debug_backtrace();
    foreach( array_slice($trace, 0, 10) as $t ) {
        printf("** %s:%d %s() with args\n%s\n", $t['file'], $t['line'], $t['function'], var_export($t['args'], true));
    }

    die(1);
} );

echo "YOURLS installed, starting PHPUnit\n\n";