Passed
Pull Request — master (#161)
by Matthew
11:56
created

FlexSliderTest::testGetSlideshowSpeed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 19
rs 9.8666
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 = array(
19
        TestPage::class,
20
    );
21
22
    /**
23
     * @var string
24
     */
25
    protected static $fixture_file = 'fixtures.yml';
26
27
    /**
28
     *
29
     */
30
    public function testTabNameConfig()
31
    {
32
        $page = TestPage::create();
33
        $page->write();
34
        $pageFields = $page->getCMSFields();
35
        $this->assertNotNull($pageFields->dataFieldByName('Slides'));
36
37
        Config::modify()
38
            ->update(TestPage::class, 'slide_tab_title', 'MyCustomSlideTitle');
39
        $page2 = TestPage::create();
40
        $page2->write();
41
        $page2Fields = $page2->getCMSFields();
42
        $this->assertNull($page2Fields->fieldByName('Root.Slides'));
43
        $this->assertNotNull($page2Fields->fieldByName('Root.MyCustomSlideTitle'));
44
    }
45
46
    /**
47
     *
48
     */
49
    public function testUpdateCMSFields()
50
    {
51
        $object = TestPage::create();
52
        $fields = $object->getCMSFields();
53
        $this->assertNull($fields->dataFieldByName('Slides'));
54
55
        $object->write();
56
        $fields = $object->getCMSFields();
57
        $this->assertInstanceOf(FieldList::class, $fields);
58
        $this->assertNotNull($fields->dataFieldbyName('Slides'));
59
    }
60
61
    /**
62
     *
63
     */
64
    public function testGetSlideshow()
65
    {
66
        $object = TestPage::create();
67
        $object->write();
68
        $slide1 = $this->objFromFixture(SlideImage::class, 'slide1');
69
        $image = $this->objFromFixture(Image::class, 'image1');
70
        $slide1->ImageID = $image->ID;
71
        $object->Slides()->add($slide1);
72
        $slides = $object->getSlideShow();
73
        $this->assertInstanceOf(DataList::class, $slides);
74
    }
75
76
    /**
77
     *
78
     */
79
    public function testGetSlideshowSpeed()
80
    {
81
        /** @var \Dynamic\FlexSlider\ORM\FlexSlider|\Page $object */
82
        $object = TestPage::create();
83
        $this->assertEquals(7000, $object->getSlideshowSpeed());
84
85
        Config::modify()->set(FlexSlider::class, 'FlexSliderSpeed', 5000);
86
        $this->assertEquals(5000, $object->getSlideshowSpeed());
87
88
        $object->config()->set('FlexSliderSpeed', 3000);
0 ignored issues
show
Bug introduced by
The method config() 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

88
        $object->/** @scrutinizer ignore-call */ 
89
                 config()->set('FlexSliderSpeed', 3000);

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...
89
        $this->assertEquals(3000, $object->getSlideshowSpeed());
90
91
        $object->config()->set('setFlexSliderSpeed', true);
92
        $this->assertEquals(1000, $object->getSlideshowSpeed());
93
94
        $object->config()->set('ShowSpeedInCMS', true);
95
        $object->FlexSliderSpeed = 0.5;
96
        $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

96
        $object->/** @scrutinizer ignore-call */ 
97
                 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...
97
        $this->assertEquals(500, $object->getSlideshowSpeed());
98
    }
99
100
    public function testGetShowSpeedInCMS()
101
    {
102
        /** @var \Dynamic\FlexSlider\ORM\FlexSlider|\Page $object */
103
        $object = TestPage::create();
104
        $this->assertFalse($object->getShowSpeedInCMS());
105
106
        Config::modify()->set(FlexSlider::class, 'ShowSpeedInCMS', true);
107
        $this->assertTrue($object->getShowSpeedInCMS());
108
109
        Config::modify()->set(FlexSlider::class, 'ShowSpeedInCMS', false);
110
        $object->config()->set('ShowSpeedInCMS', true);
111
        $this->assertTrue($object->getShowSpeedInCMS());
112
    }
113
}
114