Skip to content

Commit

Permalink
Merge pull request #147 from silverstripe/ux-fixes/issue3
Browse files Browse the repository at this point in the history
BUG title validation on DMSDocumentSet
  • Loading branch information
robbieaverill committed Jun 2, 2017
2 parents 886fd21 + 3d19b9f commit d3cd151
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 12 additions & 1 deletion code/model/DMSDocumentSet.php
Expand Up @@ -122,7 +122,8 @@ public function getCMSFields()
->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');
Expand Down Expand Up @@ -311,4 +312,14 @@ public function getDocumentDisplayFields()
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;
}
}
16 changes: 15 additions & 1 deletion tests/DMSDocumentSetTest.php
Expand Up @@ -163,7 +163,7 @@ public function testShortcodeHandlerKeyFieldExists()
{
Config::inst()->update('DMS', 'shortcode_handler_key', 'unit-test');

$set = DMSDocumentSet::create();
$set = DMSDocumentSet::create(array('Title' => 'TestSet'));
$set->write();

$fields = $set->getCMSFields();
Expand All @@ -187,4 +187,18 @@ public function testSaveLinkedDocuments()
$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;
}
}
}

0 comments on commit d3cd151

Please sign in to comment.