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',
|
'set',
|
||||||
'end',
|
'end',
|
||||||
'clear',
|
'clear',
|
||||||
|
'Form',
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $alternative_database_name = -1;
|
private static $alternative_database_name = -1;
|
||||||
@ -35,7 +36,7 @@ class TestSessionController extends Controller {
|
|||||||
if(SapphireTest::using_temp_db()) return $this->renderWith('TestSession_inprogress');
|
if(SapphireTest::using_temp_db()) return $this->renderWith('TestSession_inprogress');
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
$dbName = $request->getVar('database');
|
$dbName = $request->requestVar('database');
|
||||||
if($dbName) {
|
if($dbName) {
|
||||||
$dbExists = (bool)DB::query(
|
$dbExists = (bool)DB::query(
|
||||||
sprintf("SHOW DATABASES LIKE '%s'", Convert::raw2sql($dbName))
|
sprintf("SHOW DATABASES LIKE '%s'", Convert::raw2sql($dbName))
|
||||||
@ -51,13 +52,40 @@ class TestSessionController extends Controller {
|
|||||||
$dbName = SapphireTest::create_temp_db();
|
$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);
|
$this->extend('onAfterStart', $dbName);
|
||||||
|
|
||||||
return $this->renderWith('TestSession_start');
|
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() {
|
public function DatabaseName() {
|
||||||
// Workaround for bug in Cookie::get(), fixed in 3.1-rc1
|
// Workaround for bug in Cookie::get(), fixed in 3.1-rc1
|
||||||
if(self::$alternative_database_name != -1) {
|
if(self::$alternative_database_name != -1) {
|
||||||
@ -78,9 +106,9 @@ class TestSessionController extends Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$state = $request->getVars();
|
$params = $request->requestVars();
|
||||||
$this->extend('onBeforeSet', $state);
|
$this->extend('onBeforeSet', $params);
|
||||||
$this->setState($data);
|
$this->setState($params);
|
||||||
$this->extend('onAfterSet');
|
$this->extend('onAfterSet');
|
||||||
|
|
||||||
return $this->renderWith('TestSession_inprogress');
|
return $this->renderWith('TestSession_inprogress');
|
||||||
@ -158,6 +186,12 @@ class TestSessionController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setState($data) {
|
public function setState($data) {
|
||||||
|
// Filter keys
|
||||||
|
$data = array_diff_key(
|
||||||
|
$data,
|
||||||
|
array('action_set' => true, 'SecurityID' => true, 'url' => true)
|
||||||
|
);
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
$dbname = (isset($data['database'])) ? $data['database'] : null;
|
$dbname = (isset($data['database'])) ? $data['database'] : null;
|
||||||
if($dbname) {
|
if($dbname) {
|
||||||
@ -203,6 +237,8 @@ class TestSessionController extends Controller {
|
|||||||
$date = (isset($data['date'])) ? $data['date'] : null;
|
$date = (isset($data['date'])) ? $data['date'] : null;
|
||||||
if($date) {
|
if($date) {
|
||||||
require_once 'Zend/Date.php';
|
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')) {
|
if(!Zend_Date::isDate($date, 'yyyy-MM-dd HH:mm:ss')) {
|
||||||
throw new LogicException(sprintf(
|
throw new LogicException(sprintf(
|
||||||
'Invalid date format "%s", use yyyy-MM-dd HH:mm:ss',
|
'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>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
$Form
|
@ -1,3 +1,17 @@
|
|||||||
|
<!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>
|
<p>Test session ended.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
@ -7,3 +21,6 @@
|
|||||||
<a id="start-link" href="$Link(start)">Start a new test session</a>
|
<a id="start-link" href="$Link(start)">Start a new test session</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,5 +1,24 @@
|
|||||||
|
<!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>
|
<p>
|
||||||
You're in the middle of a test session.
|
You're in the middle of a test session.
|
||||||
<a id="end-session" href="$Link(end)">Click here to end it.</a>
|
<a id="end-session" href="$Link(end)">Click here to end it.</a>
|
||||||
</p>
|
</p>
|
||||||
<% include TestSession_State %>
|
<% include TestSession_State %>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
<!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 -->
|
<!-- SUCCESS: DBNAME=$DatabaseName -->
|
||||||
<p>
|
<p>
|
||||||
Started testing session.
|
Started testing session.
|
||||||
@ -19,17 +33,6 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<% include TestSession_State %>
|
<% include TestSession_State %>
|
||||||
<form action="$Link(set)">
|
</div>
|
||||||
<p>
|
</body>
|
||||||
Enter a fixture file name to add it to the test session.
|
</html>
|
||||||
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>
|
|
Loading…
Reference in New Issue
Block a user