FIX title validation on DMSDocumentSet

This commit is contained in:
Franco Springveldt 2017-06-02 15:50:07 +12:00
parent 886fd217f2
commit 3d19b9fc75
2 changed files with 27 additions and 2 deletions

View File

@ -122,7 +122,8 @@ class DMSDocumentSet extends DataObject
->setFieldCasting(array('LastEdited' => 'Datetime->Ago'))
->setFieldFormatting(
array(
'FilenameWithoutID' => '<a target=\'_blank\' class=\'file-url\' href=\'$Link\'>$FilenameWithoutID</a>',
'FilenameWithoutID' => '<a target=\'_blank\' class=\'file-url\''
. ' href=\'$Link\'>$FilenameWithoutID</a>',
'ManuallyAdded' => function ($value) {
if ($value) {
return _t('DMSDocumentSet.MANUAL', 'Manually');
@ -311,4 +312,14 @@ class DMSDocumentSet extends DataObject
array('ManuallyAdded' => _t('DMSDocumentSet.ADDEDMETHOD', 'Added'))
);
}
protected function validate()
{
$result = parent::validate();
if (!$this->getTitle()) {
$result->error(_t('DMSDocumentSet.VALIDATION_NO_TITLE', '\'Title\' is required.'));
}
return $result;
}
}

View File

@ -163,7 +163,7 @@ class DMSDocumentSetTest extends SapphireTest
{
Config::inst()->update('DMS', 'shortcode_handler_key', 'unit-test');
$set = DMSDocumentSet::create();
$set = DMSDocumentSet::create(array('Title' => 'TestSet'));
$set->write();
$fields = $set->getCMSFields();
@ -187,4 +187,18 @@ class DMSDocumentSetTest extends SapphireTest
$set->saveLinkedDocuments();
$this->assertEquals(2, $set->getDocuments()->count(), 'Set has 2 documents');
}
/**
* Tests that an exception is thrown if no title entered for a DMSDocumentSet.
* @expectedException ValidationException
*/
public function testExceptionOnNoTitleGiven()
{
$set = DMSDocumentSet::create(array('Title' => ''));
try {
$set->write();
} catch (ValidationException $e) {
throw $e;
}
}
}