|
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); |
|
|
|
|
|
|
51
|
|
|
$this->assertTrue((bool) $gridField->hasClass('documentsets')); |
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
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( |
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
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
|
|
|
|
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.