mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: Removed dev/reset, instead encouraging the use of dev/tests/startsession for tests.
ENHANCEMENT: Let people use dev/tests/startsession without a fixture, instead calling requireDefaultRecords git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@98081 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
cd64c943f7
commit
909de1f454
@ -63,9 +63,10 @@ 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",
|
||||
"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",
|
||||
"modules/add" => "Add a module, for example, 'sake dev/modules/add ecommerce'",
|
||||
@ -140,84 +141,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 '<div style="margin: 0 2em">';
|
||||
return "<p>The dev/reset feature has been removed. If you are trying to test your site " .
|
||||
"with a clean datababase, we recommend that you use " .
|
||||
"<a href=\"$link\">dev/test/startsession</a> ".
|
||||
"instead.</P>";
|
||||
|
||||
if(isset($_GET['done'])) {
|
||||
echo "<p style=\"color: green\"><b>$databaseName</b> has been completely truncated and rebuilt.</p>";
|
||||
echo "<p>Note: If you had <i>SS_DEFAULT_ADMIN_USERNAME</i> and <i>SS_DEFAULT_ADMIN_PASSWORD</i>
|
||||
defined in your <b>_ss_environment.php</b> file, a default admin Member record has been created
|
||||
with those credentials.</p>";
|
||||
} else {
|
||||
echo $this->ResetForm()->renderWith('Form');
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
$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', "<p style=\"color: red\">WARNING: This will completely
|
||||
destroy ALL existing data in <b>$databaseName</b>! Press the button below to
|
||||
confirm this action.</p>"),
|
||||
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() {
|
||||
|
@ -214,39 +214,51 @@ class TestRunner extends Controller {
|
||||
return <<<HTML
|
||||
<form action="$me">
|
||||
<p>Enter a fixture file name to start a new test session. Don't forget to visit dev/tests/endsession when you're done!</p>
|
||||
<p>Fixture file: <input id="fixture-file" name="fixture" /></p>
|
||||
<p>Fixture file (leave blank to start with default set-up): <input id="fixture-file" name="fixture" /></p>
|
||||
<input type="hidden" name="flush" value="1">
|
||||
<p><input id="start-session" value="Start test session" type="submit" /></p>
|
||||
</form>
|
||||
HTML;
|
||||
} else {
|
||||
$fixtureFile = $_GET['fixture'];
|
||||
|
||||
// Validate fixture file
|
||||
$realFile = realpath('../' . $fixtureFile);
|
||||
$baseDir = realpath(Director::baseFolder());
|
||||
if(!$realFile || !file_exists($realFile)) {
|
||||
return "<p>Fixture file doesn't exist</p>";
|
||||
} else if(substr($realFile,0,strlen($baseDir)) != $baseDir) {
|
||||
return "<p>Fixture file must be inside $baseDir</p>";
|
||||
} else if(substr($realFile,-4) != '.yml') {
|
||||
return "<p>Fixture file must be a .yml file</p>";
|
||||
} else if(!preg_match('/^([^\/.][^\/]+)\/tests\//', $fixtureFile)) {
|
||||
return "<p>Fixture file must be inside the tests subfolder of one of your modules.</p>";
|
||||
|
||||
if($fixtureFile) {
|
||||
// Validate fixture file
|
||||
$realFile = realpath('../' . $fixtureFile);
|
||||
$baseDir = realpath(Director::baseFolder());
|
||||
if(!$realFile || !file_exists($realFile)) {
|
||||
return "<p>Fixture file doesn't exist</p>";
|
||||
} else if(substr($realFile,0,strlen($baseDir)) != $baseDir) {
|
||||
return "<p>Fixture file must be inside $baseDir</p>";
|
||||
} else if(substr($realFile,-4) != '.yml') {
|
||||
return "<p>Fixture file must be a .yml file</p>";
|
||||
} else if(!preg_match('/^([^\/.][^\/]+)\/tests\//', $fixtureFile)) {
|
||||
return "<p>Fixture file must be inside the tests subfolder of one of your modules.</p>";
|
||||
}
|
||||
}
|
||||
|
||||
$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 "<p>Started testing session with fixture '$fixtureFile'. Time to start testing; where would you like to start?</p>
|
||||
<ul>
|
||||
<li><a id=\"home-link\" href=\"" .Director::baseURL() . "\">Homepage - published site</a></li>
|
||||
<li><a id=\"draft-link\" href=\"" .Director::baseURL() . "?stage=Stage\">Homepage - draft site</a></li>
|
||||
<li><a id=\"admin-link\" href=\"" .Director::baseURL() . "admin/\">CMS Admin</a></li>
|
||||
<li><a id=\"endsession-link\" href=\"" .Director::baseURL() . "dev/tests/endsession\">End your test session</a></li>
|
||||
</ul>";
|
||||
}
|
||||
|
||||
@ -259,7 +271,11 @@ HTML;
|
||||
SapphireTest::kill_temp_db();
|
||||
DB::set_alternative_database_name(null);
|
||||
|
||||
return "<p>Test session ended.</p>";
|
||||
return "<p>Test session ended.</p>
|
||||
<ul>
|
||||
<li><a id=\"home-link\" href=\"" .Director::baseURL() . "\">Return to your site</a></li>
|
||||
<li><a id=\"startsession-link\" href=\"" .Director::baseURL() . "dev/tests/startsession\">Start a new test session</a></li>
|
||||
</ul>";
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
|
Loading…
Reference in New Issue
Block a user