Completed
Pull Request — master (#10)
by Helpful
14:43
created

EditableFieldAdminTest::testSaveRequest()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 29
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
/**
4
 * EditableFieldAdminTest contains test cases for testing the LeftAndMain subclass
5
 *
6
 * @author  Mohamed Alsharaf <[email protected]>
7
 * @package editablefield
8
 */
9
class EditableFieldAdminTest extends FunctionalTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    protected static $fixture_file = 'EditableFieldTest.yml';
12
13
    public function testPermission()
14
    {
15
        $this->logInWithPermission('EDITOR');
16
17
        $this->assertEquals('403', $this->get('/admin/editablefield')->getStatusCode());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFieldAdminTest>.

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...
18
    }
19
20 View Code Duplication
    public function testFilterRequest()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $this->logInWithPermission('ADMIN');
23
24
        $request = new SS_HTTPRequest(null, 'admin/editablefield/filter', [
25
            'q'               => [
26
                'Term' => 'email-field',
27
            ],
28
            'action_doSearch' => 'Apply Filter'
29
        ]);
30
        $admin = new EditableFieldAdmin();
31
        $admin->setRequest($request);
32
        $response = $admin->filter();
33
34
        $this->assertEquals('200', $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFieldAdminTest>.

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...
35
        $this->assertContains('email-field', $response->getBody());
36
    }
37
38 View Code Duplication
    public function testAddRequest()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $this->logInWithPermission('ADMIN');
41
42
        $request = new SS_HTTPRequest('post', 'admin/editablefield/doAdd', null, [
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
            'Type'              => 'EditableFieldText',
44
            'action_doAddField' => 'Add'
45
        ]);
46
        $admin = new EditableFieldAdmin();
47
        $admin->setRequest($request);
48
        $response = $admin->doAdd($request);
49
50
        $this->assertInstanceOf('HTMLText', $response);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<EditableFieldAdminTest>.

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...
51
        $this->assertContains('EditableFieldText', $response->getValue());
52
    }
53
54
    public function testSaveRequest()
55
    {
56
        $this->logInWithPermission('ADMIN');
57
58
        $text = $this->objFromFixture('EditableFieldText', 'basic-text');
59
        $email = $this->objFromFixture('EditableFieldEmail', 'email-field');
60
        $textName = $text->Name . '_update';
61
        $emailTitle = 'Email address 2';
62
63
        $response = $this->post('admin/editablefield/EditForm', [
64
            'Fields'      => [
65
                $text->ID  => [
66
                    'Name' => $textName,
67
                ],
68
                $email->ID => [
69
                    'Title' => $emailTitle,
70
                ]
71
            ],
72
            'action_save' => 'Save'
73
        ]);
74
75
        $this->assertEquals('200', $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFieldAdminTest>.

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...
76
77
        $newText = $this->objFromFixture('EditableFieldText', 'basic-text');
78
        $newEmail = $this->objFromFixture('EditableFieldEmail', 'email-field');
79
80
        $this->assertEquals($newText->Name, $textName);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFieldAdminTest>.

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...
81
        $this->assertEquals($newEmail->Title, $emailTitle);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFieldAdminTest>.

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...
82
    }
83
84
    public function testDeleteRequest()
85
    {
86
        $this->logInWithPermission('ADMIN');
87
88
        $text = $this->objFromFixture('EditableFieldText', 'basic-text');
89
90
        $response = $this->post('admin/editablefield/EditForm', [
91
            'Fields'        => [
92
                $text->ID => [],
93
            ],
94
            'action_delete' => 1,
95
            'delete_row'    => 1
96
        ]);
97
98
        $this->assertEquals('200', $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFieldAdminTest>.

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...
99
        $this->assertFalse($this->getFixtureFactory()->get('EditableFieldText', 'basic-text'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFieldAdminTest>.

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...
100
    }
101
102
    public function testAddOptionRequest()
103
    {
104
        $this->logInWithPermission('ADMIN');
105
106
        $dropdown = $this->objFromFixture('EditableFieldDropdown', 'basic-dropdown');
107
        $optionsCount = $dropdown->Options()->count();
108
109
        $this->post('admin/editablefield/EditForm', [
110
            'action_addoptionfield' => 1,
111
            'Parent'                => $dropdown->ID
112
        ]);
113
114
        $optionsCount2 = $dropdown->Options()->count() - 1;
115
116
        $this->assertEquals($optionsCount, $optionsCount2);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFieldAdminTest>.

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...
117
    }
118
}
119