1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Firesphere\PartialUserforms\Tests; |
4
|
|
|
|
5
|
|
|
use Firesphere\PartialUserforms\Controllers\PartialSubmissionController; |
6
|
|
|
use Firesphere\PartialUserforms\Controllers\PartialUserFormVerifyController; |
7
|
|
|
use Firesphere\PartialUserforms\Forms\PasswordForm; |
8
|
|
|
use Firesphere\PartialUserforms\Models\PartialFormSubmission; |
9
|
|
|
use SilverStripe\Control\NullHTTPRequest; |
10
|
|
|
use SilverStripe\Control\Session; |
11
|
|
|
use SilverStripe\Dev\Debug; |
12
|
|
|
use SilverStripe\Dev\SapphireTest; |
13
|
|
|
use SilverStripe\Forms\Form; |
14
|
|
|
use SilverStripe\UserForms\Model\UserDefinedForm; |
15
|
|
|
|
16
|
|
|
class PartialUserFormVerifyControllerTest extends SapphireTest |
17
|
|
|
{ |
18
|
|
|
protected static $fixture_file = '../fixtures/partialformtest.yml'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @expectedException \SilverStripe\Control\HTTPResponse_Exception |
22
|
|
|
*/ |
23
|
|
|
public function testInit() |
24
|
|
|
{ |
25
|
|
|
$request = new NullHTTPRequest(); |
26
|
|
|
$session = new Session(['hi' => 'bye']); |
27
|
|
|
$request->setSession($session); |
28
|
|
|
$controller = PartialUserFormVerifyController::create(); |
29
|
|
|
$controller->setRequest($request); |
30
|
|
|
|
31
|
|
|
$controller->init(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testInitSuccess() |
35
|
|
|
{ |
36
|
|
|
$partialForm = $this->objFromFixture(PartialFormSubmission::class, 'submission1'); |
37
|
|
|
$request = new NullHTTPRequest(); |
38
|
|
|
$session = new Session(['hi' => 'bye', PartialSubmissionController::SESSION_KEY => $partialForm->ID]); |
39
|
|
|
$request->setSession($session); |
40
|
|
|
$controller = PartialUserFormVerifyController::create(); |
41
|
|
|
$controller->setRequest($request); |
42
|
|
|
|
43
|
|
|
$controller->init(); |
44
|
|
|
$this->assertEquals(200, $controller->getResponse()->getStatusCode()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testDoValidate() |
48
|
|
|
{ |
49
|
|
|
$request = new NullHTTPRequest(); |
50
|
|
|
/** @var PartialFormSubmission $partialForm */ |
51
|
|
|
$partialForm = $this->objFromFixture(PartialFormSubmission::class, 'submission1'); |
52
|
|
|
$parent = $partialForm->getParent(); |
53
|
|
|
$parent->PasswordProtected = true; |
54
|
|
|
$parent->write(); |
|
|
|
|
55
|
|
|
$parent->publishRecursive(); |
56
|
|
|
$partialForm->ParentID = $parent->ID; |
|
|
|
|
57
|
|
|
$partialForm->write(); |
58
|
|
|
$session = new Session(['hi' => 'bye', PartialSubmissionController::SESSION_KEY => $partialForm->ID]); |
59
|
|
|
$request->setSession($session); |
60
|
|
|
$controller = PartialUserFormVerifyController::create(); |
61
|
|
|
$controller->setRequest($request); |
62
|
|
|
|
63
|
|
|
$this->assertNotNull($partialForm->Password); |
64
|
|
|
|
65
|
|
|
$testPwd = hash_pbkdf2('SHA256', '1234567890', $partialForm->TokenSalt, 1000); |
66
|
|
|
|
67
|
|
|
$partialForm->Password = $testPwd; |
68
|
|
|
$partialForm->write(); |
69
|
|
|
|
70
|
|
|
$controller->init(); |
71
|
|
|
$form = new PasswordForm($controller, __FUNCTION__); |
72
|
|
|
$result = $controller->doValidate(['Password' => '1234567890'], $form); |
73
|
|
|
|
74
|
|
|
$this->assertEquals($partialForm->ID, $session->get('PartialFormSession')); |
75
|
|
|
$this->assertContains('/partial/', $result->getHeader('Location')); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: