mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Remove test for old submissions tab
This commit is contained in:
parent
a8ca0184c3
commit
b3805d2a8b
@ -1,155 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package userforms
|
|
||||||
*/
|
|
||||||
class SubmittedFormTest extends FunctionalTest {
|
|
||||||
|
|
||||||
static $fixture_file = 'userforms/tests/SubmittedFormTest.yml';
|
|
||||||
|
|
||||||
protected $controller, $form, $page, $field;
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
parent::setUp();
|
|
||||||
$this->page = $this->objFromFixture('UserDefinedForm', 'popular-form');
|
|
||||||
|
|
||||||
$this->controller = new SubmittedFormTest_Controller($this->page);
|
|
||||||
$this->form = $this->controller->Form();
|
|
||||||
$this->field = $this->form->Fields()->dataFieldByName('Report');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmissions() {
|
|
||||||
$submissions = $this->field->getSubmissions();
|
|
||||||
|
|
||||||
$this->assertEquals($submissions->TotalPages(), 2);
|
|
||||||
$this->assertEquals($submissions->getTotalItems(), 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
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), "Pages:");
|
|
||||||
$this->assertEquals(str_replace("\n", ' ',(string) $pagination[0]->a), "2");
|
|
||||||
|
|
||||||
// ensure the actions exist
|
|
||||||
$actions = $parser->getBySelector('.userforms-submission-actions');
|
|
||||||
$this->assertEquals(count($actions[0]->li), 2);
|
|
||||||
|
|
||||||
// submissions
|
|
||||||
$submissions = $parser->getBySelector('.userform-submission');
|
|
||||||
$this->assertEquals(count($submissions), 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCSVExport() {
|
|
||||||
$export = $this->field->export($this->page->ID);
|
|
||||||
|
|
||||||
// Pretend we are opening via file
|
|
||||||
$fp = fopen('php://memory', 'w+');
|
|
||||||
fwrite($fp, $export);
|
|
||||||
rewind($fp);
|
|
||||||
|
|
||||||
$data = array();
|
|
||||||
while($data[] = fgetcsv($fp));
|
|
||||||
array_pop($data);
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
// Check the headers are fine and include every legacy field. They should also be ordered
|
|
||||||
// according to the latest form layout.
|
|
||||||
$this->assertEquals($data[0], array(
|
|
||||||
'First', 'Submitted Title 2', 'Submitted Title', 'Submitted'
|
|
||||||
));
|
|
||||||
|
|
||||||
// Check the number of records in the export
|
|
||||||
$this->assertEquals(count($data), 12);
|
|
||||||
|
|
||||||
// Make sure the number of columns matches
|
|
||||||
$this->assertEquals(count($data[1]), 4);
|
|
||||||
$this->assertEquals(count($data[2]), 4);
|
|
||||||
$this->assertEquals(count($data[3]), 4);
|
|
||||||
$this->assertEquals(count($data[11]), 4);
|
|
||||||
|
|
||||||
// Specific value tests
|
|
||||||
$this->assertEquals($data[1][1], 'quote " and comma , test');
|
|
||||||
$this->assertEquals($data[1][2], 'Value 1');
|
|
||||||
$this->assertEquals($data[2][1], 'Value 2');
|
|
||||||
|
|
||||||
$this->assertEquals($data[3][1], "multi\nline\ntest");
|
|
||||||
|
|
||||||
$this->assertEquals($data[11][0], 'First');
|
|
||||||
$this->assertEquals($data[11][1], 'Second');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testdeletesubmission() {
|
|
||||||
$submission = $this->objFromFixture('SubmittedForm', 'long-1');
|
|
||||||
|
|
||||||
$count = $this->page->Submissions()->Count();
|
|
||||||
$this->assertTrue($this->field->deletesubmission($submission->ID));
|
|
||||||
|
|
||||||
$this->assertEquals($count - 1, $this->page->Submissions()->Count());
|
|
||||||
|
|
||||||
$this->assertFalse($this->field->deletesubmission(-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testdeletesubmissions() {
|
|
||||||
$this->assertTrue($this->field->deletesubmissions($this->page->ID));
|
|
||||||
|
|
||||||
$this->assertEquals($this->page->Submissions()->Count(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOnBeforeDeleteOfForm() {
|
|
||||||
$field = $this->objFromFixture('SubmittedFormField', 'submitted-form-field-1');
|
|
||||||
$form = $field->Parent();
|
|
||||||
|
|
||||||
$this->assertEquals($form->Values()->Count(), 2);
|
|
||||||
$form->delete();
|
|
||||||
|
|
||||||
$fields = DataObject::get('SubmittedFormField', "\"ParentID\" = '$form->ID'");
|
|
||||||
|
|
||||||
$this->assertEquals(array(), $fields->toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetFormattedValue() {
|
|
||||||
$field = $this->objFromFixture('SubmittedFormField', 'submitted-form-field-1');
|
|
||||||
|
|
||||||
$this->assertEquals('1', $field->getFormattedValue());
|
|
||||||
|
|
||||||
$textarea = $this->objFromFixture('SubmittedFormField', 'submitted-textarea-1');
|
|
||||||
|
|
||||||
$text = "I am here testing<br />\nTesting until I cannot<br />\nI love my testing";
|
|
||||||
|
|
||||||
$this->assertEquals($text, $textarea->getFormattedValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFileGetLink() {
|
|
||||||
$field = $this->objFromFixture('SubmittedFileField', 'submitted-file-1');
|
|
||||||
|
|
||||||
// @todo add checks for if no file can be downloaded
|
|
||||||
$this->assertContains('my-file.jpg', $field->getLink());
|
|
||||||
|
|
||||||
}
|
|
||||||
function testFileGetFormattedValue() {
|
|
||||||
$field = $this->objFromFixture('SubmittedFileField', 'submitted-file-1');
|
|
||||||
|
|
||||||
// @todo add checks for if no file can be downloaded
|
|
||||||
$this->assertContains('Download File', $field->getFormattedValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class SubmittedFormTest_Controller extends ContentController {
|
|
||||||
|
|
||||||
function Form() {
|
|
||||||
$form = new Form($this, 'Form', new FieldList(new SubmittedFormReportField('Report')), new FieldList(new FormAction('Submit')));
|
|
||||||
|
|
||||||
$form->loadDataFrom($this->data());
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function forTemplate() {
|
|
||||||
return $this->renderWith(array('ContentController'));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,111 +0,0 @@
|
|||||||
SubmittedForm:
|
|
||||||
submitted-form-1:
|
|
||||||
ID: 1
|
|
||||||
submitted-form-2:
|
|
||||||
ID: 2
|
|
||||||
long-1:
|
|
||||||
ID: 3
|
|
||||||
long-2:
|
|
||||||
ID: 4
|
|
||||||
long-3:
|
|
||||||
ID: 5
|
|
||||||
long-4:
|
|
||||||
ID: 6
|
|
||||||
long-5:
|
|
||||||
ID: 7
|
|
||||||
long-6:
|
|
||||||
ID: 8
|
|
||||||
long-7:
|
|
||||||
ID: 9
|
|
||||||
long-8:
|
|
||||||
ID: 10
|
|
||||||
long-9:
|
|
||||||
ID: 11
|
|
||||||
long-10:
|
|
||||||
ID: 12
|
|
||||||
long-11:
|
|
||||||
ID: 13
|
|
||||||
long-12:
|
|
||||||
ID: 14
|
|
||||||
|
|
||||||
UserDefinedForm:
|
|
||||||
form-page:
|
|
||||||
Title: Form
|
|
||||||
Submissions: =>SubmittedForm.submitted-form-1
|
|
||||||
|
|
||||||
form-page-2:
|
|
||||||
Title: Second Form
|
|
||||||
Submissions: =>SubmittedForm.submitted-form-2
|
|
||||||
|
|
||||||
popular-form:
|
|
||||||
Title: Popular Form
|
|
||||||
Submissions: =>SubmittedForm.long-1, =>SubmittedForm.long-2, =>SubmittedForm.long-3, =>SubmittedForm.long-4, =>SubmittedForm.long-5, =>SubmittedForm.long-6, =>SubmittedForm.long-7, =>SubmittedForm.long-8, =>SubmittedForm.long-9, =>SubmittedForm.long-10, =>SubmittedForm.long-11
|
|
||||||
|
|
||||||
File:
|
|
||||||
uploaded-file:
|
|
||||||
Name: My File
|
|
||||||
Filename: my-file.jpg
|
|
||||||
|
|
||||||
SubmittedFormField:
|
|
||||||
submitted-form-field-1:
|
|
||||||
Parent: =>SubmittedForm.submitted-form-1
|
|
||||||
Name: field-1
|
|
||||||
Title: Field 1
|
|
||||||
Value: 1
|
|
||||||
|
|
||||||
submitted-textarea-1:
|
|
||||||
Parent: =>SubmittedForm.submitted-form-2
|
|
||||||
Name: field 2
|
|
||||||
Title: Field 2
|
|
||||||
Value: |
|
|
||||||
I am here testing
|
|
||||||
Testing until I cannot
|
|
||||||
I love my testing
|
|
||||||
|
|
||||||
long-submitted-1a:
|
|
||||||
Name: Submitted Name
|
|
||||||
Title: Submitted Title
|
|
||||||
Parent: =>SubmittedForm.long-1
|
|
||||||
Value: Value 1
|
|
||||||
|
|
||||||
long-submitted-1b:
|
|
||||||
Name: Submitted Name 2
|
|
||||||
Title: Submitted Title 2
|
|
||||||
Parent: =>SubmittedForm.long-1
|
|
||||||
Value: 'quote " and comma , test'
|
|
||||||
|
|
||||||
long-submitted-2:
|
|
||||||
Parent: =>SubmittedForm.long-2
|
|
||||||
Name: Submitted Name 2
|
|
||||||
Title: Submitted Title 2
|
|
||||||
Value: Value 2
|
|
||||||
|
|
||||||
long-submitted-3:
|
|
||||||
Name: Submitted Name 2
|
|
||||||
Title: Submitted Title 2
|
|
||||||
Parent: =>SubmittedForm.long-3
|
|
||||||
Value: |
|
|
||||||
multi
|
|
||||||
line
|
|
||||||
test
|
|
||||||
|
|
||||||
long-submitted-11a:
|
|
||||||
Parent: =>SubmittedForm.long-11
|
|
||||||
Name: First
|
|
||||||
Title: First
|
|
||||||
Value: First
|
|
||||||
|
|
||||||
long-submitted-11b:
|
|
||||||
Parent: =>SubmittedForm.long-11
|
|
||||||
Name: Submitted Name 2
|
|
||||||
Title: Submitted Title 2
|
|
||||||
Value: Second
|
|
||||||
|
|
||||||
SubmittedFileField:
|
|
||||||
submitted-file-1:
|
|
||||||
Name: File Field
|
|
||||||
Title: File
|
|
||||||
Parent: =>SubmittedForm.submitted-form-1
|
|
||||||
UploadedFile: =>File.uploaded-file
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user