Passed
Pull Request — master (#39)
by Matthew
01:58
created

testUpdateCMSActionsWithID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 17
rs 9.8666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Dynamic\Salsify\Tests\Model\Mapper;
4
5
use Dyanmic\Salsify\ORM\SalsifyIDExtension;
6
use Dynamic\Salsify\Tests\TestOnly\MappedObject;
7
use Dynamic\Salsify\Tests\TestOnly\TestController;
0 ignored issues
show
Bug introduced by
The type Dynamic\Salsify\Tests\TestOnly\TestController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SilverStripe\Control\HTTPRequest;
9
use SilverStripe\Control\Session;
10
use SilverStripe\Dev\SapphireTest;
11
use SilverStripe\Forms\FieldList;
12
use SilverStripe\Forms\FormAction;
13
use SilverStripe\Forms\FormField;
14
15
/**
16
 * Class MapperTest
17
 * @package Dynamic\Salsify\Tests\Model\Mapper
18
 */
19
class SalsifyIDExtensionTest extends SapphireTest
20
{
21
    /**
22
     * @var array
23
     */
24
    protected static $extra_dataobjects = [
25
        MappedObject::class,
26
    ];
27
28
    /**
29
     * @var array
30
     */
31
    protected static $extra_controllers = [
32
        TestController::class,
33
    ];
34
35
    /**
36
     * @var array
37
     */
38
    protected static $required_extensions = [
39
        MappedObject::class => [
40
            SalsifyIDExtension::class,
41
        ],
42
    ];
43
44
    /**
45
     *
46
     */
47
    public function testUpdateCMSFieldsWithID()
48
    {
49
        /** @var MappedObject|SalsifyIDExtension $object */
50
        $object = MappedObject::create();
51
        $object->SalsifyID = '001';
0 ignored issues
show
Bug Best Practice introduced by
The property SalsifyID does not exist on Dynamic\Salsify\Tests\TestOnly\MappedObject. Since you implemented __set, consider adding a @property annotation.
Loading history...
52
        $fields = $object->getCMSFields();
0 ignored issues
show
Bug introduced by
The method getCMSFields() does not exist on Dyanmic\Salsify\ORM\SalsifyIDExtension. ( Ignorable by Annotation )

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

52
        /** @scrutinizer ignore-call */ 
53
        $fields = $object->getCMSFields();

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...
53
        $this->assertInstanceOf(FieldList::class, $fields);
54
        $this->assertInstanceOf(FormField::class, $fields->fieldByName('SalsifyID'));
55
        $this->assertTrue($fields->fieldByName('SalsifyID')->isReadonly());
56
    }
57
58
    /**
59
     *
60
     */
61
    public function testUpdateCMSFieldsWithoutID()
62
    {
63
        /** @var MappedObject|SalsifyIDExtension $object */
64
        $object = MappedObject::create();
65
        $fields = $object->getCMSFields();
66
        $this->assertInstanceOf(FieldList::class, $fields);
67
        $this->assertInstanceOf(FormField::class, $fields->fieldByName('SalsifyID'));
68
        $this->assertFalse($fields->fieldByName('SalsifyID')->isReadonly());
69
    }
70
71
    /**
72
     *
73
     */
74
    public function testUpdateCMSActionsWithoutID()
75
    {
76
        /** @var MappedObject|SalsifyIDExtension $object */
77
        $object = MappedObject::create();
78
        $actions = $object->getCMSActions();
0 ignored issues
show
Bug introduced by
The method getCMSActions() does not exist on Dyanmic\Salsify\ORM\SalsifyIDExtension. ( Ignorable by Annotation )

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

78
        /** @scrutinizer ignore-call */ 
79
        $actions = $object->getCMSActions();

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...
79
        $this->assertInstanceOf(FieldList::class, $actions);
80
        $this->assertNull($actions->fieldByName('action_salsifyFetch'));
81
    }
82
83
    /**
84
     *
85
     */
86
    public function testUpdateCMSActionsWithID()
87
    {
88
        $controller = TestController::create();
89
        $request = new HTTPRequest('GET', '/');
90
        $session = new Session([]);
91
        $request->setSession($session);
92
        $controller->setRequest($request);
93
        $controller->doInit();
94
        $controller->pushCurrent();
95
96
97
        /** @var MappedObject|SalsifyIDExtension $object */
98
        $object = MappedObject::create();
99
        $object->SalsifyID = '001';
0 ignored issues
show
Bug Best Practice introduced by
The property SalsifyID does not exist on Dynamic\Salsify\Tests\TestOnly\MappedObject. Since you implemented __set, consider adding a @property annotation.
Loading history...
100
        $actions = $object->getCMSActions();
101
        $this->assertInstanceOf(FieldList::class, $actions);
102
        $this->assertInstanceOf(FormAction::class, $actions->fieldByName('action_salsifyFetch'));
103
    }
104
}
105