|
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\FunctionalTest; |
|
12
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
13
|
|
|
|
|
14
|
|
|
class PartialUserFormVerifyControllerTest extends FunctionalTest |
|
15
|
|
|
{ |
|
16
|
|
|
protected static $fixture_file = '../fixtures/partialformtest.yml'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @expectedException \SilverStripe\Control\HTTPResponse_Exception |
|
20
|
|
|
*/ |
|
21
|
|
|
public function testInit() |
|
22
|
|
|
{ |
|
23
|
|
|
$request = new NullHTTPRequest(); |
|
24
|
|
|
$session = new Session(['hi' => 'bye']); |
|
25
|
|
|
$request->setSession($session); |
|
26
|
|
|
$controller = PartialUserFormVerifyController::create(); |
|
27
|
|
|
$controller->setRequest($request); |
|
28
|
|
|
|
|
29
|
|
|
$controller->init(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testInitSuccess() |
|
33
|
|
|
{ |
|
34
|
|
|
$partialForm = $this->objFromFixture(PartialFormSubmission::class, 'submission1'); |
|
35
|
|
|
$request = new NullHTTPRequest(); |
|
36
|
|
|
$session = new Session(['hi' => 'bye', PartialSubmissionController::SESSION_KEY => $partialForm->ID]); |
|
37
|
|
|
$request->setSession($session); |
|
38
|
|
|
$controller = PartialUserFormVerifyController::create(); |
|
39
|
|
|
$controller->setRequest($request); |
|
40
|
|
|
|
|
41
|
|
|
$controller->init(); |
|
42
|
|
|
$this->assertEquals(200, $controller->getResponse()->getStatusCode()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testDoValidate() |
|
46
|
|
|
{ |
|
47
|
|
|
$request = new NullHTTPRequest(); |
|
48
|
|
|
/** @var PartialFormSubmission $partialForm */ |
|
49
|
|
|
$partialForm = $this->objFromFixture(PartialFormSubmission::class, 'submission1'); |
|
50
|
|
|
$parent = $partialForm->getParent(); |
|
51
|
|
|
$parent->PasswordProtected = true; |
|
52
|
|
|
$parent->write(); |
|
|
|
|
|
|
53
|
|
|
$parent->publishRecursive(); |
|
54
|
|
|
$partialForm->ParentID = $parent->ID; |
|
|
|
|
|
|
55
|
|
|
$partialForm->write(); |
|
56
|
|
|
$session = new Session(['hi' => 'bye', PartialSubmissionController::SESSION_KEY => $partialForm->ID]); |
|
57
|
|
|
$request->setSession($session); |
|
58
|
|
|
$controller = PartialUserFormVerifyController::create(); |
|
59
|
|
|
$controller->setRequest($request); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertNotNull($partialForm->Password); |
|
62
|
|
|
|
|
63
|
|
|
$testPwd = hash_pbkdf2('SHA256', '1234567890', $partialForm->TokenSalt, 1000); |
|
64
|
|
|
|
|
65
|
|
|
$partialForm->Password = $testPwd; |
|
66
|
|
|
$partialForm->write(); |
|
67
|
|
|
|
|
68
|
|
|
$controller->init(); |
|
69
|
|
|
$form = new PasswordForm($controller, __FUNCTION__); |
|
70
|
|
|
$result = $controller->doValidate(['Password' => '1234567890'], $form); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals($partialForm->ID, $session->get('PartialFormSession')); |
|
73
|
|
|
$this->assertContains('/partial/', $result->getHeader('Location')); |
|
74
|
|
|
|
|
75
|
|
|
$controller = new PartialUserFormVerifyController(); |
|
76
|
|
|
$controller->setRequest($request); |
|
77
|
|
|
$controller->init(); |
|
78
|
|
|
$result = $controller->doValidate(['Password' => '0987654321'], $form); |
|
79
|
|
|
|
|
80
|
|
|
// It uses redirect back, so it's unclear what the 'back' is at this stage |
|
81
|
|
|
$this->assertNotContains('/partial', $result->getHeader('Location')); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
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: