Completed
Pull Request — master (#146)
by Franco
02:39
created

testDocumentSetsGridFieldHasLinkToCMSPageEditor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
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
    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" button is gone, and replaced with our customised version of it
16
     */
17
    public function testGridFieldHasCustomisedAddNewButton()
18
    {
19
        $modelAdmin = new DMSDocumentAdmin;
20
        $modelAdmin->init();
21
22
        $form = $modelAdmin->getEditForm();
23
        $gridFieldConfig = $form->Fields()->first()->getConfig();
24
25
        // Our button is an instance of the original, so is returned when asking for the original
26
        $addNewButtons = $gridFieldConfig->getComponentsByType('GridFieldAddNewButton');
27
        foreach ($addNewButtons as $key => $addNewButton) {
28
            if ($addNewButton instanceof DMSGridFieldAddNewButton) {
29
                // Remove our version for testing's sake
30
                $addNewButtons->remove($addNewButton);
31
            }
32
        }
33
34
        $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...
35
        $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...
36
            'DMSGridFieldAddNewButton',
37
            $gridFieldConfig->getComponentByType('DMSGridFieldAddNewButton'),
38
            'Model admin for documents contains customised DMS add new button'
39
        );
40
    }
41
42
    /**
43
     * Quick check to ensure that the ModelAdmin endpoint is working
44
     */
45
    public function testModelAdminEndpointWorks()
46
    {
47
        $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...
48
    }
49
50
    /**
51
     * Check that the document sets GridField has a data column for the parent page title. Here we check for the
52
     * Page title existing in the DOM, since "Page" is guaranteed to exist somewhere else.
53
     */
54
    public function testDocumentSetsGridFieldHasParentPageColumn()
55
    {
56
        $result = (string) $this->get('admin/documents/DMSDocumentSet')->getBody();
57
        $this->assertContains('Home Test Page', $result);
58
        $this->assertContains('About Us Test Page', $result);
59
    }
60
61
    /**
62
     * Checks that the document sets GridField has a data column which links to the DocumentSets tab on
63
     * the actual page in the CMS
64
     */
65
    public function testDocumentSetsGridFieldHasLinkToCMSPageEditor()
66
    {
67
        $result = (string)$this->get('admin/documents/DMSDocumentSet')->getBody();
68
        $this->assertContains(
69
            "<a class='dms-doc-sets-link' href='admin/pages/edit/show/1#Root_DocumentSets2'>Home Test Page</a>",
70
            $result
71
        );
72
    }
73
}
74