mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
BUGFIX: fixes for 3.0 unit tests. Ensure form is not shown if no fields in the list, Prevent nested with getSubmissions().
This commit is contained in:
parent
ec6045d7e1
commit
3256663cad
@ -12,35 +12,41 @@ class SubmittedFormReportField extends FormField {
|
||||
Requirements::javascript("userforms/javascript/UserForm.js");
|
||||
return $this->renderWith("SubmittedFormReportField");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the submissions from the site
|
||||
*
|
||||
* @return ComponentSet
|
||||
* @return PaginatedList
|
||||
*/
|
||||
public function Submissions() {
|
||||
$pageStart = isset($_REQUEST['start']) && is_numeric($_REQUEST['start']) ? $_REQUEST['start'] : 0;
|
||||
$pageLength = 10;
|
||||
|
||||
$items = $this->form->getRecord()->getComponents('Submissions', null, "\"Created\" DESC")->limit($pageStart,$pageLength);
|
||||
$formId = $this->form->getRecord()->ID;
|
||||
|
||||
foreach(DB::query("SELECT COUNT(*) AS \"CountRows\" FROM \"SubmittedForm\" WHERE \"ParentID\" = $formId") as $r) $totalCount = $r['CountRows'];
|
||||
public function getSubmissions($start = 0) {
|
||||
$record = $this->form->getRecord();
|
||||
$submissions = $record->getComponents('Submissions', null, "\"Created\" DESC");
|
||||
|
||||
//$items->setPageLimits($pageStart, $pageLength, $totalCount);
|
||||
$items->NextStart = $pageStart + $pageLength;
|
||||
$items->PrevStart = $pageStart - $pageLength;
|
||||
$items->Start = $pageStart;
|
||||
$items->StartPlusOffset = $pageStart+$pageLength;
|
||||
$items->TotalCount = $totalCount;
|
||||
|
||||
return $items;
|
||||
$query = DB::query(sprintf("
|
||||
SELECT COUNT(*) AS \"CountRows\"
|
||||
FROM \"SubmittedForm\"
|
||||
WHERE \"ParentID\" = '%d'", $record->ID
|
||||
));
|
||||
|
||||
foreach($query as $r) $totalCount = $r['CountRows'];
|
||||
|
||||
$list = new PaginatedList($submissions);
|
||||
$list->setPageStart($start);
|
||||
$list->setPageLength(10);
|
||||
$list->setTotalItems($totalCount);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getSubmissions() {
|
||||
return $this->customise(array(
|
||||
'Submissions' => $this->Submissions()
|
||||
))->renderWith(array('SubmittedFormReportField'));
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMoreSubmissions() {
|
||||
$start = ($start = $this->request->getVar('start')) ? (int) $start : 0;
|
||||
|
||||
return $this->customise(new ArrayData(array(
|
||||
'Submissions' => $this->getSubmissions($start)
|
||||
)))->renderWith(array('SubmittedFormReportField'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -331,7 +331,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
*/
|
||||
public function Form() {
|
||||
$fields = $this->getFormFields();
|
||||
if(!$fields) return false;
|
||||
if(!$fields || !$fields->exists()) return false;
|
||||
|
||||
$actions = $this->getFormActions();
|
||||
|
||||
|
@ -6,36 +6,36 @@
|
||||
<li><a href="{$Top.Link}/deletesubmissions/?id={$RecordID}" class="deleteAllSubmissions"><% _t('DELETEALLSUBMISSIONS', 'Delete All Submissions') %></a></li>
|
||||
</ul>
|
||||
|
||||
<% control Submissions %>
|
||||
<% loop Submissions %>
|
||||
<div class="userform-submission">
|
||||
<h4><% _t('SUBMITTED', 'Submitted at') %> $Created.Nice. <a href="{$Top.Link}/deletesubmission/?id={$ID}" class="deleteSubmission"><% _t('DELETESUBMISSION', 'Delete Submission') %></a></h4>
|
||||
|
||||
<table>
|
||||
<% control Values %>
|
||||
<% loop Values %>
|
||||
<tr>
|
||||
<td class="field">$Title</td>
|
||||
<td class="value">$FormattedValue</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
</table>
|
||||
</div>
|
||||
<% end_control %>
|
||||
<% end_loop %>
|
||||
|
||||
<% if Submissions.MoreThanOnePage %>
|
||||
<div class="userforms-submissions-pagination">
|
||||
|
||||
<% if Submissions.NotFirstPage %>
|
||||
<a class="prev" href="javascript:void(0)" onclick="jQuery('#userforms-submissions').parent().load(jQuery('base').get(0).href+'/{$Top.Link}/getSubmissions/?start={$Submissions.PrevStart}');" title="View the previous page">Previous page</a>
|
||||
<a class="prev" href="javascript:void(0)" onclick="jQuery('#userforms-submissions').parent().load(jQuery('base').get(0).href+'/{$Top.Link}/getMoreSubmissions/?start={$Submissions.PrevStart}');" title="View the previous page">Previous page</a>
|
||||
<% end_if %>
|
||||
|
||||
<span>Viewing rows $Submissions.Start - $Submissions.StartPlusOffset of $Submissions.TotalCount rows</span>
|
||||
|
||||
<% if Submissions.NotLastPage %>
|
||||
<a class="next" href="javascript:void(0)" onclick="jQuery('#userforms-submissions').parent().load(jQuery('base').get(0).href+'/{$Top.Link}/getSubmissions/?start={$Submissions.NextStart}');" title="View the next page">Next page</a>
|
||||
<a class="next" href="javascript:void(0)" onclick="jQuery('#userforms-submissions').parent().load(jQuery('base').get(0).href+'/{$Top.Link}/getMoreSubmissions/?start={$Submissions.NextStart}');" title="View the next page">Next page</a>
|
||||
<% end_if %>
|
||||
</div>
|
||||
<% end_if %>
|
||||
<% else %>
|
||||
<p class="userforms-nosubmissions" <% if Submissions %>style="display: none"<% end_if %>><% _t('NOSUBMISSIONS', 'No Submissions') %></p>
|
||||
<% end_if %>
|
||||
|
||||
<p class="userforms-nosubmissions" <% if Submissions %>style="display: none"<% end_if %>><% _t('NOSUBMISSIONS', 'No Submissions') %></p>
|
||||
</div>
|
||||
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package userforms
|
||||
*/
|
||||
class SubmittedFormTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'userforms/tests/SubmittedFormTest.yml';
|
||||
@ -16,23 +19,18 @@ class SubmittedFormTest extends FunctionalTest {
|
||||
}
|
||||
|
||||
function testSubmissions() {
|
||||
$submissions = $this->field->Submissions();
|
||||
|
||||
// test with 11 submissions. Should be over 2 pages. 10 per page.
|
||||
// @todo add tests to ensure the order
|
||||
$this->assertEquals($submissions->Count(), 10);
|
||||
$submissions = $this->field->getSubmissions();
|
||||
|
||||
$this->assertEquals($submissions->TotalPages(), 2);
|
||||
$this->assertEquals($submissions->TotalItems(), 11);
|
||||
$this->assertEquals($submissions->getTotalItems(), 11);
|
||||
}
|
||||
|
||||
function testGetSubmissionns() {
|
||||
$template = $this->field->getSubmissions();
|
||||
|
||||
function testGetMoreSubmissions() {
|
||||
$template = $this->field->getMoreSubmissions();
|
||||
$parser = new CSSContentParser($template);
|
||||
|
||||
// check to ensure that the pagination exists
|
||||
$pagination = $parser->getBySelector('.userforms-submissions-pagination');
|
||||
|
||||
|
||||
$this->assertEquals(str_replace("\n", ' ',(string) $pagination[0]->span), "Viewing rows 0 - 10 of 11 rows");
|
||||
$this->assertEquals(str_replace("\n", ' ',(string) $pagination[0]->a), "Next page");
|
||||
|
||||
|
@ -10,8 +10,11 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
|
||||
|
||||
function testRollbackToVersion() {
|
||||
// @todo rolling back functionality (eg fields) is not supported yet
|
||||
$this->markTestSkipped(
|
||||
'UserDefinedForm::rollback() has not been implemented completely'
|
||||
);
|
||||
|
||||
// @todo
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
@ -125,7 +128,7 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
|
||||
// should not have published the dropdown
|
||||
$liveDropdown = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $dropdown->ID");
|
||||
$this->assertFalse($liveDropdown);
|
||||
$this->assertNull($liveDropdown);
|
||||
|
||||
// when publishing it should have added it
|
||||
$form->doPublish();
|
||||
@ -164,7 +167,7 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
// unpublish
|
||||
$form->doUnpublish();
|
||||
|
||||
$this->assertFalse(Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"));
|
||||
$this->assertNull(Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"));
|
||||
$this->assertEquals(DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value(), 0);
|
||||
|
||||
}
|
||||
@ -172,35 +175,27 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
function testDoRevertToLive() {
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
$form->SubmitButtonText = 'Button Text';
|
||||
$form->doPublish();
|
||||
$text = $form->Fields()->First();
|
||||
|
||||
$form->SubmitButtonText = 'Edited Button Text';
|
||||
$form->write();
|
||||
$field = $form->Fields()->First();
|
||||
|
||||
$text->Title = 'Edited title';
|
||||
$text->write();
|
||||
$field->Title = 'Title';
|
||||
$field->write();
|
||||
|
||||
$form->doPublish();
|
||||
|
||||
$field->Title = 'Edited title';
|
||||
$field->write();
|
||||
|
||||
// check that the published version is not updated
|
||||
$liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
|
||||
|
||||
$revertTo = $liveText->Title;
|
||||
|
||||
$this->assertFalse($revertTo == $text->Title);
|
||||
$live = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $field->ID");
|
||||
$this->assertEquals('Title', $live->Title);
|
||||
|
||||
// revert back to the live data
|
||||
$form->doRevertToLive();
|
||||
$form->flushCache();
|
||||
|
||||
$check = Versioned::get_one_by_stage("EditableFormField", "Stage", "\"EditableFormField\".\"ID\" = $text->ID");
|
||||
$check = Versioned::get_one_by_stage("EditableFormField", "Stage", "\"EditableFormField\".\"ID\" = $field->ID");
|
||||
|
||||
$this->assertEquals($check->Title, $revertTo);
|
||||
|
||||
// check the edited buttoned
|
||||
$liveForm = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
|
||||
$revertedForm = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
|
||||
|
||||
$this->assertEquals($liveForm->SubmitButtonText, $revertedForm->SubmitButtonText);
|
||||
$this->assertEquals('Title', $check->Title);
|
||||
}
|
||||
|
||||
function testDuplicatingForm() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user