Better default styles, made form extensible

This commit is contained in:
Ingo Schommer 2013-12-10 16:50:23 +01:00
parent dca76e9ba3
commit c901abe83c
6 changed files with 133 additions and 55 deletions

View File

@ -10,6 +10,7 @@ class TestSessionController extends Controller {
'set',
'end',
'clear',
'Form',
);
private static $alternative_database_name = -1;
@ -35,7 +36,7 @@ class TestSessionController extends Controller {
if(SapphireTest::using_temp_db()) return $this->renderWith('TestSession_inprogress');
// Database
$dbName = $request->getVar('database');
$dbName = $request->requestVar('database');
if($dbName) {
$dbExists = (bool)DB::query(
sprintf("SHOW DATABASES LIKE '%s'", Convert::raw2sql($dbName))
@ -51,13 +52,40 @@ class TestSessionController extends Controller {
$dbName = SapphireTest::create_temp_db();
}
$this->setState(array_merge($request->getVars(), array('database' => $dbName)));
$this->setState(array_merge($request->requestVars(), array('database' => $dbName)));
$this->extend('onAfterStart', $dbName);
return $this->renderWith('TestSession_start');
}
public function Form() {
$form = new Form(
$this,
'Form',
new FieldList(
(new TextField('fixture', 'Fixture YAML file path'))
->setAttribute('placeholder', 'Example: framework/tests/security/MemberTest.yml'),
$datetimeField = new DatetimeField('date', 'Custom date'),
new HiddenField('flush', null, 1)
),
new FieldList(
new FormAction('set', 'Set testing state')
)
);
$datetimeField->getDateField()
->setConfig('dateformat', 'yyyy-MM-dd')
->setConfig('showcalendar', true)
->setAttribute('placeholder', 'Date');
$datetimeField->getTimeField()
->setAttribute('placeholder', 'Time');
$form->setFormAction($this->Link('set'));
$this->extend('updateForm', $form);
return $form;
}
public function DatabaseName() {
// Workaround for bug in Cookie::get(), fixed in 3.1-rc1
if(self::$alternative_database_name != -1) {
@ -78,9 +106,9 @@ class TestSessionController extends Controller {
);
}
$state = $request->getVars();
$this->extend('onBeforeSet', $state);
$this->setState($data);
$params = $request->requestVars();
$this->extend('onBeforeSet', $params);
$this->setState($params);
$this->extend('onAfterSet');
return $this->renderWith('TestSession_inprogress');
@ -158,6 +186,12 @@ class TestSessionController extends Controller {
}
public function setState($data) {
// Filter keys
$data = array_diff_key(
$data,
array('action_set' => true, 'SecurityID' => true, 'url' => true)
);
// Database
$dbname = (isset($data['database'])) ? $data['database'] : null;
if($dbname) {
@ -203,6 +237,8 @@ class TestSessionController extends Controller {
$date = (isset($data['date'])) ? $data['date'] : null;
if($date) {
require_once 'Zend/Date.php';
// Convert DatetimeField format
if(is_array($date)) $date = $date['date'] . ' ' . $date['time'];
if(!Zend_Date::isDate($date, 'yyyy-MM-dd HH:mm:ss')) {
throw new LogicException(sprintf(
'Invalid date format "%s", use yyyy-MM-dd HH:mm:ss',

2
css/styles.css Normal file
View File

@ -0,0 +1,2 @@
input[name=fixture] {width: 400px;}
.datetime .middleColumn .field {overflow: auto;}

View File

@ -7,4 +7,5 @@
<% end_loop %>
</ul>
</p>
<% end_if %>
<% end_if %>
$Form

View File

@ -1,9 +1,26 @@
<p>Test session ended.</p>
<ul>
<li>
<a id="home-link" href="$BaseHref">Return to your site</a>
</li>
<li>
<a id="start-link" href="$Link(start)">Start a new test session</a>
</li>
</ul>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<% base_tag %>
$MetaTags
<% require css('framework/css/debug.css') %>
<% require css('testsession/css/styles.css') %>
</head>
<body>
<div class="info">
<h1>SilverStripe TestSession</h1>
</div>
<div class="content">
<p>Test session ended.</p>
<ul>
<li>
<a id="home-link" href="$BaseHref">Return to your site</a>
</li>
<li>
<a id="start-link" href="$Link(start)">Start a new test session</a>
</li>
</ul>
</div>
</body>
</html>

View File

@ -1,5 +1,24 @@
<p>
You're in the middle of a test session.
<a id="end-session" href="$Link(end)">Click here to end it.</a>
</p>
<% include TestSession_State %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<% base_tag %>
$MetaTags
<% require css('framework/css/debug.css') %>
<% require css('testsession/css/styles.css') %>
</head>
<body>
<div class="info">
<h1>SilverStripe TestSession</h1>
</div>
<div class="content">
<p>
You're in the middle of a test session.
<a id="end-session" href="$Link(end)">Click here to end it.</a>
</p>
<% include TestSession_State %>
</div>
</body>
</html>

View File

@ -1,35 +1,38 @@
<!-- SUCCESS: DBNAME=$DatabaseName -->
<p>
Started testing session.
<% if Fixture %>Loaded fixture "$Fixture" into database.<% end_if %>
Time to start testing; where would you like to start?
</p>
<ul>
<li>
<a id="home-link" href="$BaseHref">Homepage - published site</a>
</li>
<li>
<a id="draft-link" href="$BaseHref/?stage=Stage">Homepage - draft site</a>
</li>
<li>
<a id="admin-link" href="$BaseHref/admin/">CMS Admin</a>
</li>
<li>
<a id="end-link" href="$Link(end)">End your test session</a>
</li>
</ul>
<% include TestSession_State %>
<form action="$Link(set)">
<p>
Enter a fixture file name to add it to the test session.
Don't forget to visit dev/testsession/end when you're done!
</p>
<p>
Fixture file:
<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>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<% base_tag %>
$MetaTags
<% require css('framework/css/debug.css') %>
<% require css('testsession/css/styles.css') %>
</head>
<body>
<div class="info">
<h1>SilverStripe TestSession</h1>
</div>
<div class="content">
<!-- SUCCESS: DBNAME=$DatabaseName -->
<p>
Started testing session.
<% if Fixture %>Loaded fixture "$Fixture" into database.<% end_if %>
Time to start testing; where would you like to start?
</p>
<ul>
<li>
<a id="home-link" href="$BaseHref">Homepage - published site</a>
</li>
<li>
<a id="draft-link" href="$BaseHref/?stage=Stage">Homepage - draft site</a>
</li>
<li>
<a id="admin-link" href="$BaseHref/admin/">CMS Admin</a>
</li>
<li>
<a id="end-link" href="$Link(end)">End your test session</a>
</li>
</ul>
<% include TestSession_State %>
</div>
</body>
</html>