Created
February 3, 2010 22:54
-
-
Save sminnee/294142 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: sapphire/dev/TestRunner.php | |
| =================================================================== | |
| --- sapphire/dev/TestRunner.php (revision 98079) | |
| +++ sapphire/dev/TestRunner.php (working copy) | |
| @@ -300,39 +300,51 @@ | |
| 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(BASE_PATH.'/'.$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(BASE_PATH.'/'.$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>"; | |
| } | |
| @@ -345,7 +357,11 @@ | |
| 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() { | |
| Index: sapphire/dev/DevelopmentAdmin.php | |
| =================================================================== | |
| --- sapphire/dev/DevelopmentAdmin.php (revision 98079) | |
| +++ sapphire/dev/DevelopmentAdmin.php (working copy) | |
| @@ -128,84 +128,13 @@ | |
| } | |
| 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() { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment