Completed
Push — master ( 20bae3...37553d )
by Jason
11s
created

SlideImageTest::testGetCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
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 = 'flexslider/tests/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 method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

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

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class 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 method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

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

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class 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));
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture(\S...Member::class, 'admin') on line 73 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canCreate() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
75
76
        $author = $this->objFromFixture(Member::class, 'author');
77
        $this->assertTrue($object->canCreate($author));
0 ignored issues
show
Bug introduced by
It seems like $author defined by $this->objFromFixture(\S...ember::class, 'author') on line 76 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canCreate() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
78
79
        $member = $this->objFromFixture(Member::class, 'default');
80
        $this->assertFalse($object->canCreate($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 79 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canCreate() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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));
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture(\S...Member::class, 'admin') on line 89 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canEdit() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
91
92
        $author = $this->objFromFixture(Member::class, 'author');
93
        $this->assertTrue($object->canEdit($author));
0 ignored issues
show
Bug introduced by
It seems like $author defined by $this->objFromFixture(\S...ember::class, 'author') on line 92 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canEdit() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
94
95
        $member = $this->objFromFixture(Member::class, 'default');
96
        $this->assertFalse($object->canEdit($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 95 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canEdit() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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));
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture(\S...Member::class, 'admin') on line 105 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canDelete() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
107
108
        $author = $this->objFromFixture(Member::class, 'author');
109
        $this->assertTrue($object->canDelete($author));
0 ignored issues
show
Bug introduced by
It seems like $author defined by $this->objFromFixture(\S...ember::class, 'author') on line 108 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canDelete() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
110
111
        $member = $this->objFromFixture(Member::class, 'default');
112
        $this->assertFalse($object->canDelete($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 111 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canDelete() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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));
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture(\S...Member::class, 'admin') on line 121 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canView() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
123
124
        $author = $this->objFromFixture(Member::class, 'author');
125
        $this->assertTrue($object->canView($author));
0 ignored issues
show
Bug introduced by
It seems like $author defined by $this->objFromFixture(\S...ember::class, 'author') on line 124 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canView() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
126
127
        $member = $this->objFromFixture(Member::class, 'default');
128
        $this->assertTrue($object->canView($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 127 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canView() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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
}