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

PartialFileFieldSubmissionTest::testCanCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
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\PartialFileFieldSubmission;
6
use Firesphere\PartialUserforms\Models\PartialFormSubmission;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Security\DefaultAdminService;
9
use SilverStripe\Security\Security;
10
use SilverStripe\UserForms\Model\UserDefinedForm;
11
12
class PartialFileFieldSubmissionTest extends SapphireTest
13
{
14
15
    /**
16
     * @var PartialFileFieldSubmission
17
     */
18
    protected $field;
19
20 View Code Duplication
    public function testCanView()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $this->assertTrue($this->field->canView());
23
24
        $member = DefaultAdminService::singleton()->findOrCreateAdmin('[email protected]');
25
        Security::setCurrentUser($member);
26
27
        $this->assertTrue($this->field->canView($member));
28
    }
29
30 View Code Duplication
    public function testCanCreate()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        Security::setCurrentUser(null);
33
        $this->assertFalse($this->field->canCreate());
34
35
        $member = DefaultAdminService::singleton()->findOrCreateAdmin('[email protected]');
36
        Security::setCurrentUser($member);
37
38
        $this->assertTrue($this->field->canCreate($member));
39
    }
40
41 View Code Duplication
    public function testCanEdit()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        Security::setCurrentUser(null);
44
        $this->assertFalse($this->field->canEdit());
45
46
        $member = DefaultAdminService::singleton()->findOrCreateAdmin('[email protected]');
47
        Security::setCurrentUser($member);
48
49
        $this->assertTrue($this->field->canEdit($member));
50
    }
51
52 View Code Duplication
    public function testCanDelete()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        Security::setCurrentUser(null);
55
        $this->assertFalse($this->field->canDelete());
56
57
        $member = DefaultAdminService::singleton()->findOrCreateAdmin('[email protected]');
58
        Security::setCurrentUser($member);
59
60
        $this->assertTrue($this->field->canDelete($member));
61
    }
62
63
    protected function setUp()
64
    {
65
        $this->field = PartialFileFieldSubmission::create();
66
        $partialForm = PartialFormSubmission::create();
67
        $udf = UserDefinedForm::create(['Title' => 'Test'])->write();
68
        $partialForm->UserDefinedFormID = $udf;
69
        $partialFormID = $partialForm->write();
70
        $this->field->SubmittedFormID = $partialFormID;
71
72
        return parent::setUp();
73
    }
74
}
75