Skip to content

Commit

Permalink
fix(glpiselectfield,dropdownfield): comparisons methods for conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed May 5, 2022
1 parent aaae034 commit f41dafc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,7 @@ private function getMyGroups($userID) {

public function equals($value): bool {
$value = html_entity_decode($value);
$itemtype = json_decode($this->question->fields['values'], true);
$itemtype = $itemtype['itemtype'];
$itemtype = $this->question->fields['itemtype'];
$dropdown = new $itemtype();
if ($dropdown->isNewId($this->value)) {
return ($value === '');
Expand All @@ -614,7 +613,7 @@ public function notEquals($value): bool {

public function greaterThan($value): bool {
$value = html_entity_decode($value);
$itemtype = $this->question->fields['values'];
$itemtype = $this->question->fields['itemtype'];
$dropdown = new $itemtype();
if (!$dropdown->getFromDB($this->value)) {
throw new ComparisonException('Item not found for comparison');
Expand All @@ -633,7 +632,7 @@ public function lessThan($value): bool {

public function regex($value): bool {
$value = html_entity_decode($value);
$itemtype = $this->getSubItemtype($this->question->fields['values']);
$itemtype = $this->question->fields['itemtype'];
$dropdown = new $itemtype();
if (!$dropdown->getFromDB($this->value)) {
throw new ComparisonException('Item not found for comparison');
Expand Down
8 changes: 4 additions & 4 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/DropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ public function providerEquals() {
return [
[
'fields' => $this->getQuestion([
'values' => json_encode(['itemtype' => \Location::class])
'itemtype' => \Location::class,
]),
'value' => $location1->fields['completename'],
'answer' => (string) $location1Id,
'expected' => true,
],
[
'fields' => $this->getQuestion([
'values' => json_encode(['itemtype' => \Location::class])
'itemtype' => \Location::class,
]),
'value' => $location2->fields['completename'],
'answer' => (string) $location1Id,
Expand Down Expand Up @@ -317,15 +317,15 @@ public function providerNotEquals() {
return [
[
'fields' => $this->getQuestion([
'values' => json_encode(['itemtype' => \Location::class])
'itemtype' => \Location::class,
]),
'value' => $location1->fields['completename'],
'answer' => (string) $location1Id,
'expected' => false,
],
[
'fields' => $this->getQuestion([
'values' => json_encode(['itemtype' => \Location::class])
'itemtype' => \Location::class,
]),
'value' => $location2->fields['completename'],
'answer' => (string) $location1Id,
Expand Down

0 comments on commit f41dafc

Please sign in to comment.