Completed
Pull Request — master (#161)
by Matthew
24:51 queued 10:08
created

FlexSliderTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testUpdateCMSFields() 0 10 1
A testGetSlideshow() 0 10 1
A testTabNameConfig() 0 14 1
A testGetSlideshowSpeed() 0 18 1
A testGetShowSpeedInCMS() 0 12 1
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 = 14;
96
        $this->assertEquals(14000, $object->getSlideshowSpeed());
97
    }
98
99
    public function testGetShowSpeedInCMS()
100
    {
101
        /** @var \Dynamic\FlexSlider\ORM\FlexSlider|\Page $object */
102
        $object = TestPage::create();
103
        $this->assertFalse($object->getShowSpeedInCMS());
104
105
        Config::modify()->set(FlexSlider::class, 'ShowSpeedInCMS', true);
106
        $this->assertTrue($object->getShowSpeedInCMS());
107
108
        Config::modify()->set(FlexSlider::class, 'ShowSpeedInCMS', false);
109
        $object->config()->set('ShowSpeedInCMS', true);
110
        $this->assertTrue($object->getShowSpeedInCMS());
111
    }
112
}
113