Completed
Pull Request — master (#109)
by Jason
06:08
created

FlexSliderTest::testUpdateCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Dynamic\FlexSlider\Tests;
4
5
use SilverStripe\Assets\Image;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Dev\TestOnly;
9
use SilverStripe\Forms\FieldList;
10
use Dynamic\FlexSlider\FlexSlider;
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 = 'flexslider/tests/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'));
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<Dynamic\FlexSlider\Tests\FlexSliderTest>.

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...
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'));
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<Dynamic\FlexSlider\Tests\FlexSliderTest>.

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...
43
        $this->assertNotNull($page2Fields->fieldByName('Root.MyCustomSlideTitle'));
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<Dynamic\FlexSlider\Tests\FlexSliderTest>.

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...
44
    }
45
46
    /**
47
     *
48
     */
49
    public function testUpdateCMSFields()
50
    {
51
        $object = TestPage::create();
52
        $fields = $object->getCMSFields();
53
        $this->assertNull($fields->dataFieldByName('Slides'));
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<Dynamic\FlexSlider\Tests\FlexSliderTest>.

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...
54
55
        $object->write();
56
        $fields = $object->getCMSFields();
57
        $this->assertInstanceOf(FieldList::class, $fields);
58
        $this->assertNotNull($fields->dataFieldbyName('Slides'));
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<Dynamic\FlexSlider\Tests\FlexSliderTest>.

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...
59
    }
60
61
    /**
62
     *
63
     */
64
    public function testGetSlideshow()
65
    {
66
        $object = TestPage::create();
67
        $object->write();
68
        $slide1 = $this->objFromFixture('Dynamic\\FlexSlider\\SlideImage', '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
}