Passed
Pull Request — master (#129)
by Matthew
13:46
created

SlideImageTest::testCanEdit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Dynamic\flexslider\tests;
4
5
use Dynamic\FlexSlider\Model\SlideImage;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\ORM\ValidationException;
10
use SilverStripe\Security\Member;
11
12
class SlideImageTest extends SapphireTest
13
{
14
    /**
15
     * @var string
16
     */
17
    protected static $fixture_file = 'fixtures.yml';
18
19
    /**
20
     *
21
     */
22
    public function testGetCMSFields()
23
    {
24
        $object = new SlideImage();
25
        $fieldset = $object->getCMSFields();
26
        $this->assertInstanceOf(FieldList::class, $fieldset);
27
        $this->assertNotNull($fieldset->dataFieldByName('Name'));
28
        $this->assertNotNull($fieldset->dataFieldByName('Image'));
29
    }
30
31
    /**
32
     *
33
     */
34 View Code Duplication
    public function testValidateName()
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...
35
    {
36
        $object = $this->objFromFixture(SlideImage::class, 'slide1');
37
        $object->Name = '';
38
        $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

38
        /** @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...
39
        $object->write();
40
    }
41
42
    /**
43
     *
44
     */
45 View Code Duplication
    public function testValidateImage()
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...
46
    {
47
        $object = $this->objFromFixture(SlideImage::class, 'slide1');
48
        $object->ImageID = '';
49
        $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

49
        /** @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...
50
        $object->write();
51
    }
52
53
    /**
54
     *
55
     */
56
    public function testProvidePermissions()
57
    {
58
        $object = singleton(SlideImage::class);
59
        $expected = array(
60
            'Slide_EDIT' => 'Slide Edit',
61
            'Slide_DELETE' => 'Slide Delete',
62
            'Slide_CREATE' => 'Slide Create',
63
        );
64
        $this->assertEquals($expected, $object->providePermissions());
65
    }
66
67
    /**
68
     *
69
     */
70 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...
71
    {
72
        $object = $this->objFromFixture(SlideImage::class, 'slide1');
73
        $admin = $this->objFromFixture(Member::class, 'admin');
74
        $this->assertTrue($object->canCreate($admin));
75
76
        $author = $this->objFromFixture(Member::class, 'author');
77
        $this->assertTrue($object->canCreate($author));
78
79
        $member = $this->objFromFixture(Member::class, 'default');
80
        $this->assertFalse($object->canCreate($member));
81
    }
82
83
    /**
84
     *
85
     */
86 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...
87
    {
88
        $object = $this->objFromFixture(SlideImage::class, 'slide1');
89
        $admin = $this->objFromFixture(Member::class, 'admin');
90
        $this->assertTrue($object->canEdit($admin));
91
92
        $author = $this->objFromFixture(Member::class, 'author');
93
        $this->assertTrue($object->canEdit($author));
94
95
        $member = $this->objFromFixture(Member::class, 'default');
96
        $this->assertFalse($object->canEdit($member));
97
    }
98
99
    /**
100
     *
101
     */
102 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...
103
    {
104
        $object = $this->objFromFixture(SlideImage::class, 'slide1');
105
        $admin = $this->objFromFixture(Member::class, 'admin');
106
        $this->assertTrue($object->canDelete($admin));
107
108
        $author = $this->objFromFixture(Member::class, 'author');
109
        $this->assertTrue($object->canDelete($author));
110
111
        $member = $this->objFromFixture(Member::class, 'default');
112
        $this->assertFalse($object->canDelete($member));
113
    }
114
115
    /**
116
     *
117
     */
118 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...
119
    {
120
        $object = $this->objFromFixture(SlideImage::class, 'slide1');
121
        $admin = $this->objFromFixture(Member::class, 'admin');
122
        $this->assertTrue($object->canView($admin));
123
124
        $author = $this->objFromFixture(Member::class, 'author');
125
        $this->assertTrue($object->canView($author));
126
127
        $member = $this->objFromFixture(Member::class, 'default');
128
        $this->assertTrue($object->canView($member));
129
    }
130
131
    /**
132
     *
133
     */
134
    public function testImageSizeLimit()
135
    {
136
        $default = 512000;
137
        $this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $default);
138
139
        $new = 1024000;
140
        Config::modify()->update(SlideImage::class, 'image_size_limit', $new);
141
        $this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $new);
142
    }
143
}
144