Code Duplication    Length = 77-77 lines in 3 locations

tests/AccordionPanelTest.php 1 location

@@ 11-87 (lines=77) @@
8
use SilverStripe\ORM\ValidationException;
9
use SilverStripe\Security\Member;
10
11
class AccordionPanelTest extends SapphireTest
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);
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));
48
        $member = $this->objFromFixture(Member::class, 'default');
49
        $this->assertTrue($object->canView($member));
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));
60
        $member = $this->objFromFixture(Member::class, 'default');
61
        $this->assertTrue($object->canEdit($member));
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));
72
        $member = $this->objFromFixture(Member::class, 'default');
73
        $this->assertTrue($object->canDelete($member));
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));
84
        $member = $this->objFromFixture(Member::class, 'default');
85
        $this->assertTrue($object->canCreate($member));
86
    }
87
}
88

tests/PageSectionObjectTest.php 1 location

@@ 11-87 (lines=77) @@
8
use SilverStripe\ORM\ValidationException;
9
use SilverStripe\Security\Member;
10
11
class PageSectionObjectTest extends SapphireTest
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(PageSectionObject::class, 'one');
24
        $fields = $object->getCMSFields();
25
        $this->assertInstanceOf(FieldList::class, $fields);
26
        //$this->assertNotNull($fields->dataFieldByName('BlockLinkID')); // todo readd once Linkable is SS4 compatible
27
    }
28
29
    /**
30
     *
31
     */
32
    public function testValidateName()
33
    {
34
        $object = $this->objFromFixture(PageSectionObject::class, 'one');
35
        $object->Name = '';
36
        $this->setExpectedException(ValidationException::class);
37
        $object->write();
38
    }
39
40
    /**
41
     *
42
     */
43
    public function testCanView()
44
    {
45
        $object = $this->objFromFixture(PageSectionObject::class, 'one');
46
        $admin = $this->objFromFixture(Member::class, 'admin');
47
        $this->assertTrue($object->canView($admin));
48
        $member = $this->objFromFixture(Member::class, 'default');
49
        $this->assertTrue($object->canView($member));
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testCanEdit()
56
    {
57
        $object = $this->objFromFixture(PageSectionObject::class, 'one');
58
        $admin = $this->objFromFixture(Member::class, 'admin');
59
        $this->assertTrue($object->canEdit($admin));
60
        $member = $this->objFromFixture(Member::class, 'default');
61
        $this->assertTrue($object->canEdit($member));
62
    }
63
64
    /**
65
     *
66
     */
67
    public function testCanDelete()
68
    {
69
        $object = $this->objFromFixture(PageSectionObject::class, 'one');
70
        $admin = $this->objFromFixture(Member::class, 'admin');
71
        $this->assertTrue($object->canDelete($admin));
72
        $member = $this->objFromFixture(Member::class, 'default');
73
        $this->assertTrue($object->canDelete($member));
74
    }
75
76
    /**
77
     *
78
     */
79
    public function testCanCreate()
80
    {
81
        $object = $this->objFromFixture(PageSectionObject::class, 'one');
82
        $admin = $this->objFromFixture(Member::class, 'admin');
83
        $this->assertTrue($object->canCreate($admin));
84
        $member = $this->objFromFixture(Member::class, 'default');
85
        $this->assertTrue($object->canCreate($member));
86
    }
87
}

tests/PromoObjectTest.php 1 location

@@ 11-87 (lines=77) @@
8
use SilverStripe\ORM\ValidationException;
9
use SilverStripe\Security\Member;
10
11
class PromoObjectTest extends SapphireTest
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(PromoObject::class, 'one');
24
        $fields = $object->getCMSFields();
25
        $this->assertInstanceOf(FieldList::class, $fields);
26
        //$this->assertNotNull($fields->dataFieldByName('BlockLinkID')); // todo readd once Linkable is SS4 compatible
27
    }
28
29
    /**
30
     *
31
     */
32
    public function testValidateName()
33
    {
34
        $object = $this->objFromFixture(PromoObject::class, 'one');
35
        $object->Name = '';
36
        $this->setExpectedException(ValidationException::class);
37
        $object->write();
38
    }
39
40
    /**
41
     *
42
     */
43
    public function testCanView()
44
    {
45
        $object = $this->objFromFixture(PromoObject::class, 'one');
46
        $admin = $this->objFromFixture(Member::class, 'admin');
47
        $this->assertTrue($object->canView($admin));
48
        $member = $this->objFromFixture(Member::class, 'default');
49
        $this->assertTrue($object->canView($member));
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testCanEdit()
56
    {
57
        $object = $this->objFromFixture(PromoObject::class, 'one');
58
        $admin = $this->objFromFixture(Member::class, 'admin');
59
        $this->assertTrue($object->canEdit($admin));
60
        $member = $this->objFromFixture(Member::class, 'default');
61
        $this->assertTrue($object->canEdit($member));
62
    }
63
64
    /**
65
     *
66
     */
67
    public function testCanDelete()
68
    {
69
        $object = $this->objFromFixture(PromoObject::class, 'one');
70
        $admin = $this->objFromFixture(Member::class, 'admin');
71
        $this->assertTrue($object->canDelete($admin));
72
        $member = $this->objFromFixture(Member::class, 'default');
73
        $this->assertTrue($object->canDelete($member));
74
    }
75
76
    /**
77
     *
78
     */
79
    public function testCanCreate()
80
    {
81
        $object = $this->objFromFixture(PromoObject::class, 'one');
82
        $admin = $this->objFromFixture(Member::class, 'admin');
83
        $this->assertTrue($object->canCreate($admin));
84
        $member = $this->objFromFixture(Member::class, 'default');
85
        $this->assertTrue($object->canCreate($member));
86
    }
87
}