Completed
Push — master ( c07b10...3eba7c )
by Simon
13s
created

testPartialPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
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 PartialUserFormControllerFunctionalTest
11
 * @package Firesphere\PartialUserforms\Tests
12
 */
13
class PartialUserFormControllerFunctionalTest extends FunctionalTest
14
{
15
    /**
16
     * @var string
17
     */
18
    protected static $fixture_file = '../fixtures/partialformtest.yml';
19
20
    public function setUp()
21
    {
22
        parent::setUp();
23
24
        $this->objFromFixture(UserDefinedForm::class, 'form1')->publishRecursive();
25
    }
26
27
    public function testPartialPage()
28
    {
29
        $result = $this->get("partial");
30
        $this->assertEquals(404, $result->getStatusCode());
31
    }
32
33
    public function xtestPartialValidKeyToken()
34
    {
35
        $token = 'q1w2e3r4t5y6u7i8';
36
        // No Parent
37
        $key = singleton(PartialFormSubmission::class)->generateKey($token);
38
        $result = $this->get("partial/{$key}/{$token}");
39
        $this->assertEquals(404, $result->getStatusCode());
40
41
        // Partial with UserDefinedForm
42
        $key = $this->objFromFixture(PartialFormSubmission::class, 'submission1')->generateKey($token);
43
        $result = $this->get("partial/{$key}/{$token}");
44
        $this->assertEquals(200, $result->getStatusCode());
45
        $this->assertContains('Field 1', $result->getBody());
46
    }
47
48
    public function testPartialInvalidToken()
49
    {
50
        $token = 'abcdef';
51
        $key = singleton(PartialFormSubmission::class)->generateKey($token);
52
53
        $result = $this->get("partial/{$key}/{$token}");
54
        $this->assertEquals(404, $result->getStatusCode());
55
    }
56
57
    public function testPartialInvalidKey()
58
    {
59
        $token = 'e6b27462211e1711';
60
        $key = 'abcdef';
61
62
        $result = $this->get("partial/{$key}/{$token}");
63
        $this->assertEquals(404, $result->getStatusCode());
64
65
        $token = 'qwerty';
66
        $key = 'abcdef';
67
68
        $result = $this->get("partial/{$key}/{$token}");
69
        $this->assertEquals(404, $result->getStatusCode());
70
    }
71
}
72