Passed
Push — fix-9163 ( 4cfde3...07a516 )
by Ingo
17:14
created

GridStateDataTest::testCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Forms\Tests\GridField;
4
5
use SilverStripe\Forms\GridField\GridState_Data;
6
use SilverStripe\Forms\GridField\GridState;
7
use SilverStripe\Forms\GridField\GridField;
8
use SilverStripe\Dev\SapphireTest;
9
10
class GridStateDataTest extends SapphireTest
11
{
12
13
    public function testGetData()
14
    {
15
        $state = new GridState_Data();
16
17
        $this->assertEquals('Bar', $state->getData('Foo', 'Bar'));
18
        $this->assertEquals('Bar', $state->Foo);
0 ignored issues
show
Bug Best Practice introduced by
The property Foo does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __get, consider adding a @property annotation.
Loading history...
19
        $this->assertEquals('Bar', $state->getData('Foo', 'Hello World'));
20
    }
21
22
    public function testCall()
23
    {
24
        $state = new GridState_Data();
25
26
        $foo = $state->Foo();
0 ignored issues
show
Bug introduced by
The method Foo() does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        /** @scrutinizer ignore-call */ 
27
        $foo = $state->Foo();
Loading history...
27
        $this->assertInstanceOf(GridState_Data::class, $foo);
28
29
        $bar = $state->Bar(123456);
0 ignored issues
show
Bug introduced by
The method Bar() does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        /** @scrutinizer ignore-call */ 
30
        $bar = $state->Bar(123456);
Loading history...
30
        $this->assertEquals(123456, $bar);
31
32
        $zone = $state->Zone(null);
0 ignored issues
show
Bug introduced by
The method Zone() does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        /** @scrutinizer ignore-call */ 
33
        $zone = $state->Zone(null);
Loading history...
33
        $this->assertEquals(null, $zone);
34
    }
35
36
    public function testInitDefaults()
37
    {
38
        $state = new GridState_Data();
39
        $state->initDefaults(['Foo' => 'Bar', 'Hello' => 'World']);
40
41
        $this->assertEquals('Bar', $state->Foo);
0 ignored issues
show
Bug Best Practice introduced by
The property Foo does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __get, consider adding a @property annotation.
Loading history...
42
        $this->assertEquals('World', $state->Hello);
0 ignored issues
show
Bug Best Practice introduced by
The property Hello does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
    }
44
45
    public function testToArray()
46
    {
47
        $state = new GridState_Data();
48
49
        $this->assertEquals([], $state->toArray());
50
51
        $state->Foo = 'Bar';
0 ignored issues
show
Bug Best Practice introduced by
The property Foo does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __set, consider adding a @property annotation.
Loading history...
52
        $this->assertEquals(['Foo' => 'Bar'], $state->toArray());
53
54
        $state->initDefaults(['Foo' => 'Bar', 'Hello' => 'World']);
55
56
        $this->assertEquals(['Foo' => 'Bar', 'Hello' => 'World'], $state->toArray());
57
        $this->assertEquals([], $state->getChangesArray());
58
59
        $boom = $state->Boom();
0 ignored issues
show
Bug introduced by
The method Boom() does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        /** @scrutinizer ignore-call */ 
60
        $boom = $state->Boom();
Loading history...
60
        $boom->Pow = 'Kaboom';
61
62
        $state->Boom(null);
63
64
        $this->assertEquals(['Foo' => 'Bar', 'Hello' => 'World', 'Boom' => ['Pow' => 'Kaboom']], $state->toArray());
65
        $this->assertEquals(['Boom' => ['Pow' => 'Kaboom']], $state->getChangesArray());
66
    }
67
68
    public function testInitDefaultsAfterSetValue()
69
    {
70
        $state = new GridState(new GridField('x'));
71
        $state->setValue('{"Foo":{"Bar":"Baz","Wee":null}}');
72
        $data = $state->getData();
73
74
        $data->Foo->initDefaults([
0 ignored issues
show
Bug Best Practice introduced by
The property Foo does not exist on SilverStripe\Forms\GridField\GridState_Data. Since you implemented __get, consider adding a @property annotation.
Loading history...
75
            'Bar' => 'Bing',
76
            'Zoop' => 'Zog',
77
            'Wee' => 'Wing',
78
        ]);
79
80
        $this->assertEquals(['Bar' => 'Baz', 'Zoop' => 'Zog', 'Wee' => null], $data->Foo->toArray());
81
        $this->assertEquals(['Bar' => 'Baz', 'Wee' => null], $data->Foo->getChangesArray());
82
    }
83
}
84