diff --git a/dev/DevelopmentAdmin.php b/dev/DevelopmentAdmin.php index 92b272279..d0ac236da 100644 --- a/dev/DevelopmentAdmin.php +++ b/dev/DevelopmentAdmin.php @@ -55,10 +55,11 @@ class DevelopmentAdmin extends Controller { function index() { $actions = array( "build" => "Build/rebuild this environment (formerly db/build). Call this whenever you have updated your project sources", - "reset" => "Reset this environment - truncate the database and rebuild. This is useful after testing to start with a fresh working copy", "buildcache" => "Rebuild the static cache, if you're using StaticPublisher", "tests" => "See a list of unit tests to run", "tests/all" => "Run all tests", + "tests/startsession" => "Start a test session in your browser (gives you a temporary database with default content)", + "tests/endsession" => "Ends a test session", "jstests" => "See a list of JavaScript tests to run", "jstests/all" => "Run all JavaScript tests", "tasks" => "See a list of build tasks to run", @@ -128,84 +129,13 @@ class DevelopmentAdmin extends Controller { } function reset() { - global $databaseConfig; - $databaseName = $databaseConfig['database']; + $link = BASE_URL.'/dev/tests/startsession'; - if(Director::is_cli()) { - echo "\nPlease run dev/reset from your web browser.\n"; - } else { - $renderer = new DebugView(); - $renderer->writeHeader(); - $renderer->writeInfo('Database reset', 'Completely truncate and rebuild the current database'); - echo '
'; + return "

The dev/reset feature has been removed. If you are trying to test your site " . + "with a clean datababase, we recommend that you use " . + "dev/test/startsession ". + "instead.

"; - if(isset($_GET['done'])) { - echo "

$databaseName has been completely truncated and rebuilt.

"; - echo "

Note: If you had SS_DEFAULT_ADMIN_USERNAME and SS_DEFAULT_ADMIN_PASSWORD - defined in your _ss_environment.php file, a default admin Member record has been created - with those credentials.

"; - } else { - echo $this->ResetForm()->renderWith('Form'); - } - - echo '
'; - $renderer->writeFooter(); - } - } - - function ResetForm() { - global $databaseConfig; - $databaseName = $databaseConfig['database']; - - if(!Session::get('devResetRandNumber')) { - $rand = rand(5,500); - Session::set('devResetRandNumber', $rand); - } else { - $rand = Session::get('devResetRandNumber'); - } - - $form = new Form( - $this, - 'ResetForm', - new FieldSet( - new LiteralField('ResetWarning', "

WARNING: This will completely - destroy ALL existing data in $databaseName!   Press the button below to - confirm this action.

"), - new HiddenField('devResetRandNumber', '', $rand) - ), - new FieldSet( - new FormAction('doReset', 'Reset and completely rebuild the database') - ) - ); - - $form->setFormAction(Director::absoluteBaseURL() . 'dev/ResetForm'); - - return $form; - } - - function doReset($data, $form, $request) { - if(!isset($data['devResetRandNumber'])) { - Director::redirectBack(); - return false; - } - - // Avoid accidental database resets by checking the posted number to the one in session - if(Session::get('devResetRandNumber') != $data['devResetRandNumber']) { - Director::redirectBack(); - return false; - } - - $da = new DatabaseAdmin(); - $da->clearAllData(); - - // If _ss_environment.php has some constants set for default admin, set these up in the request - $_REQUEST['username'] = defined('SS_DEFAULT_ADMIN_USERNAME') ? SS_DEFAULT_ADMIN_USERNAME : null; - $_REQUEST['password'] = defined('SS_DEFAULT_ADMIN_PASSWORD') ? SS_DEFAULT_ADMIN_PASSWORD : null; - - $da->build(); - - Session::clear('devResetRandNumber'); - Director::redirect(Director::absoluteBaseURL() . 'dev/reset?done=1'); } function errors() { diff --git a/dev/TestRunner.php b/dev/TestRunner.php index bd4ead6a0..0143cfea5 100644 --- a/dev/TestRunner.php +++ b/dev/TestRunner.php @@ -300,39 +300,51 @@ class TestRunner extends Controller { return <<

Enter a fixture file name to start a new test session. Don't forget to visit dev/tests/endsession when you're done!

-

Fixture file:

+

Fixture file (leave blank to start with default set-up):

HTML; } else { $fixtureFile = $_GET['fixture']; - - // Validate fixture file - $realFile = realpath(BASE_PATH.'/'.$fixtureFile); - $baseDir = realpath(Director::baseFolder()); - if(!$realFile || !file_exists($realFile)) { - return "

Fixture file doesn't exist

"; - } else if(substr($realFile,0,strlen($baseDir)) != $baseDir) { - return "

Fixture file must be inside $baseDir

"; - } else if(substr($realFile,-4) != '.yml') { - return "

Fixture file must be a .yml file

"; - } else if(!preg_match('/^([^\/.][^\/]+)\/tests\//', $fixtureFile)) { - return "

Fixture file must be inside the tests subfolder of one of your modules.

"; + + if($fixtureFile) { + // Validate fixture file + $realFile = realpath(BASE_PATH.'/'.$fixtureFile); + $baseDir = realpath(Director::baseFolder()); + if(!$realFile || !file_exists($realFile)) { + return "

Fixture file doesn't exist

"; + } else if(substr($realFile,0,strlen($baseDir)) != $baseDir) { + return "

Fixture file must be inside $baseDir

"; + } else if(substr($realFile,-4) != '.yml') { + return "

Fixture file must be a .yml file

"; + } else if(!preg_match('/^([^\/.][^\/]+)\/tests\//', $fixtureFile)) { + return "

Fixture file must be inside the tests subfolder of one of your modules.

"; + } } $dbname = SapphireTest::create_temp_db(); DB::set_alternative_database_name($dbname); - - $fixture = new YamlFixture($_GET['fixture']); - $fixture->saveIntoDatabase(); + + // Fixture + if($fixtureFile) { + $fixture = new YamlFixture($fixtureFile); + $fixture->saveIntoDatabase(); + + // If no fixture, then use defaults + } else { + $dataClasses = ClassInfo::subclassesFor('DataObject'); + array_shift($dataClasses); + foreach($dataClasses as $dataClass) singleton($dataClass)->requireDefaultRecords(); + } return "

Started testing session with fixture '$fixtureFile'. Time to start testing; where would you like to start?

"; } @@ -345,7 +357,11 @@ HTML; SapphireTest::kill_temp_db(); DB::set_alternative_database_name(null); - return "

Test session ended.

"; + return "

Test session ended.

+ "; } function setUp() {