mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
Better default styles, made form extensible
This commit is contained in:
parent
dca76e9ba3
commit
c901abe83c
@ -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
2
css/styles.css
Normal file
@ -0,0 +1,2 @@
|
||||
input[name=fixture] {width: 400px;}
|
||||
.datetime .middleColumn .field {overflow: auto;}
|
@ -8,3 +8,4 @@
|
||||
</ul>
|
||||
</p>
|
||||
<% end_if %>
|
||||
$Form
|
@ -1,9 +1,26 @@
|
||||
<p>Test session ended.</p>
|
||||
<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>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,5 +1,24 @@
|
||||
<p>
|
||||
<!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 %>
|
||||
</p>
|
||||
<% include TestSession_State %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
@ -1,10 +1,24 @@
|
||||
<!-- SUCCESS: DBNAME=$DatabaseName -->
|
||||
<p>
|
||||
<!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>
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
<a id="home-link" href="$BaseHref">Homepage - published site</a>
|
||||
</li>
|
||||
@ -17,19 +31,8 @@
|
||||
<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>
|
||||
</ul>
|
||||
<% include TestSession_State %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user