|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DNADesign\ElementalUserForms\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
|
6
|
|
|
use DNADesign\Elemental\Tests\Src\TestElement; |
|
7
|
|
|
use DNADesign\Elemental\Tests\Src\TestPage; |
|
8
|
|
|
use DNADesign\ElementalUserForms\Control\ElementFormController; |
|
9
|
|
|
use DNADesign\ElementalUserForms\Model\ElementForm; |
|
10
|
|
|
use SilverStripe\Dev\FunctionalTest; |
|
11
|
|
|
use SilverStripe\UserForms\Control\UserDefinedFormController; |
|
12
|
|
|
use SilverStripe\Versioned\Versioned; |
|
13
|
|
|
|
|
14
|
|
|
class ElementFormControllerTest extends FunctionalTest |
|
15
|
|
|
{ |
|
16
|
|
|
protected static $fixture_file = 'ElementFormTest.yml'; |
|
17
|
|
|
|
|
18
|
|
|
protected static $use_draft_site = true; |
|
19
|
|
|
|
|
20
|
|
|
protected static $extra_dataobjects = array( |
|
21
|
|
|
TestPage::class, |
|
22
|
|
|
TestElement::class |
|
23
|
|
|
); |
|
24
|
|
|
|
|
25
|
|
|
protected function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
Versioned::set_stage(Versioned::DRAFT); |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testElementFormRendering() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->logInWithPermission('ADMIN'); |
|
34
|
|
|
$page = $this->objFromFixture(TestPage::class, 'page1'); |
|
35
|
|
|
|
|
36
|
|
|
$element = $this->objFromFixture(ElementForm::class, 'formelement'); |
|
37
|
|
|
|
|
38
|
|
|
$response = $this->get($page->URLSegment); |
|
39
|
|
|
$formAction = sprintf('%s/element/%d/Form', $page->URLSegment, $element->ID); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertContains( |
|
42
|
|
|
$formAction, |
|
43
|
|
|
$response->getBody(), |
|
44
|
|
|
'Element forms are rendered through ElementalArea templates' |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testElementFormSubmission() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->logInWithPermission('ADMIN'); |
|
51
|
|
|
$page = $this->objFromFixture(TestPage::class, 'page1'); |
|
52
|
|
|
|
|
53
|
|
|
$element = $this->objFromFixture(TestElement::class, 'element1'); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
$response = $this->get($page->URLSegment); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$response = $this->submitForm('UserForm_Form_2', 'action_process', array('TestValue' => 'Updated')); |
|
58
|
|
|
$this->assertContains( |
|
59
|
|
|
'received your submission', |
|
60
|
|
|
$response->getBody(), |
|
61
|
|
|
'Form values are submitted to correct element form' |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testUserFormControllerInitIsCalled() |
|
66
|
|
|
{ |
|
67
|
|
|
$userFormControllerMock = $this->getMockBuilder(UserDefinedFormController::class) |
|
68
|
|
|
->setMethods(['doInit']) |
|
69
|
|
|
->getMock(); |
|
70
|
|
|
|
|
71
|
|
|
$userFormControllerMock->expects($this->once())->method('doInit'); |
|
72
|
|
|
|
|
73
|
|
|
$controller = new ElementFormController(new BaseElement); |
|
74
|
|
|
$controller->getRequest()->setSession($this->session()); |
|
75
|
|
|
$controller->setUserFormController($userFormControllerMock); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertSame($userFormControllerMock, $controller->getUserFormController()); |
|
78
|
|
|
$controller->doInit(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|