Passed
Push — master ( 5540e2...e2d432 )
by Jason
02:58
created

FoxyCategoryTest::testCanDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Foxy\Test\Model;
4
5
use Dynamic\Foxy\Model\FoxyCategory;
6
use Dynamic\Foxy\Test\TestOnly\TestProduct;
7
use SilverStripe\Core\Injector\Injector;
8
use SilverStripe\Dev\SapphireTest;
9
use SilverStripe\Forms\FieldList;
10
use SilverStripe\ORM\ValidationException;
11
use SilverStripe\Security\Member;
12
13
class FoxyCategoryTest extends SapphireTest
14
{
15
    /**
16
     * @var string
17
     */
18
    protected static $fixture_file = '../fixtures.yml';
19
20
    /**
21
     *
22
     */
23
    public function testGetCMSFields()
24
    {
25
        $object = $this->objFromFixture(FoxyCategory::class, 'one');
26
        $fields = $object->getCMSFields();
27
        $this->assertInstanceOf(FieldList::class, $fields);
28
29
        $object = Injector::inst()->create(FoxyCategory::class);
30
        $object->Code = 'DEFAULT';
31
        $object->write();
32
        $fields = $object->getCMSFields();
33
        $this->assertInstanceOf(FieldList::class, $fields);
34
    }
35
36
    /**
37
     *
38
     */
39
    public function testValidateCode()
40
    {
41
        $object = $this->objFromFixture(FoxyCategory::class, 'one');
42
        $object->Code = '';
43
        $this->setExpectedException(ValidationException::class);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

43
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException(ValidationException::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
44
        $object->write();
45
46
        $object = $this->objFromFixture(FoxyCategory::class, 'one');
47
        $object->Code = 'DEFAULT';
48
        $this->setExpectedException(ValidationException::class);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException(ValidationException::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
        $object->write();
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testCanCreate()
56
    {
57
        /** @var FoxyCategory $object */
58
        $object = singleton(FoxyCategory::class);
59
        /** @var \SilverStripe\Security\Member $admin */
60
        $admin = $this->objFromFixture(Member::class, 'admin');
61
        /** @var \SilverStripe\Security\Member $siteOwner */
62
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
63
        /** @var \SilverStripe\Security\Member $default */
64
        $default = $this->objFromFixture(Member::class, 'default');
65
66
        $this->assertFalse($object->canCreate($default));
67
        $this->assertTrue($object->canCreate($admin));
68
        $this->assertTrue($object->canCreate($siteOwner));
69
    }
70
71
    /**
72
     *
73
     */
74
    public function testCanEdit()
75
    {
76
        /** @var FoxyCategory $object */
77
        $object = singleton(FoxyCategory::class);
78
        /** @var \SilverStripe\Security\Member $admin */
79
        $admin = $this->objFromFixture(Member::class, 'admin');
80
        /** @var \SilverStripe\Security\Member $siteOwner */
81
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
82
        /** @var \SilverStripe\Security\Member $default */
83
        $default = $this->objFromFixture(Member::class, 'default');
84
85
        $this->assertFalse($object->canEdit($default));
86
        $this->assertTrue($object->canEdit($admin));
87
        $this->assertTrue($object->canEdit($siteOwner));
88
    }
89
90
    /**
91
     *
92
     */
93
    public function testCanDelete()
94
    {
95
        /** @var FoxyCategory $object */
96
        $object = singleton(FoxyCategory::class);
97
        /** @var \SilverStripe\Security\Member $admin */
98
        $admin = $this->objFromFixture(Member::class, 'admin');
99
        /** @var \SilverStripe\Security\Member $siteOwner */
100
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
101
        /** @var \SilverStripe\Security\Member $default */
102
        $default = $this->objFromFixture(Member::class, 'default');
103
104
        $this->assertFalse($object->canDelete($default));
105
        $this->assertTrue($object->canDelete($admin));
106
        $this->assertTrue($object->canDelete($siteOwner));
107
    }
108
}
109