1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class DMSDocumentAddControllerTest extends FunctionalTest |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
protected static $fixture_file = 'dms/tests/dmstest.yml'; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @var DMSDocumentAddController |
9
|
|
|
*/ |
10
|
|
|
protected $controller; |
11
|
|
|
|
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
$this->logInWithPermission(); |
16
|
|
|
$this->controller = new DMSDocumentAddController; |
17
|
|
|
$this->controller->init(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Ensure that if no ID is provided then a SiteTree singleton is returned (which will not have an ID). If one is |
22
|
|
|
* provided then it should be loaded from the database via versioning. |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function testCurrentPageReturnsSiteTree() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$page = $this->objFromFixture('SiteTree', 's1'); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf('SiteTree', $this->controller->currentPage()); |
|
|
|
|
29
|
|
|
$this->assertEmpty($this->controller->currentPage()->ID); |
|
|
|
|
30
|
|
|
$this->controller->setRequest(new SS_HTTPRequest('GET', '/', array('page_id' => $page->ID))); |
31
|
|
|
$this->assertEquals($page->ID, $this->controller->currentPage()->ID, 'Specified page is loaded and returned'); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Ensure that if no "dsid" is given a singleton is returned (which will not have an ID). If one is provided |
36
|
|
|
* it should be loaded from the database |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testGetCurrentDocumentSetReturnsDocumentSet() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$set = $this->objFromFixture('DMSDocumentSet', 'ds1'); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf('DMSDocumentSet', $this->controller->getCurrentDocumentSet()); |
|
|
|
|
43
|
|
|
$this->assertEmpty($this->controller->getCurrentDocumentSet()->ID, 'Singleton does not have an ID'); |
|
|
|
|
44
|
|
|
$this->controller->setRequest(new SS_HTTPRequest('GET', '/', array('dsid' => $set->ID))); |
45
|
|
|
$this->assertEquals($set->ID, $this->controller->getCurrentDocumentSet()->ID, 'Specified document set is returned'); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Test that extra allowed extensions are merged into the default upload field allowed extensions |
50
|
|
|
*/ |
51
|
|
|
public function testGetAllowedExtensions() |
52
|
|
|
{ |
53
|
|
|
Config::inst()->remove('File', 'allowed_extensions'); |
54
|
|
|
Config::inst()->update('File', 'allowed_extensions', array('jpg', 'gif')); |
55
|
|
|
$this->assertSame(array('jpg', 'gif'), $this->controller->getAllowedExtensions()); |
|
|
|
|
56
|
|
|
|
57
|
|
|
Config::inst()->update('DMSDocumentAddController', 'allowed_extensions', array('php', 'php5')); |
58
|
|
|
$this->assertSame(array('jpg', 'gif', 'php', 'php5'), $this->controller->getAllowedExtensions()); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Test that the back link will be the document set that a file is uploaded into if relevant, otherwise the model |
63
|
|
|
* admin that it was uploaded from |
64
|
|
|
*/ |
65
|
|
|
public function testBacklink() |
66
|
|
|
{ |
67
|
|
|
// No page ID and no document set ID |
68
|
|
|
$this->assertContains('admin/documents', $this->controller->Backlink()); |
69
|
|
|
|
70
|
|
|
// No page ID, has document set ID |
71
|
|
|
$request = new SS_HTTPRequest('GET', '/', array('dsid' => 123)); |
72
|
|
|
$this->controller->setRequest($request); |
73
|
|
|
$this->assertContains('EditForm', $this->controller->Backlink()); |
74
|
|
|
$this->assertContains('123', $this->controller->Backlink()); |
75
|
|
|
|
76
|
|
|
// Has page ID and document set ID |
77
|
|
|
$request = new SS_HTTPRequest('GET', '/', array('dsid' => 123, 'page_id' => 234)); |
78
|
|
|
$this->controller->setRequest($request); |
79
|
|
|
$this->assertContains('admin/pages', $this->controller->Backlink()); |
80
|
|
|
$this->assertContains('123', $this->controller->Backlink()); |
81
|
|
|
|
82
|
|
|
$urlHandlers = (array) Config::inst()->get('CMSMain', 'url_handlers', Config::UNINHERITED); |
83
|
|
|
if (array_key_exists('EditForm/$ID', $urlHandlers)) { |
84
|
|
|
// SS 3.6 and above, ensure that the page ID is in the edit URL |
85
|
|
|
$this->assertContains('admin/pages/edit/EditForm/234', $this->controller->Backlink()); |
86
|
|
|
} else { |
87
|
|
|
// SS 3.5 and below, the page ID is loaded from the session |
88
|
|
|
$this->assertNotContains('234', $this->controller->Backlink()); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Test that the document autocomplete endpoint returns JSON, matching on ID, title or filename (case insensitive) |
94
|
|
|
*/ |
95
|
|
|
public function testDocumentAutocomplete() |
96
|
|
|
{ |
97
|
|
|
$result = (string) $this->get('admin/pages/adddocument/documentautocomplete?term=EXIST')->getBody(); |
98
|
|
|
$this->assertJson($result, 'Autocompleter should return JSON'); |
|
|
|
|
99
|
|
|
$this->assertContains("File That Doesn't Exist (Title)", $result); |
100
|
|
|
$this->assertContains('test-file-file-doesnt-exist-1', $result); |
101
|
|
|
$this->assertNotContains('doc-logged-in-users', $result); |
102
|
|
|
|
103
|
|
|
$document = $this->objFromFixture('DMSDocument', 'd2'); |
104
|
|
|
$result = (string) $this->get('admin/pages/adddocument/documentautocomplete?term=' . $document->ID)->getBody(); |
105
|
|
|
$this->assertContains($document->ID . " - File That Doesn't Exist (Title)", $result); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
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.