Completed
Pull Request — master (#160)
by Matthew
03:08
created

FlexSliderTest::testGetSlideshowSpeed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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

84
        $object->/** @scrutinizer ignore-call */ 
85
                 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...
85
        $this->assertEquals(3000, $object->getSlideshowSpeed());
86
87
        $object->config()->set('setFlexSliderSpeed', true);
88
        $this->assertEquals(1000, $object->getSlideshowSpeed());
89
    }
90
}
91