|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DMSGridFieldAddNewButtonTest extends SapphireTest |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
protected static $fixture_file = 'dms/tests/dmstest.yml'; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @var DMSGridFieldAddNewButton |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $button; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var GridField |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $gridField; |
|
16
|
|
|
|
|
17
|
|
|
public function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::setUp(); |
|
20
|
|
|
|
|
21
|
|
|
$fakeList = DMSDocument::get(); |
|
22
|
|
|
$this->gridField = GridField::create('TestGridField', false, $fakeList); |
|
23
|
|
|
$this->button = new DMSGridFieldAddNewButton; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Test that when no document set ID is present then it is not added to the URL for "add document" |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testNoDocumentSetIdInAddUrlWhenNotProvided() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->assertNotContains('?dsid', $this->getButtonHtml()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Test that when a document set ID is provided, it is added onto the "add document" link |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testDocumentSetIdAddedToLinkWhenProvided() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->button->setDocumentSetId(123); |
|
40
|
|
|
$this->assertContains('?dsid=123', $this->getButtonHtml()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* If a set is saved and associated to a page, that page's ID should be added to the "add document" link to help |
|
45
|
|
|
* to ensure the user gets redirected back to the correct place afterwards |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testPageIdIsAddedWhenAvailableViaDocumentSetRelationship() |
|
48
|
|
|
{ |
|
49
|
|
|
$set = $this->objFromFixture('DMSDocumentSet', 'ds1'); |
|
50
|
|
|
$this->button->setDocumentSetId($set->ID); |
|
51
|
|
|
|
|
52
|
|
|
$controller = new ContentController; |
|
53
|
|
|
$controller->pushCurrent(); |
|
54
|
|
|
|
|
55
|
|
|
$result = $this->getButtonHtml(); |
|
56
|
|
|
$this->assertContains('dsid=' . $set->ID, $result, 'Add new button contains document set ID'); |
|
57
|
|
|
$this->assertNotContains('page_id=' . $set->Page()->ID, $result, 'No page ID when not editing in page context'); |
|
58
|
|
|
|
|
59
|
|
|
$controller = new CMSPageEditController; |
|
60
|
|
|
$controller->pushCurrent(); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertContains( |
|
63
|
|
|
'page_id=' . $set->Page()->ID, |
|
64
|
|
|
$this->getButtonHtml(), |
|
65
|
|
|
'Button contains page ID when in edit page context' |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns the HTML result of the "add new" button, used for DRY in test class |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getButtonHtml() |
|
75
|
|
|
{ |
|
76
|
|
|
$fragments = $this->button->getHTMLFragments($this->gridField); |
|
77
|
|
|
return array_pop($fragments)->getValue(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.