2017-05-05 04:51:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DMSDocumentAddControllerTest extends FunctionalTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'dms/tests/dmstest.yml';
|
|
|
|
|
2017-06-07 07:00:25 +02:00
|
|
|
/**
|
|
|
|
* @var DMSDocumentAddController
|
|
|
|
*/
|
|
|
|
protected $controller;
|
|
|
|
|
2017-05-05 04:51:52 +02:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->logInWithPermission();
|
2017-06-07 07:00:25 +02:00
|
|
|
$this->controller = new DMSDocumentAddController;
|
|
|
|
$this->controller->init();
|
2017-05-05 04:51:52 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 07:00:25 +02:00
|
|
|
/**
|
|
|
|
* Ensure that if no ID is provided then a SiteTree singleton is returned (which will not have an ID). If one is
|
|
|
|
* provided then it should be loaded from the database via versioning.
|
|
|
|
*/
|
2017-05-05 04:51:52 +02:00
|
|
|
public function testCurrentPageReturnsSiteTree()
|
|
|
|
{
|
2017-06-07 07:00:25 +02:00
|
|
|
$page = $this->objFromFixture('SiteTree', 's1');
|
|
|
|
|
|
|
|
$this->assertInstanceOf('SiteTree', $this->controller->currentPage());
|
|
|
|
$this->assertEmpty($this->controller->currentPage()->ID);
|
2017-06-13 07:07:14 +02:00
|
|
|
$this->controller->setRequest(new SS_HTTPRequest('GET', '/', array('page_id' => $page->ID)));
|
2017-06-07 07:00:25 +02:00
|
|
|
$this->assertEquals($page->ID, $this->controller->currentPage()->ID, 'Specified page is loaded and returned');
|
2017-05-05 04:51:52 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 07:00:25 +02:00
|
|
|
/**
|
|
|
|
* Ensure that if no "dsid" is given a singleton is returned (which will not have an ID). If one is provided
|
|
|
|
* it should be loaded from the database
|
|
|
|
*/
|
2017-05-05 04:51:52 +02:00
|
|
|
public function testGetCurrentDocumentSetReturnsDocumentSet()
|
|
|
|
{
|
2017-06-07 07:00:25 +02:00
|
|
|
$set = $this->objFromFixture('DMSDocumentSet', 'ds1');
|
|
|
|
|
|
|
|
$this->assertInstanceOf('DMSDocumentSet', $this->controller->getCurrentDocumentSet());
|
|
|
|
$this->assertEmpty($this->controller->getCurrentDocumentSet()->ID, 'Singleton does not have an ID');
|
|
|
|
$this->controller->setRequest(new SS_HTTPRequest('GET', '/', array('dsid' => $set->ID)));
|
|
|
|
$this->assertEquals($set->ID, $this->controller->getCurrentDocumentSet()->ID, 'Specified document set is returned');
|
2017-05-05 04:51:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that extra allowed extensions are merged into the default upload field allowed extensions
|
|
|
|
*/
|
|
|
|
public function testGetAllowedExtensions()
|
|
|
|
{
|
|
|
|
Config::inst()->remove('File', 'allowed_extensions');
|
|
|
|
Config::inst()->update('File', 'allowed_extensions', array('jpg', 'gif'));
|
2017-06-07 07:00:25 +02:00
|
|
|
$this->assertSame(array('jpg', 'gif'), $this->controller->getAllowedExtensions());
|
2017-05-05 04:51:52 +02:00
|
|
|
|
|
|
|
Config::inst()->update('DMSDocumentAddController', 'allowed_extensions', array('php', 'php5'));
|
2017-06-07 07:00:25 +02:00
|
|
|
$this->assertSame(array('jpg', 'gif', 'php', 'php5'), $this->controller->getAllowedExtensions());
|
2017-05-05 04:51:52 +02:00
|
|
|
}
|
2017-05-18 01:51:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the back link will be the document set that a file is uploaded into if relevant, otherwise the model
|
|
|
|
* admin that it was uploaded from
|
|
|
|
*/
|
|
|
|
public function testBacklink()
|
|
|
|
{
|
2017-06-08 02:26:53 +02:00
|
|
|
// No page ID and no document set ID
|
2017-06-07 07:00:25 +02:00
|
|
|
$this->assertContains('admin/documents', $this->controller->Backlink());
|
2017-05-18 01:51:32 +02:00
|
|
|
|
2017-06-08 02:26:53 +02:00
|
|
|
// No page ID, has document set ID
|
2017-05-18 01:51:32 +02:00
|
|
|
$request = new SS_HTTPRequest('GET', '/', array('dsid' => 123));
|
2017-06-07 07:00:25 +02:00
|
|
|
$this->controller->setRequest($request);
|
|
|
|
$this->assertContains('EditForm', $this->controller->Backlink());
|
|
|
|
$this->assertContains('123', $this->controller->Backlink());
|
2017-06-08 02:26:53 +02:00
|
|
|
|
|
|
|
// Has page ID and document set ID
|
2017-06-13 07:07:14 +02:00
|
|
|
$request = new SS_HTTPRequest('GET', '/', array('dsid' => 123, 'page_id' => 234));
|
2017-06-08 02:26:53 +02:00
|
|
|
$this->controller->setRequest($request);
|
|
|
|
$this->assertContains('admin/pages', $this->controller->Backlink());
|
|
|
|
$this->assertContains('123', $this->controller->Backlink());
|
2017-06-14 05:53:37 +02:00
|
|
|
|
|
|
|
$urlHandlers = (array) Config::inst()->get('CMSMain', 'url_handlers', Config::UNINHERITED);
|
|
|
|
if (array_key_exists('EditForm/$ID', $urlHandlers)) {
|
|
|
|
// SS 3.6 and above, ensure that the page ID is in the edit URL
|
|
|
|
$this->assertContains('admin/pages/edit/EditForm/234', $this->controller->Backlink());
|
|
|
|
} else {
|
|
|
|
// SS 3.5 and below, the page ID is loaded from the session
|
|
|
|
$this->assertNotContains('234', $this->controller->Backlink());
|
|
|
|
}
|
2017-06-07 07:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the document autocomplete endpoint returns JSON, matching on ID, title or filename (case insensitive)
|
|
|
|
*/
|
|
|
|
public function testDocumentAutocomplete()
|
|
|
|
{
|
|
|
|
$result = (string) $this->get('admin/pages/adddocument/documentautocomplete?term=EXIST')->getBody();
|
|
|
|
$this->assertJson($result, 'Autocompleter should return JSON');
|
|
|
|
$this->assertContains("File That Doesn't Exist (Title)", $result);
|
|
|
|
$this->assertContains('test-file-file-doesnt-exist-1', $result);
|
|
|
|
$this->assertNotContains('doc-logged-in-users', $result);
|
|
|
|
|
|
|
|
$document = $this->objFromFixture('DMSDocument', 'd2');
|
|
|
|
$result = (string) $this->get('admin/pages/adddocument/documentautocomplete?term=' . $document->ID)->getBody();
|
|
|
|
$this->assertContains($document->ID . " - File That Doesn't Exist (Title)", $result);
|
2017-05-18 01:51:32 +02:00
|
|
|
}
|
2017-05-05 04:51:52 +02:00
|
|
|
}
|