Completed
Push — master ( 1f0706...385015 )
by Franco
15s queued 10s
created

testGridFieldHasCustomisedAddNewButton()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 15
nc 3
nop 0
1
<?php
2
3
class DMSDocumentAdminTest 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...
4
{
5
    /**
6
     * Check that the default "add new" button is gone, and replaced with our customised version of it
7
     */
8
    public function testGridFieldHasCustomisedAddNewButton()
9
    {
10
        $modelAdmin = new DMSDocumentAdmin;
11
        // SS < 3.3 doesn't have a response setter, this initialises it
12
        $modelAdmin->handleRequest(new SS_HTTPRequest('GET', '/'), DataModel::inst());
13
        $modelAdmin->init();
14
15
        $form = $modelAdmin->getEditForm();
16
        $gridFieldConfig = $form->Fields()->first()->getConfig();
17
18
        // Our button is an instance of the original, so is returned when asking for the original
19
        $addNewButtons = $gridFieldConfig->getComponentsByType('GridFieldAddNewButton');
20
        foreach ($addNewButtons as $key => $addNewButton) {
21
            if ($addNewButton instanceof DMSGridFieldAddNewButton) {
22
                // Remove our version for testing's sake
23
                $addNewButtons->remove($addNewButton);
24
            }
25
        }
26
27
        $this->assertCount(0, $addNewButtons, 'Original add new button is removed');
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DMSDocumentAdminTest>.

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...
28
        $this->assertInstanceOf(
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentAdminTest>.

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...
29
            'DMSGridFieldAddNewButton',
30
            $gridFieldConfig->getComponentByType('DMSGridFieldAddNewButton'),
31
            'Model admin for documents contains customised DMS add new button'
32
        );
33
    }
34
}
35