mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
FIX title validation on DMSDocumentSet
This commit is contained in:
parent
886fd217f2
commit
3d19b9fc75
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user