FIX regression testing fixes

This commit is contained in:
Franco Springveldt 2017-09-11 15:25:16 +12:00
parent 49610f2ce4
commit 34970c754f
6 changed files with 23 additions and 41 deletions

View File

@ -180,7 +180,7 @@ abstract class MultiForm extends Form
// Disable security token - we tie a form to a session ID instead
$this->disableSecurityToken();
$this->config()->merge('ignored_fields', $getVar);
$this->config()->merge('ignored_fields', [$getVar]);
}
/**
@ -220,7 +220,7 @@ abstract class MultiForm extends Form
// Check if there was a start step defined on the subclass of MultiForm
if (!isset($startStepClass)) {
user_error(
'MultiForm::init(): Please define a $start_step on ' . $this->class,
'MultiForm::init(): Please define a $start_step on ' . static::class,
E_USER_ERROR
);
}
@ -302,13 +302,9 @@ abstract class MultiForm extends Form
// If there was no session found, create a new one instead
if (!$this->session) {
$this->session = MultiFormSession::create();
}
// Create encrypted identification to the session instance if it doesn't exist
if (!$this->session->Hash) {
$this->session->Hash = sha1($this->session->ID . '-' . microtime());
$this->session->write();
$session = MultiFormSession::create();
$session->write();
$this->session = $session;
}
}
@ -433,30 +429,6 @@ abstract class MultiForm extends Form
return $actions;
}
/**
* Return a rendered version of this form, with a specific template.
* Looks through the step ancestory templates (MultiFormStep, current step
* subclass template) to see if one is available to render the form with. If
* any of those don't exist, look for a default Form template to render
* with instead.
*
* @return SSViewer object to render the template with
*/
public function forTemplate()
{
$return = $this->renderWith([
$this->getCurrentStep()->class,
'MultiFormStep',
$this->class,
'MultiForm',
'Form'
]);
$this->clearMessage();
return $return;
}
/**
* This method saves the data on the final step, after submitting.
* It should always be overloaded with parent::finish($data, $form)

View File

@ -78,4 +78,14 @@ class MultiFormSession extends DataObject
parent::onBeforeDelete();
}
public function onAfterWrite()
{
parent::onAfterWrite();
// Create encrypted identification to the session instance if it doesn't exist
if (!$this->Hash) {
$this->Hash = sha1($this->ID . '-' . microtime());
$this->write();
}
}
}

View File

@ -63,7 +63,7 @@ class MultiFormStep extends DataObject
*
* @var boolean
*/
protected static $can_go_back = true;
private static $can_go_back = true;
/**
* Title of this step.
@ -249,7 +249,7 @@ class MultiFormStep extends DataObject
if (!isset($nextSteps)) {
user_error(
'MultiFormStep->getNextStep(): Please define at least one $next_steps on '
. $this->class,
. static::class,
E_USER_ERROR
);
}
@ -314,8 +314,8 @@ class MultiFormStep extends DataObject
$step->setForm($this->form);
if ($step->getNextStep()) {
if ($step->getNextStep() == $this->class) {
return $step->class;
if ($step->getNextStep() == static::class) {
return get_class($step);
}
}
}
@ -417,7 +417,7 @@ class MultiFormStep extends DataObject
*/
public function isCurrentStep()
{
return ($this->class == $this->getSession()->CurrentStep()->class) ? true : false;
return (static::class == get_class($this->getSession()->CurrentStep())) ? true : false;
}
/**

View File

@ -4,7 +4,7 @@
<% if $LinkingMode = current %>
<% else %>
<% if $ID %>
<a href="{$Top.URLSegment}/?${Top.GetVar}={$SessionID}&amp;StepID={$ID}">
<a href="{$Top.URLSegment}/?{$Top.GetVar}={$Session.Hash}&amp;StepID={$ID}">
<% end_if %>
<% end_if %>

View File

@ -1 +1 @@
<p><%t SilverStripe\\MultiForm\\MultiForm.ProgressPercent "You've completed {percent}% ({completedSteps}/{totalSteps})" percent=$CompletedPercent.Nice completedSteps=$CompletedStepCount totalSteps$TotalStepCount %></p>
<p><%t SilverStripe\\MultiForm\\MultiForm.ProgressPercent "You've completed {percent}% ({completedSteps}/{totalSteps})" percent=$CompletedPercent.Nice completedSteps=$CompletedStepCount totalSteps=$TotalStepCount %></p>

View File

@ -93,7 +93,7 @@ class MultiFormTest extends FunctionalTest
public function testParentForm()
{
$currentStep = $this->form->getCurrentStep();
$this->assertEquals($currentStep->getForm()->class, $this->form->class);
$this->assertEquals(get_class($currentStep->getForm()), get_class($this->form));
}
public function testTotalStepCount()