33 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2016-10-14 14:30:05 +13:00
namespace SilverStripe\ORM\Tests;
use SilverStripe\Control\Director;
2017-06-19 17:42:42 +12:00
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;
use SilverStripe\ORM\DB;
use SilverStripe\Dev\SapphireTest;
class DBTest extends SapphireTest
{
public function testValidAlternativeDatabaseName()
{
2017-06-19 17:42:42 +12:00
/** @var Kernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
$prefix = getenv('SS_DATABASE_PREFIX') ?: 'ss_';
2014-08-15 18:53:05 +12:00
2017-06-19 17:42:42 +12:00
$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(''));
2017-06-19 17:42:42 +12:00
$kernel->setEnvironment(Kernel::LIVE);
$this->assertFalse(DB::valid_alternative_database_name($prefix.'tmpdb1234567'));
2017-06-19 17:42:42 +12:00
$kernel->setEnvironment(Kernel::DEV);
}
2014-08-15 18:53:05 +12:00
}