Skip to content

Commit

Permalink
Fixed ORM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Jun 20, 2017
1 parent d75a8d1 commit 2a10c23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Control/HTTP.php
Expand Up @@ -70,7 +70,7 @@ public static function filename2url($filename)
*/
public static function absoluteURLs($html)
{
$html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html);
$html = str_replace('$CurrentPageURL', Controller::curr()->getRequest()->getURL(), $html);
return HTTP::urlRewriter($html, function ($url) {
//no need to rewrite, if uri has a protocol (determined here by existence of reserved URI character ":")
if (preg_match('/^\w+:/', $url)) {
Expand Down Expand Up @@ -170,7 +170,8 @@ public static function urlRewriter($content, $code)
*/
public static function setGetVar($varname, $varvalue, $currentURL = null, $separator = '&')
{
$uri = $currentURL ? $currentURL : Director::makeRelative($_SERVER['REQUEST_URI']);
$request = Controller::curr()->getRequest();
$uri = $currentURL ?: $request->getURL();

$isRelative = false;
// We need absolute URLs for parse_url()
Expand Down
11 changes: 7 additions & 4 deletions tests/php/ORM/DBTest.php
Expand Up @@ -3,6 +3,8 @@
namespace SilverStripe\ORM\Tests;

use SilverStripe\Control\Director;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;
use SilverStripe\ORM\DB;
use SilverStripe\Dev\SapphireTest;

Expand All @@ -11,19 +13,20 @@ class DBTest extends SapphireTest

public function testValidAlternativeDatabaseName()
{

/** @var Kernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
$prefix = getenv('SS_DATABASE_PREFIX') ?: 'ss_';

Director::set_environment_type('dev');
$kernel->setEnvironment(Kernel::DEV);
$this->assertTrue(DB::valid_alternative_database_name($prefix.'tmpdb1234567'));
$this->assertFalse(DB::valid_alternative_database_name($prefix.'tmpdb12345678'));
$this->assertFalse(DB::valid_alternative_database_name('tmpdb1234567'));
$this->assertFalse(DB::valid_alternative_database_name('random'));
$this->assertFalse(DB::valid_alternative_database_name(''));

Director::set_environment_type('live');
$kernel->setEnvironment(Kernel::LIVE);
$this->assertFalse(DB::valid_alternative_database_name($prefix.'tmpdb1234567'));

Director::set_environment_type('dev');
$kernel->setEnvironment(Kernel::DEV);
}
}

0 comments on commit 2a10c23

Please sign in to comment.