Skip to content

Commit

Permalink
fix(filefield): fix bad value in generated targets
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Mar 13, 2019
1 parent 575dbf8 commit d3aeb0d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 2 additions & 3 deletions inc/fields/filefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ public function deserializeValue($value) {
if ($this->uploadData === null) {
$this->uploadData = [];
}
if (count($this->uploadData) === 0) {
$this->value = __('No attached document', 'formcreator');;
if (count($this->uploadData) > 0) {
$this->value = __('Attached document', 'formcreator');
} else {
$this->value = '';
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/suite-unit/PluginFormcreatorFileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,23 @@ public function testIsPrerequisites() {
$output = $instance->isPrerequisites();
$this->boolean($output)->isEqualTo(true);
}

public function testDeserializeValue() {
$instance = $this->newTestedInstance([]);
$instance->deserializeValue('invalid Json');
$this->string($instance->getValueForTargetText(true))
->isEqualTo('No attached document');

$instance->deserializeValue('[]');
$this->string($instance->getValueForTargetText(true))
->isEqualTo('No attached document');

$instance->deserializeValue('[1]');
$this->string($instance->getValueForTargetText(true))
->isEqualTo('Attached document');

$instance->deserializeValue('[1,2]');
$this->string($instance->getValueForTargetText(true))
->isEqualTo('Attached document');
}
}

0 comments on commit d3aeb0d

Please sign in to comment.