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

PartialFieldSubmissionTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
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\PartialFieldSubmission;
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 PartialFieldSubmissionTest extends SapphireTest
13
{
14
15
    /**
16
     * @var PartialFieldSubmission
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()
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...
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()
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...
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()
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...
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 = PartialFieldSubmission::create();
66
        $partialForm = PartialFormSubmission::create();
67
        $udf = UserDefinedForm::create(['Title' => 'Test'])->write();
68
        $partialForm->UserDefinedFormID = $udf;
69
        $partialFormID = $partialForm->write();
70
        $partialForm->publishRecursive();
0 ignored issues
show
Documentation Bug introduced by
The method publishRecursive does not exist on object<Firesphere\Partia...\PartialFormSubmission>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
71
        $this->field->SubmittedFormID = $partialFormID;
72
73
        return parent::setUp();
74
    }
75
76
    protected function tearDown()
77
    {
78
        parent::tearDown();
79
    }
80
}
81