Completed
Pull Request — master (#62)
by Jason
11:55
created

AccordionPanelTest::testCanView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
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\DynamicBlocks\Test;
4
5
use Dynamic\DynamicBlocks\Model\AccordionPanel;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\ORM\ValidationException;
9
use SilverStripe\Security\Member;
10
11 View Code Duplication
class AccordionPanelTest extends SapphireTest
0 ignored issues
show
Duplication introduced by
This class 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...
12
{
13
    /**
14
     * @var string
15
     */
16
    protected static $fixture_file = 'dynamic-blocks/tests/Fixtures.yml';
17
18
    /**
19
     *
20
     */
21
    public function testGetCMSFields()
22
    {
23
        $object = $this->objFromFixture(AccordionPanel::class, 'one');
24
        $fields = $object->getCMSFields();
25
        $this->assertInstanceOf(FieldList::class, $fields);
26
        $this->assertNull($fields->dataFieldByName('SortOrder'));
27
    }
28
29
    /**
30
     *
31
     */
32
    public function testValidateTitle()
33
    {
34
        $object = $this->objFromFixture(AccordionPanel::class, 'one');
35
        $object->Title = '';
36
        $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...
37
        $object->write();
38
    }
39
40
    /**
41
     *
42
     */
43
    public function testCanView()
44
    {
45
        $object = $this->objFromFixture(AccordionPanel::class, 'one');
46
        $admin = $this->objFromFixture(Member::class, 'admin');
47
        $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 46 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...
48
        $member = $this->objFromFixture(Member::class, 'default');
49
        $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 48 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...
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testCanEdit()
56
    {
57
        $object = $this->objFromFixture(AccordionPanel::class, 'one');
58
        $admin = $this->objFromFixture(Member::class, 'admin');
59
        $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 58 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...
60
        $member = $this->objFromFixture(Member::class, 'default');
61
        $this->assertTrue($object->canEdit($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 60 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...
62
    }
63
64
    /**
65
     *
66
     */
67
    public function testCanDelete()
68
    {
69
        $object = $this->objFromFixture(AccordionPanel::class, 'one');
70
        $admin = $this->objFromFixture(Member::class, 'admin');
71
        $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 70 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...
72
        $member = $this->objFromFixture(Member::class, 'default');
73
        $this->assertTrue($object->canDelete($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 72 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...
74
    }
75
76
    /**
77
     *
78
     */
79
    public function testCanCreate()
80
    {
81
        $object = $this->objFromFixture(AccordionPanel::class, 'one');
82
        $admin = $this->objFromFixture(Member::class, 'admin');
83
        $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 82 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...
84
        $member = $this->objFromFixture(Member::class, 'default');
85
        $this->assertTrue($object->canCreate($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 84 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...
86
    }
87
}
88