Completed
Pull Request — master (#16)
by Simon
08:02
created

PartialUserFormControllerTest::testPartialValidKeyToken()   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
    protected static $fixture_file = '../fixtures/partialformtest.yml';
16
17
    public function testPartialPage()
18
    {
19
        $result = $this->get("partial");
20
        $this->assertEquals(404, $result->getStatusCode());
21
    }
22
23
    /**
24
     * @todo
25
     */
26
    public function testPartialValidKeyToken()
27
    {
28
        $this->markTestSkipped('Revisit and set up themes for testing');
29
30
        $token = 'q1w2e3r4t5y6u7i8';
31
        // No Parent
32
        $key = singleton(PartialFormSubmission::class)->generateKey($token);
33
        $result = $this->get("partial/{$key}/{$token}");
34
        $this->assertEquals(404, $result->getStatusCode());
35
36
        // Partial with UserDefinedForm
37
        $key = $this->objFromFixture(PartialFormSubmission::class, 'submission1')->generateKey($token);
38
        $result = $this->get("partial/{$key}/{$token}");
39
        $this->assertEquals(200, $result->getStatusCode());
40
        $this->assertContains('Field 1', $result->getBody());
41
    }
42
43
    public function testPartialInvalidToken()
44
    {
45
        $token = 'abcdef';
46
        $key = singleton(PartialFormSubmission::class)->generateKey($token);
47
48
        $result = $this->get("partial/{$key}/{$token}");
49
        $this->assertEquals(404, $result->getStatusCode());
50
    }
51
52
    public function testPartialInvalidKey()
53
    {
54
        $token = 'e6b27462211e1711';
55
        $key = 'abcdef';
56
57
        $result = $this->get("partial/{$key}/{$token}");
58
        $this->assertEquals(404, $result->getStatusCode());
59
60
        $token = 'qwerty';
61
        $key = 'abcdef';
62
63
        $result = $this->get("partial/{$key}/{$token}");
64
        $this->assertEquals(404, $result->getStatusCode());
65
    }
66
67
    public function setUp()
68
    {
69
        parent::setUp();
70
        $this->objFromFixture(UserDefinedForm::class, 'form1')->publishRecursive();
71
    }
72
}
73