mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
Merge pull request #147 from silverstripe/ux-fixes/issue3
BUG title validation on DMSDocumentSet
This commit is contained in:
commit
d3cd151ebc
@ -122,7 +122,8 @@ class DMSDocumentSet extends DataObject
|
|||||||
->setFieldCasting(array('LastEdited' => 'Datetime->Ago'))
|
->setFieldCasting(array('LastEdited' => 'Datetime->Ago'))
|
||||||
->setFieldFormatting(
|
->setFieldFormatting(
|
||||||
array(
|
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) {
|
'ManuallyAdded' => function ($value) {
|
||||||
if ($value) {
|
if ($value) {
|
||||||
return _t('DMSDocumentSet.MANUAL', 'Manually');
|
return _t('DMSDocumentSet.MANUAL', 'Manually');
|
||||||
@ -311,4 +312,14 @@ class DMSDocumentSet extends DataObject
|
|||||||
array('ManuallyAdded' => _t('DMSDocumentSet.ADDEDMETHOD', 'Added'))
|
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');
|
Config::inst()->update('DMS', 'shortcode_handler_key', 'unit-test');
|
||||||
|
|
||||||
$set = DMSDocumentSet::create();
|
$set = DMSDocumentSet::create(array('Title' => 'TestSet'));
|
||||||
$set->write();
|
$set->write();
|
||||||
|
|
||||||
$fields = $set->getCMSFields();
|
$fields = $set->getCMSFields();
|
||||||
@ -187,4 +187,18 @@ class DMSDocumentSetTest extends SapphireTest
|
|||||||
$set->saveLinkedDocuments();
|
$set->saveLinkedDocuments();
|
||||||
$this->assertEquals(2, $set->getDocuments()->count(), 'Set has 2 documents');
|
$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