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.4@98080 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
c8cefb5d6c
commit
eba7aa8fc0
@ -55,10 +55,11 @@ class DevelopmentAdmin extends Controller {
|
|||||||
function index() {
|
function index() {
|
||||||
$actions = array(
|
$actions = array(
|
||||||
"build" => "Build/rebuild this environment (formerly db/build). Call this whenever you have updated your project sources",
|
"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",
|
"buildcache" => "Rebuild the static cache, if you're using StaticPublisher",
|
||||||
"tests" => "See a list of unit tests to run",
|
"tests" => "See a list of unit tests to run",
|
||||||
"tests/all" => "Run all tests",
|
"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" => "See a list of JavaScript tests to run",
|
||||||
"jstests/all" => "Run all JavaScript tests",
|
"jstests/all" => "Run all JavaScript tests",
|
||||||
"tasks" => "See a list of build tasks to run",
|
"tasks" => "See a list of build tasks to run",
|
||||||
@ -128,84 +129,13 @@ class DevelopmentAdmin extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
global $databaseConfig;
|
$link = BASE_URL.'/dev/tests/startsession';
|
||||||
$databaseName = $databaseConfig['database'];
|
|
||||||
|
|
||||||
if(Director::is_cli()) {
|
return "<p>The dev/reset feature has been removed. If you are trying to test your site " .
|
||||||
echo "\nPlease run dev/reset from your web browser.\n";
|
"with a clean datababase, we recommend that you use " .
|
||||||
} else {
|
"<a href=\"$link\">dev/test/startsession</a> ".
|
||||||
$renderer = new DebugView();
|
"instead.</P>";
|
||||||
$renderer->writeHeader();
|
|
||||||
$renderer->writeInfo('Database reset', 'Completely truncate and rebuild the current database');
|
|
||||||
echo '<div style="margin: 0 2em">';
|
|
||||||
|
|
||||||
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() {
|
function errors() {
|
||||||
|
@ -300,7 +300,7 @@ class TestRunner extends Controller {
|
|||||||
return <<<HTML
|
return <<<HTML
|
||||||
<form action="$me">
|
<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>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">
|
<input type="hidden" name="flush" value="1">
|
||||||
<p><input id="start-session" value="Start test session" type="submit" /></p>
|
<p><input id="start-session" value="Start test session" type="submit" /></p>
|
||||||
</form>
|
</form>
|
||||||
@ -308,6 +308,7 @@ HTML;
|
|||||||
} else {
|
} else {
|
||||||
$fixtureFile = $_GET['fixture'];
|
$fixtureFile = $_GET['fixture'];
|
||||||
|
|
||||||
|
if($fixtureFile) {
|
||||||
// Validate fixture file
|
// Validate fixture file
|
||||||
$realFile = realpath(BASE_PATH.'/'.$fixtureFile);
|
$realFile = realpath(BASE_PATH.'/'.$fixtureFile);
|
||||||
$baseDir = realpath(Director::baseFolder());
|
$baseDir = realpath(Director::baseFolder());
|
||||||
@ -320,19 +321,30 @@ HTML;
|
|||||||
} else if(!preg_match('/^([^\/.][^\/]+)\/tests\//', $fixtureFile)) {
|
} else if(!preg_match('/^([^\/.][^\/]+)\/tests\//', $fixtureFile)) {
|
||||||
return "<p>Fixture file must be inside the tests subfolder of one of your modules.</p>";
|
return "<p>Fixture file must be inside the tests subfolder of one of your modules.</p>";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$dbname = SapphireTest::create_temp_db();
|
$dbname = SapphireTest::create_temp_db();
|
||||||
|
|
||||||
DB::set_alternative_database_name($dbname);
|
DB::set_alternative_database_name($dbname);
|
||||||
|
|
||||||
$fixture = new YamlFixture($_GET['fixture']);
|
// Fixture
|
||||||
|
if($fixtureFile) {
|
||||||
|
$fixture = new YamlFixture($fixtureFile);
|
||||||
$fixture->saveIntoDatabase();
|
$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>
|
return "<p>Started testing session with fixture '$fixtureFile'. Time to start testing; where would you like to start?</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a id=\"home-link\" href=\"" .Director::baseURL() . "\">Homepage - published site</a></li>
|
<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=\"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=\"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>";
|
</ul>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +357,11 @@ HTML;
|
|||||||
SapphireTest::kill_temp_db();
|
SapphireTest::kill_temp_db();
|
||||||
DB::set_alternative_database_name(null);
|
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() {
|
function setUp() {
|
||||||
|
Loading…
Reference in New Issue
Block a user