JobSubmissionTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 128
rs 10
c 0
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetName() 0 10 1
A testGetFrontEndFields() 0 6 1
A testGetRequiredFields() 0 6 1
A testGetTitle() 0 8 1
A testGetCMSFields() 0 6 1
A testCanView() 0 6 1
A testCanCreate() 0 12 1
A testCanEdit() 0 12 1
A testCanDelete() 0 12 1
1
<?php
2
3
namespace Dynamic\Jobs\Test;
4
5
use Dynamic\Jobs\Model\JobSubmission;
6
use SilverStripe\Core\Injector\Injector;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\RequiredFields;
10
use SilverStripe\Security\Member;
11
12
/**
13
 * Class JobSubmission
14
 * @package Dynamic\Jobs\Tests
15
 */
16
class JobSubmissionTest extends SapphireTest
17
{
18
    /**
19
     * @var string
20
     */
21
    protected static $fixture_file = '../fixtures.yml';
22
23
    /**
24
     * Tests getName()
25
     */
26
    public function testGetName()
27
    {
28
        /** @var JobSubmission $object */
29
        $object = Injector::inst()->create(JobSubmission::class);
30
        $this->assertEquals('No Name', $object->getName());
31
32
        $object->FirstName = 'Raymond';
0 ignored issues
show
Bug Best Practice introduced by
The property FirstName does not exist on Dynamic\Jobs\Model\JobSubmission. Since you implemented __set, consider adding a @property annotation.
Loading history...
33
        $object->LastName = 'Luxury-Yacht';
0 ignored issues
show
Bug Best Practice introduced by
The property LastName does not exist on Dynamic\Jobs\Model\JobSubmission. Since you implemented __set, consider adding a @property annotation.
Loading history...
34
35
        $this->assertEquals('Raymond Luxury-Yacht', $object->getName());
36
    }
37
38
    /**
39
     * Tests getTitle()
40
     */
41
    public function testGetTitle()
42
    {
43
        /** @var JobSubmission $object */
44
        $object = Injector::inst()->create(JobSubmission::class);
45
        $object->FirstName = 'Arthur';
0 ignored issues
show
Bug Best Practice introduced by
The property FirstName does not exist on Dynamic\Jobs\Model\JobSubmission. Since you implemented __set, consider adding a @property annotation.
Loading history...
46
        $object->LastName = 'Nudge';
0 ignored issues
show
Bug Best Practice introduced by
The property LastName does not exist on Dynamic\Jobs\Model\JobSubmission. Since you implemented __set, consider adding a @property annotation.
Loading history...
47
48
        $this->assertEquals('Arthur Nudge', $object->getTitle());
49
    }
50
51
    /**
52
     * Tests getFrontEndFields()
53
     */
54
    public function testGetFrontEndFields()
55
    {
56
        /** @var JobSubmission $object */
57
        $object = Injector::inst()->create(JobSubmission::class);
58
        $fields = $object->getFrontEndFields();
59
        $this->assertInstanceOf(FieldList::class, $fields);
60
    }
61
62
    /**
63
     * Tests getRequiredFields()
64
     */
65
    public function testGetRequiredFields()
66
    {
67
        /** @var JobSubmission $object */
68
        $object = Injector::inst()->create(JobSubmission::class);
69
        $fields = $object->getRequiredFields();
70
        $this->assertInstanceOf(RequiredFields::class, $fields);
71
    }
72
73
    /**
74
     * Tests getCMSFields
75
     */
76
    public function testGetCMSFields()
77
    {
78
        /** @var JobSubmission $object */
79
        $object = Injector::inst()->create(JobSubmission::class);
80
        $fields = $object->getCMSFields();
81
        $this->assertInstanceOf(FieldList::class, $fields);
82
    }
83
84
    /**
85
     * Tests canCreate()
86
     */
87
    public function testCanCreate()
88
    {
89
        /** @var JobSubmission $object */
90
        $object = Injector::inst()->create(JobSubmission::class);
91
92
        $admin = $this->objFromFixture(Member::class, 'Admin');
93
        $manage = $this->objFromFixture(Member::class, 'Manager');
94
        $visitor = $this->objFromFixture(Member::class, 'Visitor');
95
96
        $this->assertTrue($object->canCreate($admin));
97
        $this->assertTrue($object->canCreate($manage));
98
        $this->assertFalse($object->canCreate($visitor));
99
    }
100
101
    /**
102
     * Tests canEdit()
103
     */
104
    public function testCanEdit()
105
    {
106
        /** @var JobSubmission $object */
107
        $object = Injector::inst()->create(JobSubmission::class);
108
109
        $admin = $this->objFromFixture(Member::class, 'Admin');
110
        $manage = $this->objFromFixture(Member::class, 'Manager');
111
        $visitor = $this->objFromFixture(Member::class, 'Visitor');
112
113
        $this->assertTrue($object->canEdit($admin));
114
        $this->assertTrue($object->canEdit($manage));
115
        $this->assertFalse($object->canEdit($visitor));
116
    }
117
118
    /**
119
     * Tests canDelete()
120
     */
121
    public function testCanDelete()
122
    {
123
        /** @var JobSubmission $object */
124
        $object = Injector::inst()->create(JobSubmission::class);
125
126
        $admin = $this->objFromFixture(Member::class, 'Admin');
127
        $manage = $this->objFromFixture(Member::class, 'Manager');
128
        $visitor = $this->objFromFixture(Member::class, 'Visitor');
129
130
        $this->assertTrue($object->canDelete($admin));
131
        $this->assertTrue($object->canDelete($manage));
132
        $this->assertFalse($object->canDelete($visitor));
133
    }
134
135
    /**
136
     * Tests canView()
137
     */
138
    public function testCanView()
139
    {
140
        /** @var JobSubmission $object */
141
        $object = Injector::inst()->create(JobSubmission::class);
142
        $manage = $this->objFromFixture(Member::class, 'Manager');
143
        $this->assertTrue($object->canView($manage));
144
    }
145
}
146