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

PartialFileFieldSubmissionTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 61.9 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 39
loc 63
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanView() 9 9 1
A testCanCreate() 10 10 1
A testCanEdit() 10 10 1
A testCanDelete() 10 10 1
A setUp() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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->assertFalse($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