Completed
Push — master ( e5c7d1...b4e5c2 )
by Daniel
28s queued 21s
created

DMSDocumentAdminTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 80
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testDocumentSetsGridFieldHasParentPageColumn() 0 6 1
B testGridFieldHasCustomisedButtons() 0 31 4
A testModelAdminEndpointWorks() 0 4 1
A testDocumentSetsGridFieldHasLinkToCMSPageEditor() 0 8 1
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
    protected static $fixture_file = 'DMSDocumentAdminTest.yml';
6
7
    public function setUp()
8
    {
9
        parent::setUp();
10
11
        $this->logInWithPermission('ADMIN');
12
    }
13
14
    /**
15
     * Check that the default "add new" and "edit" buttons are gone, and replaced with our customised version of it
16
     */
17
    public function testGridFieldHasCustomisedButtons()
18
    {
19
        $modelAdmin = new DMSDocumentAdmin;
20
        $modelAdmin->init();
21
22
        $form = $modelAdmin->getEditForm();
23
        $gridFieldConfig = $form->Fields()->first()->getConfig();
24
25
        $replacements = array(
26
            'GridFieldAddNewButton'=>'DMSGridFieldAddNewButton',
27
            'GridFieldEditButton'=>'DMSGridFieldEditButton'
28
        );
29
30
        foreach ($replacements as $oldClass => $newClass) {
31
            // Our button is an instance of the original, so is returned when asking for the original
32
            $newButtons = $gridFieldConfig->getComponentsByType($oldClass);
33
            foreach ($newButtons as $key => $newButton) {
34
                if ($newButton instanceof $newClass) {
35
                    // Remove our version for testing's sake
36
                    $newButtons->remove($newButton);
37
                }
38
            }
39
40
            $this->assertCount(0, $newButtons, 'Original 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...
41
            $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...
42
                $newClass,
43
                $gridFieldConfig->getComponentByType($newClass),
44
                "Model admin for documents contains customised {$newClass} button"
45
            );
46
        }
47
    }
48
49
50
51
    /**
52
     * Quick check to ensure that the ModelAdmin endpoint is working
53
     */
54
    public function testModelAdminEndpointWorks()
55
    {
56
        $this->assertEquals(200, $this->get('admin/documents')->getStatusCode());
0 ignored issues
show
Bug introduced by
The method assertEquals() 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...
57
    }
58
59
    /**
60
     * Check that the document sets GridField has a data column for the parent page title. Here we check for the
61
     * Page title existing in the DOM, since "Page" is guaranteed to exist somewhere else.
62
     */
63
    public function testDocumentSetsGridFieldHasParentPageColumn()
64
    {
65
        $result = (string) $this->get('admin/documents/DMSDocumentSet')->getBody();
66
        $this->assertContains('Home Test Page', $result);
67
        $this->assertContains('About Us Test Page', $result);
68
    }
69
70
    /**
71
     * Checks that the document sets GridField has a data column which links to the DocumentSets tab on
72
     * the actual page in the CMS
73
     */
74
    public function testDocumentSetsGridFieldHasLinkToCMSPageEditor()
75
    {
76
        $result = (string)$this->get('admin/documents/DMSDocumentSet')->getBody();
77
        $this->assertContains(
78
            "<a class='dms-doc-sets-link'",
79
            $result
80
        );
81
    }
82
}
83