FlexSliderTest::testTabNameConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 14
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\FlexSlider\Test;
4
5
use Dynamic\FlexSlider\Model\SlideImage;
6
use Dynamic\FlexSlider\ORM\FlexSlider;
7
use SilverStripe\Assets\Image;
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\Dev\SapphireTest;
10
use SilverStripe\Forms\FieldList;
11
use SilverStripe\ORM\DataList;
12
13
class FlexSliderTest extends SapphireTest
14
{
15
    /**
16
     * @var array
17
     */
18
    protected static $extra_dataobjects = [
19
        TestPage::class,
20
    ];
21
22
    /**
23
     * @var string
24
     */
25
    protected static $fixture_file = 'fixtures.yml';
26
27
    /**
28
     * @var array
29
     */
30
    protected static $required_extensions = [
31
        TestPage::class => [
32
            FlexSlider::class,
33
        ],
34
    ];
35
36
    /**
37
     *
38
     */
39
    public function testTabNameConfig()
40
    {
41
        $page = TestPage::create();
42
        $page->write();
43
        $pageFields = $page->getCMSFields();
44
        $this->assertNotNull($pageFields->dataFieldByName('Slides'));
45
46
        Config::modify()
47
            ->update(TestPage::class, 'slide_tab_title', 'MyCustomSlideTitle');
48
        $page2 = TestPage::create();
49
        $page2->write();
50
        $page2Fields = $page2->getCMSFields();
51
        $this->assertNull($page2Fields->fieldByName('Root.Slides'));
52
        $this->assertNotNull($page2Fields->fieldByName('Root.MyCustomSlideTitle'));
53
    }
54
55
    /**
56
     *
57
     */
58
    public function testUpdateCMSFields()
59
    {
60
        $object = TestPage::create();
61
        $fields = $object->getCMSFields();
62
        $this->assertNull($fields->dataFieldByName('Slides'));
63
64
        $object->write();
65
        $fields = $object->getCMSFields();
66
        $this->assertInstanceOf(FieldList::class, $fields);
67
        $this->assertNotNull($fields->dataFieldbyName('Slides'));
68
    }
69
70
    /**
71
     *
72
     */
73
    public function testGetSlideshow()
74
    {
75
        $object = TestPage::create();
76
        $object->write();
77
        $slide1 = $this->objFromFixture(SlideImage::class, 'slide1');
78
        $image = $this->objFromFixture(Image::class, 'image1');
79
        $slide1->ImageID = $image->ID;
80
        $object->Slides()->add($slide1);
81
        $slides = $object->getSlideShow();
82
        $this->assertInstanceOf(DataList::class, $slides);
83
    }
84
85
    /**
86
     *
87
     */
88
    public function testGetSlideshowSpeed()
89
    {
90
        /** @var \Dynamic\FlexSlider\ORM\FlexSlider|\Page $object */
91
        $object = TestPage::create();
92
        $object->FlexSliderSpeed = 0;
93
        $this->assertEquals(
94
            Config::inst()->get(FlexSlider::class, 'flex_slider_speed') * 1000,
95
            $object->getSlideshowSpeed()
96
        );
97
98
        $object->FlexSliderSpeed = 0.5;
99
        $object->write();
0 ignored issues
show
Bug introduced by
The method write() does not exist on Dynamic\FlexSlider\ORM\FlexSlider. ( Ignorable by Annotation )

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

99
        $object->/** @scrutinizer ignore-call */ 
100
                 write();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
        $this->assertEquals(500, $object->getSlideshowSpeed());
101
    }
102
}
103