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('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
|
|
|
$this->assertContains('admin/documents', $this->controller->Backlink()); |
68
|
|
|
|
69
|
|
|
$request = new SS_HTTPRequest('GET', '/', array('dsid' => 123)); |
70
|
|
|
$this->controller->setRequest($request); |
71
|
|
|
$this->assertContains('EditForm', $this->controller->Backlink()); |
72
|
|
|
$this->assertContains('123', $this->controller->Backlink()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test that the document autocomplete endpoint returns JSON, matching on ID, title or filename (case insensitive) |
77
|
|
|
*/ |
78
|
|
|
public function testDocumentAutocomplete() |
79
|
|
|
{ |
80
|
|
|
$result = (string) $this->get('admin/pages/adddocument/documentautocomplete?term=EXIST')->getBody(); |
81
|
|
|
$this->assertJson($result, 'Autocompleter should return JSON'); |
|
|
|
|
82
|
|
|
$this->assertContains("File That Doesn't Exist (Title)", $result); |
83
|
|
|
$this->assertContains('test-file-file-doesnt-exist-1', $result); |
84
|
|
|
$this->assertNotContains('doc-logged-in-users', $result); |
85
|
|
|
|
86
|
|
|
$document = $this->objFromFixture('DMSDocument', 'd2'); |
87
|
|
|
$result = (string) $this->get('admin/pages/adddocument/documentautocomplete?term=' . $document->ID)->getBody(); |
88
|
|
|
$this->assertContains($document->ID . " - File That Doesn't Exist (Title)", $result); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.