WarrantyTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanCreate() 0 9 1
A testGetCMSFields() 0 10 1
A testCanView() 0 9 1
A testProvidePermissions() 0 9 1
A testCanDelete() 0 9 1
A testCanEdit() 0 9 1
1
<?php
2
3
namespace Dynamic\ProductCatalog\Test;
4
5
use Dynamic\ProductCatalog\Docs\Warranty;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Security\Member;
9
10
class WarrantyTest extends SapphireTest
11
{
12
    /**
13
     * @var string
14
     */
15
    protected static $fixture_file = 'fixtures.yml';
16
17
    /**
18
     *
19
     */
20
    public function testGetCMSFields()
21
    {
22
        $object = new Warranty();
23
        $fields = $object->getCMSFields();
24
        $this->assertInstanceOf(FieldList::class, $fields);
25
        $this->assertNull($fields->dataFieldByName('Products'));
26
27
        $object = $this->objFromFixture(Warranty::class, 'one');
28
        $fields = $object->getCMSFields();
29
        $this->assertInstanceOf(FieldList::class, $fields);
30
        //$this->assertNotNull($fields->dataFieldByName('Products'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
    }
32
33
    public function testCanView()
34
    {
35
        $object = $this->objFromFixture(Warranty::class, 'one');
36
37
        $admin = $this->objFromFixture(Member::class, 'admin');
38
        $this->assertTrue($object->canView($admin));
39
40
        $member = $this->objFromFixture(Member::class, 'default');
41
        $this->assertTrue($object->canView($member));
42
    }
43
44
    public function testCanEdit()
45
    {
46
        $object = $this->objFromFixture(Warranty::class, 'one');
47
48
        $admin = $this->objFromFixture(Member::class, 'admin');
49
        $this->assertTrue($object->canEdit($admin));
50
51
        $member = $this->objFromFixture(Member::class, 'default');
52
        $this->assertFalse($object->canEdit($member));
53
    }
54
55
    public function testCanDelete()
56
    {
57
        $object = $this->objFromFixture(Warranty::class, 'one');
58
59
        $admin = $this->objFromFixture(Member::class, 'admin');
60
        $this->assertTrue($object->canDelete($admin));
61
62
        $member = $this->objFromFixture(Member::class, 'default');
63
        $this->assertFalse($object->canDelete($member));
64
    }
65
66
    public function testCanCreate()
67
    {
68
        $object = $this->objFromFixture(Warranty::class, 'one');
69
70
        $admin = $this->objFromFixture(Member::class, 'admin');
71
        $this->assertTrue($object->canCreate($admin));
72
73
        $member = $this->objFromFixture(Member::class, 'default');
74
        $this->assertFalse($object->canCreate($member));
75
    }
76
77
    public function testProvidePermissions()
78
    {
79
        $object = $this->objFromFixture(Warranty::class, 'one');
80
        $expected = array(
81
            'Warranty_EDIT' => 'Edit Warranty Docs',
82
            'Warranty_DELETE' => 'Delete Warranty Docs',
83
            'Warranty_CREATE' => 'Create Warranty Docs',
84
        );
85
        $this->assertEquals($expected, $object->providePermissions());
86
    }
87
}
88