Passed
Pull Request — master (#198)
by Nic
02:19
created

FlexSliderTest::testGetSlideshow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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

104
        $object->/** @scrutinizer ignore-call */ 
105
                 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...
105
        $this->assertEquals(500, $object->getSlideshowSpeed());
106
    }
107
}
108