/**
  * currentAbsoluteURL needs to handle base or url being missing, or any combination of slashes.
  *
  * There should always be exactly one slash between each part in the result, and any trailing slash
  * should be preserved.
  */
 public function testCurrentAbsoluteURLHandlesSlashes()
 {
     global $url;
     $token = new ParameterConfirmationTokenTest_Token('parameterconfirmationtokentest_parameter');
     foreach (array('foo', 'foo/') as $host) {
         list($hostAnswer, $hostSlash) = $this->addPart(array(), '', $host);
         foreach (array('', '/', 'bar', 'bar/', '/bar', '/bar/') as $base) {
             list($baseAnswer, $baseSlash) = $this->addPart($hostAnswer, $hostSlash, $base);
             foreach (array('', '/', 'baz', 'baz/', '/baz', '/baz/') as $url) {
                 list($urlAnswer, $urlSlash) = $this->addPart($baseAnswer, $baseSlash, $url);
                 $_SERVER['HTTP_HOST'] = $host;
                 ParameterConfirmationToken::$alternateBaseURL = $base;
                 $this->assertEquals('http://' . implode('/', $urlAnswer) . $urlSlash, $token->currentAbsoluteURL());
             }
         }
     }
 }
    // Pass back to the webserver for files that exist
    if (php_sapi_name() === 'cli-server' && file_exists(BASE_PATH . $url) && is_file(BASE_PATH . $url)) {
        return false;
    }
}
// Remove base folders from the URL if webroot is hosted in a subfolder
if (substr(strtolower($url), 0, strlen(BASE_URL)) == strtolower(BASE_URL)) {
    $url = substr($url, strlen(BASE_URL));
}
/**
 * Include SilverStripe's core code
 */
require_once 'Core/Startup/ErrorControlChain.php';
require_once 'Core/Startup/ParameterConfirmationToken.php';
// Prepare tokens and execute chain
$reloadToken = ParameterConfirmationToken::prepare_tokens(array('isTest', 'isDev', 'flush'));
$chain = new ErrorControlChain();
$chain->then(function ($chain) use($reloadToken) {
    // If no redirection is necessary then we can disable error supression
    if (!$reloadToken) {
        $chain->setSuppression(false);
    }
    // Load in core
    require_once 'Core/Core.php';
    // Connect to database
    global $databaseConfig;
    if ($databaseConfig) {
        DB::connect($databaseConfig);
    }
    // Check if a token is requesting a redirect
    if (!$reloadToken) {
 /**
  * Given a list of token names, suppress all tokens that have not been validated, and
  * return the non-validated token with the highest priority
  *
  * @param array $keys List of token keys in ascending priority (low to high)
  * @return ParameterConfirmationToken The token container for the unvalidated $key given with the highest priority
  */
 public static function prepare_tokens($keys)
 {
     $target = null;
     foreach ($keys as $key) {
         $token = new ParameterConfirmationToken($key);
         // Validate this token
         if ($token->reloadRequired()) {
             $token->suppress();
             $target = $token;
         }
     }
     return $target;
 }
    public function checkRewrite()
    {
        require_once 'Core/Startup/ParameterConfirmationToken.php';
        $token = new ParameterConfirmationToken('flush');
        $params = http_build_query($token->params());
        $destinationURL = str_replace('install.php', '', $_SERVER['SCRIPT_NAME']) . ($this->checkModuleExists('cms') ? "home/successfullyinstalled?{$params}" : "?{$params}");
        echo <<<HTML
<li id="ModRewriteResult">Testing...</li>
<script>
\tif(typeof \$ == 'undefined') {
\t\tdocument.getElemenyById('ModeRewriteResult').innerHTML = "I can't run jQuery ajax to set rewriting; I will redirect you to the homepage to see if everything is working.";
\t\tsetTimeout(function() {
\t\t\twindow.location = "{$destinationURL}";
\t\t}, 10000);
\t} else {
\t\t\$.ajax({
\t\t\tmethod: 'get',
\t\t\turl: 'InstallerTest/testrewrite',
\t\t\tcomplete: function(response) {
\t\t\t\tvar r = response.responseText.replace(/[^A-Z]?/g,"");
\t\t\t\tif(r === "OK") {
\t\t\t\t\t\$('#ModRewriteResult').html("Friendly URLs set up successfully; I am now redirecting you to your SilverStripe site...")
\t\t\t\t\tsetTimeout(function() {
\t\t\t\t\t\twindow.location = "{$destinationURL}";
\t\t\t\t\t}, 2000);
\t\t\t\t} else {
\t\t\t\t\t\$('#ModRewriteResult').html("Friendly URLs are not working. This is most likely because a rewrite module isn't configured "
\t\t\t\t\t\t+ "correctly on your site. You may need to get your web host or server administrator to do this for you: "
\t\t\t\t\t\t+ "<ul>"
\t\t\t\t\t\t+ "<li><strong>mod_rewrite</strong> or other rewrite module is enabled on your web server</li>"
\t\t\t\t\t\t+ "<li><strong>AllowOverride All</strong> is set for the directory where SilverStripe is installed</li>"
\t\t\t\t\t\t+ "</ul>");
\t\t\t\t}
\t\t\t}
\t\t});
\t}
</script>
<noscript>
\t<li><a href="{$destinationURL}">Click here</a> to check friendly URLs are working. If you get a 404 then something is wrong.</li>
</noscript>
HTML;
    }