DMSSiteTreeExtensionTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanDisableDocumentSetsTab() 0 6 1
A documentSetEnabledConfigProvider() 0 7 1
A testDocumentSetsGridFieldIsCorrectlyConfigured() 0 9 1
A testGetTitleWithNumberOfDocuments() 0 5 1
A testOnBeforePublishUnEmbargoesDocumentsSetAsEmbargoedUntilPublish() 0 16 2
A testGetRelatedDocumentsForAutocompleter() 0 15 1
1
<?php
2
3
class DMSSiteTreeExtensionTest extends SapphireTest
4
{
5
    protected static $fixture_file = 'dms/tests/dmstest.yml';
6
7
    protected $requiredExtensions = array(
8
        'SiteTree' => array('DMSSiteTreeExtension')
9
    );
10
11
    /**
12
     * Ensure that setting the configuration property "documents_enabled" to false for a page type will prevent the
13
     * CMS fields from being modified.
14
     *
15
     * Also ensures that a correctly named Document Sets GridField is added to the fields in the right place.
16
     *
17
     * Note: the (1) is the number of sets defined for this SiteTree in the fixture
18
     *
19
     * @dataProvider documentSetEnabledConfigProvider
20
     */
21
    public function testCanDisableDocumentSetsTab($configSetting, $assertionMethod)
22
    {
23
        Config::inst()->update('SiteTree', 'documents_enabled', $configSetting);
24
        $siteTree = $this->objFromFixture('SiteTree', 's2');
25
        $this->$assertionMethod($siteTree->getCMSFields()->fieldByName('Root.DocumentSets.DocumentSets'));
26
    }
27
28
    /**
29
     * @return array[]
30
     */
31
    public function documentSetEnabledConfigProvider()
32
    {
33
        return array(
34
            array(true, 'assertNotNull'),
35
            array(false, 'assertNull')
36
        );
37
    }
38
39
    /**
40
     * Tests for the Document Sets GridField.
41
     *
42
     * Note: the (1) is the number of sets defined for this SiteTree in the fixture
43
     */
44
    public function testDocumentSetsGridFieldIsCorrectlyConfigured()
45
    {
46
        Config::inst()->update('SiteTree', 'documents_enabled', true);
47
        $siteTree = $this->objFromFixture('SiteTree', 's2');
48
        $gridField = $siteTree->getCMSFields()->fieldByName('Root.DocumentSets.DocumentSets');
49
50
        $this->assertInstanceOf('GridField', $gridField);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSSiteTreeExtensionTest>.

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->assertTrue((bool) $gridField->hasClass('documentsets'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSSiteTreeExtensionTest>.

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...
52
    }
53
54
    /**
55
     * Ensure that a page title can be retrieved with the number of related documents it has (across all document sets).
56
     *
57
     * See fixtures for relationships that define this result.
58
     */
59
    public function testGetTitleWithNumberOfDocuments()
60
    {
61
        $siteTree = $this->objFromFixture('SiteTree', 's1');
62
        $this->assertSame('testPage1 has document sets (5)', $siteTree->getTitleWithNumberOfDocuments());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DMSSiteTreeExtensionTest>.

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...
63
    }
64
65
    /**
66
     * Ensure that documents marked as "embargo until publish" are unmarked as such when a page containing them is
67
     * published
68
     */
69
    public function testOnBeforePublishUnEmbargoesDocumentsSetAsEmbargoedUntilPublish()
70
    {
71
        $siteTree = $this->objFromFixture('SiteTree', 's7');
72
        $siteTree->doPublish();
73
74
        // Fixture defines this page as having two documents via one set
75
        foreach (array('embargo-until-publish1', 'embargo-until-publish2') as $filename) {
76
            $this->assertFalse(
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSSiteTreeExtensionTest>.

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...
77
                (bool) $siteTree->getAllDocuments()
78
                    ->filter('Filename', 'embargo-until-publish1')
79
                    ->first()
80
                    ->EmbargoedUntilPublished
81
            );
82
        }
83
        $this->assertCount(0, $siteTree->getAllDocuments()->filter('EmbargoedUntilPublished', true));
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DMSSiteTreeExtensionTest>.

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...
84
    }
85
86
    /**
87
     * Ensure that document sets that are assigned to pages to not show up in "link existing" autocomplete
88
     * search results
89
     */
90
    public function testGetRelatedDocumentsForAutocompleter()
91
    {
92
        $page = $this->objFromFixture('SiteTree', 's1');
93
        $gridField = $page->getCMSFields()->fieldByName('Root.DocumentSets.DocumentSets');
94
        $this->assertInstanceOf('GridField', $gridField);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSSiteTreeExtensionTest>.

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...
95
96
        $autocompleter = $gridField->getConfig()->getComponentByType('GridFieldAddExistingAutocompleter');
97
        $jsonResult = $autocompleter->doSearch(
98
            $gridField,
99
            new SS_HTTPRequest('GET', '/', array('gridfield_relationsearch' => 'Document Set'))
100
        );
101
102
        $this->assertContains('Document Set not linked', $jsonResult);
103
        $this->assertNotContains('Document Set 1', $jsonResult);
104
    }
105
}
106