Completed
Pull Request — master (#12)
by Simon
01:19
created

testPasswordProtectedPartial()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Firesphere\PartialUserforms\Tests;
4
5
use Firesphere\PartialUserforms\Models\PartialFormSubmission;
6
use SilverStripe\Dev\FunctionalTest;
7
use SilverStripe\UserForms\Model\UserDefinedForm;
8
9
/**
10
 * Class PartialUserFormControllerTest
11
 * @package Firesphere\PartialUserforms\Tests
12
 */
13
class PartialUserFormControllerTest extends FunctionalTest
14
{
15
    /**
16
     * @var string
17
     */
18
    protected static $fixture_file = '../fixtures/partialformtest.yml';
19
20
    public function testPartialPage()
21
    {
22
        $result = $this->get("partial");
23
        $this->assertEquals(404, $result->getStatusCode());
24
    }
25
26
    /**
27
     * @todo
28
     */
29
    public function testPartialValidKeyToken()
30
    {
31
        $this->markTestSkipped('Revisit and set up themes for testing');
32
33
        $token = 'q1w2e3r4t5y6u7i8';
34
        // No Parent
35
        $key = singleton(PartialFormSubmission::class)->generateKey($token);
36
        $result = $this->get("partial/{$key}/{$token}");
37
        $this->assertEquals(404, $result->getStatusCode());
38
39
        // Partial with UserDefinedForm
40
        $key = $this->objFromFixture(PartialFormSubmission::class, 'submission1')->generateKey($token);
41
        $result = $this->get("partial/{$key}/{$token}");
42
        $this->assertEquals(200, $result->getStatusCode());
43
        $this->assertContains('Field 1', $result->getBody());
44
    }
45
46
    public function testPartialInvalidToken()
47
    {
48
        $token = 'abcdef';
49
        $key = singleton(PartialFormSubmission::class)->generateKey($token);
50
51
        $result = $this->get("partial/{$key}/{$token}");
52
        $this->assertEquals(404, $result->getStatusCode());
53
    }
54
55
    public function testPartialInvalidKey()
56
    {
57
        $token = 'e6b27462211e1711';
58
        $key = 'abcdef';
59
60
        $result = $this->get("partial/{$key}/{$token}");
61
        $this->assertEquals(404, $result->getStatusCode());
62
63
        $token = 'qwerty';
64
        $key = 'abcdef';
65
66
        $result = $this->get("partial/{$key}/{$token}");
67
        $this->assertEquals(404, $result->getStatusCode());
68
    }
69
70
    public function testPasswordProtectedPartial()
71
    {
72
        $token = 'q1w2e3r4t5y6u7i8';
73
        // Partial with UserDefinedForm
74
        $submission = $this->objFromFixture(PartialFormSubmission::class, 'submission1');
75
        /** @var UserDefinedForm $parent */
76
        $parent = $submission->Parent();
77
        $parent->PasswordProtected = true;
78
        $parent->write();
79
        $parent->publishRecursive();
80
        $key = $submission->generateKey($token);
81
        $result = $this->get("partial/{$key}/{$token}");
82
        // Be redirected to the Password form
83
        $formOpeningTag = '<form id="PasswordForm_getForm" action="/verify/getForm" method="post" enctype="application/x-www-form-urlencoded" class="userform">';
84
        $this->assertContains($formOpeningTag, $result->getBody());
85
    }
86
87
    public function setUp()
88
    {
89
        parent::setUp();
90
        $this->objFromFixture(UserDefinedForm::class, 'form1')->publishRecursive();
91
    }
92
}
93